vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.47k stars 667 forks source link

No ref as operand in composable #2615

Open timothee-durand opened 3 days ago

timothee-durand commented 3 days ago

Checklist

Tell us about your environment

Please show your full configuration:

/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
  root: true,
  ignorePatterns: ['*.legacy.vue'],
  env: { node: true, es6: true, browser: true, jest: true },
  extends: [
    'eslint:recommended',
    '@vue/eslint-config-typescript',
    'plugin:vue/vue3-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:import/recommended',
    'plugin:import/typescript',
    '@vue/eslint-config-prettier',
  ],
  parser: 'vue-eslint-parser',
  parserOptions: {
    ecmaVersion: 'latest',
    parser: '@typescript-eslint/parser',
  },
  plugins: ['import', '@typescript-eslint', 'unused-imports'],
  settings: {
    'import/resolver': {
      typescript: {
        alwaysTryTypes: true,
        project: './tsconfig.app.json',
      },
      node: true,
    },
  },
  rules: {
    quotes: [
      'error',
      'single',
      { avoidEscape: true, allowTemplateLiterals: false },
    ],
    '@typescript-eslint/no-explicit-any': 'error',
    '@typescript-eslint/explicit-function-return-type': 'warn',
    'import/newline-after-import': 'error',
    'import/no-unresolved': 'error',
    'import/order': [
      'error',
      {
        'newlines-between': 'always',
        groups: [
          'builtin',
          'external',
          'internal',
          'parent',
          'sibling',
          'index',
        ],
        alphabetize: { order: 'asc', caseInsensitive: true },
      },
    ],
    'no-console': 'warn',
    'no-use-before-define': 'off',
    'no-warning-comments': 'warn',
    'padding-line-between-statements': 'off',
    'unused-imports/no-unused-imports': 'error',
    'vue/no-multiple-template-root': 'off',
    'vue/no-ref-as-operand': 'error',
    'vue/no-undef-components': 'error',
    'vue/html-self-closing': 'off',
    'vue/component-name-in-template-casing': [
      'error',
      'PascalCase',
      {
        registeredComponentsOnly: true,
      },
    ],
  },
  globals: {
    'i18n-t': 'readonly',
  },
}

What did you do?

<script setup>
function useSomething() {
  const testRef = ref('test')
  const testComputed = computed(() => {
    return testRef.value !== 'test'
  })
  return {
    testComputed,
    testRef,
  }
}

const isTestComputedOk = computed(() => {
  const { testComputed } = useSomething()
  if (testComputed) {
    return 'yes'
  } else {
    return 'no'
  }
})
</script>

What did you expect to happen? The testComputed in the isTestComputedOk should throw a vue/no-ref-as-operand lint error

What actually happened? It doesn't throw

Repository to reproduce this issue https://github.com/timothee-durand/minimal-reproduce-no-ref-as-operand