eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

vue/no-ref-as-operand only lint left identifier of a logical expression

Open lakb248 opened this issue 2 years ago • 1 comments

Checklist

  • [x] I have tried restarting my IDE and the issue persists.
  • [x] I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: v8.27.0
  • eslint-plugin-vue version: v9.7.0
  • Node version: v16.17.0
  • Operating System: MacOS

Please show your full configuration:

module.exports = {
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  extends: [
    'plugin:vue/recommended',
    'eslint:recommended',
    '@vue/eslint-config-typescript/recommended',
  ],
  settings: {
    'import/resolver': {
      typescript: { directory: 'tsconfig.json' },
      alias: {
        extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
        map: [
          // for more custom alias config not included in tsconfig
        ],
      },
    },
  },
  plugins: [
    'import'
  ],
}

What did you do?

const myRef = ref(0);
const a = true;
if (a && myRef) {
  // do something
}

What did you expect to happen? myRef will throw vue/no-ref-as-operand error, vue/no-ref-as-operand only lint left identifier of a logicalExpression

What actually happened?

eslint don't throw vue/no-ref-as-operand error, and

Repository to reproduce this issue

lakb248 avatar Aug 08 '23 06:08 lakb248

Maybe put the logic for this rule in a separate no-ref-as-operand-strict rule, or customize with a parameter (strictCheck) of the current one? In my code there are no cases of the following type

const refValue1: Ref<number>  = ref(0)
const maybeRefValue: Ref<number> | null = getMaybeRef()
const refValue2 = maybeRefValue || refValue1

But errors with such case use are often encountered

const refValue1: Ref<number>  = ref(0)
if (refValue1) {
  //incorrect condition
}

grindpride avatar Oct 24 '24 11:10 grindpride