Can I use different eslint rules for methods in a .vue file?

54 Views Asked by At

I've got a Vue 2 project using the options API and single file components (.vue files). I'm using the eslint-plugin-jsdoc plugin to require JSDoc comments on methods. I want JSDoc comments to be required on methods only, and optional on computed getters, watchers, etc.

The Vue ESLint parser code includes AST node definitions that look like I should be able to somehow target methods only:

export interface ESLintMethodDefinition extends HasLocation, HasParent {
    type: "MethodDefinition"                       // <-- 
    kind: "constructor" | "method" | "get" | "set" // <-- 
    computed: boolean                              // <-- 
    static: boolean
    key: ESLintExpression | ESLintPrivateIdentifier
    value: ESLintFunctionExpression

But I don't understand how to use that in my ESLint config.

I've tried a few variations on this override object in my ESLint config:

{
  "files": [
    "*.vue"
  ],
  "parser": "vue-eslint-parser",
  "rules": {
    "jsdoc/require-jsdoc": [
      "error",
      {
        "contexts": [
          "FunctionDeclaration",
          "MethodDefinition",
          "FunctionExpression"
        ]
      }
    ]
  }
}

Removing FunctionExpression makes the linter ignore all function expressions in .vue files, so it definitely does something, but I don't know how to make that more specific, and only target certain sections of the Vue 2 SFC.

I want to do this project-wide, so adding eslint-disable comments all over every file isn't an option in this case.

Is there a way to apply different eslint rules specifically in the methods section of a Vue file?

0

There are 0 best solutions below