Skip to content

vue/no-use-computed-property-like-method reports errors where there aren't any #1594

Closed
@FloEdelmann

Description

@FloEdelmann

Checklist

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

Tell us about your environment

  • ESLint version: 7.32.0
  • eslint-plugin-vue version: 7.15.1
  • Node version: both 12.22.3 and 14.17.4
  • Operating System: Ubuntu 20.04

Please show your full configuration:

Details
const pluginPresets = {
  'array-func': `all`,
  import: `recommended`,
  jsdoc: `recommended`,
  markdown: `recommended`,
  nuxt: `recommended`,
  promise: `recommended`,
  security: `recommended`,
  unicorn: `recommended`,
  vue: `recommended`,
  jsonc: `recommended-with-json`, // has to be after `vue` and `nuxt`
};

const enabledRuleParameters = {
  // Core ESLint rules
  'accessor-pairs': [],
  'array-bracket-spacing': [],
  'arrow-parens': [`as-needed`],
  'arrow-spacing': [],
  'block-spacing': [],
  'brace-style': [`stroustrup`],
  'camelcase': [],
  'comma-dangle': [`always-multiline`],
  'comma-spacing': [],
  'comma-style': [],
  'complexity': [7],
  'consistent-return': [],
  'curly': [`all`],
  'dot-location': [`property`],
  'dot-notation': [],
  'eol-last': [`always`],
  'eqeqeq': [`always`, { null: `ignore` }],
  'func-call-spacing': [],
  'getter-return': [],
  'grouped-accessor-pairs': [`getBeforeSet`],
  'guard-for-in': [],
  'indent': [2, { SwitchCase: 1 }],
  'key-spacing': [],
  'keyword-spacing': [],
  'linebreak-style': [`unix`],
  'new-parens': [],
  'no-array-constructor': [],
  'no-bitwise': [],
  'no-confusing-arrow': [{ allowParens: true }],
  'no-else-return': [{ allowElseIf: false }],
  'no-irregular-whitespace': [],
  'no-lonely-if': [],
  'no-loop-func': [],
  'no-mixed-operators': [],
  'no-multi-spaces': [],
  'no-new-object': [],
  'no-prototype-builtins': [],
  'no-restricted-imports': [{
    name: `fs`,
    message: `Please use 'fs/promises' instead.`,
  }],
  'no-return-assign': [],
  'no-return-await': [],
  'no-shadow': [{ builtinGlobals: false }],
  'no-template-curly-in-string': [],
  'no-trailing-spaces': [],
  'no-unsafe-optional-chaining': [{ 'disallowArithmeticOperators': true }],
  'no-unused-vars': [{ args: `none` }],
  'no-var': [],
  'object-curly-spacing': [`always`],
  'object-shorthand': [`always`, { avoidQuotes: true }],
  'prefer-arrow-callback': [],
  'prefer-const': [{ destructuring: `all` }],
  'prefer-rest-params': [],
  'prefer-template': [],
  'quotes': [`backtick`, { allowTemplateLiterals: true }],
  'radix': [],
  'semi': [],
  'space-before-blocks': [],
  'space-before-function-paren': [{
    anonymous: `never`,
    named: `never`,
    asyncArrow: `always`,
  }],
  'space-in-parens': [],
  'space-infix-ops': [],
  'spaced-comment': [`always`],
  'template-curly-spacing': [],

  // eslint-plugin-import
  'import/extensions': [`ignorePackages`],
  'import/first': [],
  'import/newline-after-import': [],
  'import/no-commonjs': [{ allowConditionalRequire: false }],
  'import/no-dynamic-require': [],
  'import/no-unresolved': [{
    ignore: [`^fs/promises$`],
  }],
  'import/order': [{
    groups: [`builtin`, `external`, `internal`, `parent`, `sibling`],
    alphabetize: {
      order: `asc`,
      caseInsensitive: true,
    },
  }],

  // eslint-plugin-jsdoc
  'jsdoc/check-alignment': [],
  'jsdoc/check-indentation': [],
  'jsdoc/check-param-names': [],
  'jsdoc/check-syntax': [],
  'jsdoc/check-tag-names': [],
  'jsdoc/check-types': [],
  'jsdoc/implements-on-classes': [],
  'jsdoc/require-jsdoc': [{
    enableFixer: false,
    require: {
      FunctionDeclaration: true,
      MethodDefinition: true,
      ClassDeclaration: true,
      ArrowFunctionExpression: false,
      FunctionExpression: false,
    },
  }],
  'jsdoc/require-param': [],
  'jsdoc/require-param-description': [],
  'jsdoc/require-param-name': [],
  'jsdoc/require-param-type': [],
  'jsdoc/require-returns': [],
  'jsdoc/require-returns-check': [],
  'jsdoc/require-returns-description': [],
  'jsdoc/require-returns-type': [],
  'jsdoc/valid-types': [],

  // eslint-plugin-jsonc
  'jsonc/auto': [],

  // eslint-plugin-promise
  'promise/no-callback-in-promise': [],
  'promise/no-nesting': [],
  'promise/no-promise-in-callback': [],
  'promise/no-return-in-finally': [],
  'promise/prefer-await-to-then': [],
  'promise/valid-params': [],

  // eslint-plugin-unicorn
  'unicorn/import-style': [{
    styles: {
      'fs/promises': { named: true },
    },
  }],
  'unicorn/prevent-abbreviations': [{
    replacements: {
      ref: false,
      env: false,
      man: { manufacturer: true },
      fix: { fixture: true },
      ch: { channel: true },
      cap: { capability: true },
      caps: { capabilities: true },
      cat: { category: true },
      cats: { categories: true },
    },
  }],

  // eslint-plugin-vue
  'vue/block-lang': [{
    script: { allowNoLang: true },
    style: { lang: `scss` },
    template: { allowNoLang: true },
  }],
  'vue/component-name-in-template-casing': [`PascalCase`, {
    registeredComponentsOnly: false,
  }],
  'vue/component-tags-order': [{
    order: [`template`, `style`, `script`],
  }],
  'vue/html-button-has-type': [],
  'vue/html-closing-bracket-newline': [{
    singleline: `never`,
    multiline: `never`,
  }],
  'vue/match-component-file-name': [{
    extensions: [`vue`],
    shouldMatchCase: true,
  }],
  'vue/max-attributes-per-line': [{ singleline: 3 }],
  'vue/next-tick-style': [],
  'vue/no-deprecated-scope-attribute': [],
  'vue/no-deprecated-slot-attribute': [],
  'vue/no-deprecated-slot-scope-attribute': [],
  'vue/no-empty-component-block': [],
  'vue/no-invalid-model-keys': [],
  'vue/no-unused-properties': [{
    groups: [`props`, `data`, `computed`, `methods`, `setup`],
    ignorePublicMembers: true,
  }],
  'vue/no-unused-refs': [],
  'vue/no-use-computed-property-like-method': [],
  'vue/require-direct-export': [],
  'vue/v-for-delimiter-style': [`of`],
  'vue/v-on-function-call': [`always`],
  'vue/v-slot-style': [`shorthand`],
  'vue/valid-next-tick': [],

  // already included in presets, but needed here because we reduce severity to `warn`
  'unicorn/no-array-for-each': [],
  'vue/no-mutating-props': [],
};

const vueCoreExtensionRules = [
  `array-bracket-newline`,
  `array-bracket-spacing`,
  `arrow-spacing`,
  `block-spacing`,
  `brace-style`,
  `camelcase`,
  `comma-dangle`,
  `comma-spacing`,
  `comma-style`,
  `dot-location`,
  `dot-notation`,
  `eqeqeq`,
  `func-call-spacing`,
  `key-spacing`,
  `keyword-spacing`,
  `max-len`,
  `no-constant-condition`,
  `no-empty-pattern`,
  `no-extra-parens`,
  `no-irregular-whitespace`,
  `no-restricted-syntax`,
  `no-sparse-arrays`,
  `no-useless-concat`,
  `object-curly-newline`,
  `object-curly-spacing`,
  `object-property-newline`,
  `operator-linebreak`,
  `prefer-template`,
  `space-in-parens`,
  `space-infix-ops`,
  `space-unary-ops`,
  `template-curly-spacing`,
];

const warnRules = new Set([
  `complexity`,
  `jsdoc/require-jsdoc`,
  `vue/no-mutating-props`,
]);

const disabledRules = [
  `no-console`,
  `jsdoc/newline-after-description`,
  `jsdoc/no-undefined-types`,
  `jsdoc/require-description`,
  `jsdoc/require-description-complete-sentence`,
  `promise/always-return`,
  `security/detect-child-process`,
  `security/detect-non-literal-fs-filename`,
  `security/detect-non-literal-require`,
  `security/detect-object-injection`,
  `unicorn/consistent-function-scoping`,
  `unicorn/filename-case`,
  `unicorn/no-null`,
  `unicorn/no-process-exit`,
  `unicorn/no-array-reduce`,
  `unicorn/no-useless-undefined`,
  `unicorn/prefer-node-protocol`,
  `unicorn/prefer-spread`,
  `vue/multiline-html-element-content-newline`,
  `vue/singleline-html-element-content-newline`,
];

for (const ruleName of vueCoreExtensionRules) {
  if (ruleName in enabledRuleParameters) {
    enabledRuleParameters[`vue/${ruleName}`] = enabledRuleParameters[ruleName];
  }
}

module.exports = {
  env: {
    es6: true,
    node: true,
  },
  parserOptions: {
    ecmaVersion: 2021,
  },
  plugins: Object.keys(pluginPresets),
  extends: [
    `eslint:recommended`,
    ...Object.entries(pluginPresets).map(([plugin, preset]) => `plugin:${plugin}/${preset}`),
  ],
  rules: {
    ...Object.fromEntries(
      Object.entries(enabledRuleParameters).map(([ruleName, parameters]) => [
        ruleName,
        [warnRules.has(ruleName) ? `warn` : `error`, ...parameters],
      ]),
    ),
    ...Object.fromEntries(
      disabledRules.map(ruleName => [ruleName, `off`]),
    ),
  },
  settings: {
    jsdoc: {
      mode: `typescript`,
      tagNamePreference: {
        augments: `extends`,
        class: `constructor`,
        file: `fileoverview`,
        fires: `emits`,
        linkcode: `link`,
        linkplain: `link`,
        overview: `fileoverview`,
      },
      preferredTypes: {
        array: `Array`,
        boolean: `Boolean`,
        number: `Number`,
        object: `Object`,
        string: `String`,
        '<>': `.<>`,
        '[]': `Array.<>`,
      },
    },
  },
  ignorePatterns: [`package-lock.json`],
  overrides: [
    {
      files: [`**/*.md/*.js`],
      rules: {
        'jsdoc/require-jsdoc': `off`,
        'import/no-unresolved': `off`,
      },
    },
    {
      files: [`**/*.cjs`, `server/**.js`],
      parserOptions: {
        sourceType: `script`,
      },
      rules: {
        'import/no-commonjs': `off`,
        'unicorn/prefer-module': `off`,
      },
    },
    {
      files: [`**/*.vue`],
    },
    {
      files: [`fixtures/**/*.json`],
      rules: {
        // allow alignment of pixel keys in matrix
        'no-multi-spaces': [`error`, {
          exceptions: {
            JSONArrayExpression: true,
          },
        }],
        'jsonc/array-bracket-spacing': `off`,

        'unicorn/prevent-abbreviations': `off`,
      },
    },
  ],
};

What did you do?

see https://github.com/OpenLightingProject/open-fixture-library/blob/e1d3b6b3503cddd54654a8aacac20bb622b36a4e/ui/components/editor/EditorCapabilityWizard.vue

What did you expect to happen?

No errors, since no computed property is called like a function.

What actually happened?

$ eslint --quiet --format codeframe .

error: Use this.insertIndex instead of this.insertIndex() (vue/no-use-computed-property-like-method) at ui/components/editor/EditorCapabilityWizard.vue:274:7:
  272 | 
  273 |       // insert all computed capabilities at insertIndex
> 274 |       inheritedCapabilities.splice(this.insertIndex, this.removeCount, ...computedCapabilites);
      |       ^
  275 | 
  276 |       return inheritedCapabilities.filter(
  277 |         capability => capability.dmxRange !== null,


error: Use this.removeCount instead of this.removeCount() (vue/no-use-computed-property-like-method) at ui/components/editor/EditorCapabilityWizard.vue:274:7:
  272 | 
  273 |       // insert all computed capabilities at insertIndex
> 274 |       inheritedCapabilities.splice(this.insertIndex, this.removeCount, ...computedCapabilites);
      |       ^
  275 | 
  276 |       return inheritedCapabilities.filter(
  277 |         capability => capability.dmxRange !== null,


error: Use this.insertIndex instead of this.insertIndex() (vue/no-use-computed-property-like-method) at ui/components/editor/EditorCapabilityWizard.vue:374:7:
  372 | 
  373 |       // insert all computed capabilities at insertIndex
> 374 |       this.capabilities.splice(this.insertIndex, this.removeCount, ...this.computedCapabilites);
      |       ^
  375 | 
  376 |       this.$emit(`close`, this.insertIndex);
  377 |     },


error: Use this.removeCount instead of this.removeCount() (vue/no-use-computed-property-like-method) at ui/components/editor/EditorCapabilityWizard.vue:374:7:
  372 | 
  373 |       // insert all computed capabilities at insertIndex
> 374 |       this.capabilities.splice(this.insertIndex, this.removeCount, ...this.computedCapabilites);
      |       ^
  375 | 
  376 |       this.$emit(`close`, this.insertIndex);
  377 |     },


error: Use this.insertIndex instead of this.insertIndex() (vue/no-use-computed-property-like-method) at ui/components/editor/EditorCapabilityWizard.vue:376:7:
  374 |       this.capabilities.splice(this.insertIndex, this.removeCount, ...this.computedCapabilites);
  375 | 
> 376 |       this.$emit(`close`, this.insertIndex);
      |       ^
  377 |     },
  378 |   },
  379 | };


5 errors found.

Repository to reproduce this issue

https://github.com/OpenLightingProject/open-fixture-library/tree/e1d3b6b3503cddd54654a8aacac20bb622b36a4e

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions