sheerun / prettier-standard

Formats with Prettier and lints with ESLint+Standard! (✿◠‿◠)
MIT License
868 stars 44 forks source link

Conflict with vue-eslint-parser #95

Closed dgautsch closed 4 years ago

dgautsch commented 4 years ago

The codebase I'm working on uses Vue single file components (SFC).

I'm using modern-standard to lint and format my files and it has been working out great. I had to add eslint-vue-plugin to my codebase so eslint is able to read the SFC format. Unfortunately the plugin requires this format in your eslintrc files.

"parser": "vue-eslint-parser",
  "parserOptions": {
    "parser": "babel-eslint",
    "sourceType": "module"
  }

When prettier-standard generates its eslint configuration it has the parser set to babel-eslint. This causes the following errors:

error    Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error

My theory is that the generated config from prettier-standard is defaulting the parser to babel-eslint but Vue requires that to be set in the parserOptions.

It's possible I could solve this via the overrides in eslint or maybe there's a code change that can happen here to facilitate the plugin. Open to ideas.

Here is my eslintrc file

{
  "extends": [
    "standard",
    "plugin:jest/recommended",
    "plugin:vue/recommended"
  ],
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jest": true
  },
  "parser": "vue-eslint-parser",
  "parserOptions": {
    "parser": "babel-eslint",
    "sourceType": "module"
  },
  "plugins": [
    "vue",
    "html",
    "jest"
  ]
}

When I run npx eslint --ext .js,.vue . The linter works fine. It's only an issue when running modern lint

dgautsch commented 4 years ago

I solved the issue with this config

{
  "extends": [
    "standard",
    "plugin:jest/recommended"
  ],
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jest": true
  },
  "parserOptions": {
    "parser": "babel-eslint",
    "sourceType": "module"
  },
  "overrides":[{
    "extends": ["plugin:vue/recommended"],
    "files": ["*.vue"],
    "parser": "vue-eslint-parser",
    "parserOptions": {
      "parser": "babel-eslint",
      "sourceType": "module"
    },
    "plugins": [
      "vue",
      "html"
    ]
  }],
  "plugins": [
    "jest"
  ]
}