Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the latest vue-eslint-parser #656

Closed
masterofnothing11 opened this issue Oct 18, 2019 · 3 comments
Closed

Use the latest vue-eslint-parser #656

masterofnothing11 opened this issue Oct 18, 2019 · 3 comments

Comments

@masterofnothing11
Copy link

masterofnothing11 commented Oct 18, 2019

First of all I would like to state that I'm fully aware this is a question to stackoverflow but since the community around Encore is not that big I see no options other than to come to the repository itself.

Enviroment:

  • Docker version 19.03.3
  • Linux Mint 19.1 Tessa

Basically I'm getting the famous error error Use the latest vue-eslint-parser. See also https://vuejs.github.io/eslint-plugin-vue/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error vue/html-indent. I have tried all the solutions that I could find on Google but nothing seems to work.

.eslintrc.js

module.exports = {
    "parser": "vue-eslint-parser",
    "parserOptions": {
        parser: "babel-eslint",
        "allowImportExportEverywhere": true,
        "ecmaFeatures": {
            "legacyDecorators": true,
            "modules": true
        },
        "ecmaVersion": 6,
        "sourceType": "module",
    },
    "extends": [
        "plugin:vue/base",
        "airbnb-base"
    ],
    "rules": {
        ...
        "vue/html-indent": [2, 4],
        ...
    },
    "env": {
        browser: true,
        es6: true,
        node: true
    },
};

webpack.config.js

...
.enableEslintLoader(eslLinterLoaderOptions => {
        eslLinterLoaderOptions.configPath = path.resolve(__dirname, '.eslintrc.js');
        eslLinterLoaderOptions.ignorePath = path.resolve(__dirname, '.eslintignore');
        eslLinterLoaderOptions.cache = false;
    })
...

package.json

...
  "devDependencies": {
    "@symfony/webpack-encore": "^0.27.0",
    "babel-eslint": "^10.0.1",
    "copy-webpack-plugin": "^4.5.3",
    "eslint": "^6.4.0",
    "eslint-plugin-vue": "^5.2.2",
    "ts-loader": "^5.3.0",
    "tslint": "^5.16.0",
    "typescript": "^3.4.5"
  },
...

Every time I run the command yarn encore --watch ESLint does it thing and check the files and the error mentioned above is thrown in almost every file.

I have tried removing the node_modules/ folder and also upgrading ESLint.

Any help would be highly appreciated

@Kocal
Copy link
Contributor

Kocal commented Oct 18, 2019

Hi, it's because Encore force parser option to babel-eslint and it's not compatible with eslint-plugin-vue.

See #574 for more information.

As a workaround you can use the following code to let Encore/ESLint lint your .vue files:

Encore
  .enableEslintLoader(options => {
      delete options.parser;
  })
  .configureLoaderRule('eslint', loader => {
      loader.test = /\.(jsx?|vue)$/;
  })

@masterofnothing11
Copy link
Author

@Kocal Completely worked for me. Thank you so much

@Kocal
Copy link
Contributor

Kocal commented Oct 19, 2019

@masterofnothing11 since your issue has been resolved, can you close your issue please? Thanks! :)

weaverryan added a commit that referenced this issue Mar 20, 2020
This PR was merged into the master branch.

Discussion
----------

Remove ESLint user-related config

Hi ✋

This PR is a proposal for #657 implementation and should fix issues encountered in #473, #574, #656, #659, and #685.

As discussed in #657, it would be better if Encore didn't configure ESLint itself. It should be done by the end user in an configuration file (e.g.: `.eslintrc.js`)

ESLint's `parser` option is not configured by default anymore, and `babel-eslint` requirement has been removed. We can considering this as a breaking change, end users should now configure `parser: 'babel-eslint` themselves.

Method `Encore.enableEslintLoader('extends-name')` has been deprecated and undocumented, in order to prevent end users to configure ESLint through Encore.

A nice message is also displayed when no ESLint configuration is found:
![Capture d’écran de 2020-01-12 11-15-09](https://user-images.githubusercontent.com/2103975/72217430-dfa2a480-352d-11ea-96e3-0e77236127d6.png)
I couldn't use `FriendlyErrorsPlugin` for this because error is not coming from Webpack. If someone has a better idea... 😕

**Pros:**
- end users have now full control hover ESLint configuration **by default**
- no need to `delete options.parser` when trying to use [`eslint-plugin-vue`](https://github.com/vuejs/eslint-plugin-vue) or [`@typescript-eslint/parser`](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)
- IDEs will be able to integrate ESLint (if they support it)

**Cons:**
- end users should now configure `parser` option to `babel-eslint` themselves
- end users will have to move their config to external config file, but it's ok

What do you think?
Thanks.

**EDIT:** tests failures are unrelated I think.

Commits
-------

9d3b02f tweaking wording and order
d23982a Display message if no ESLint configuration is found
c828b32 Deprecate `Encore.enableEslintLoader('extends-name')`
9f31d95 Add test for ESLint with external configuration (and babel-eslint usage)
3ba6cf2 Remove babel-eslint from ESLint configuration
weaverryan added a commit that referenced this issue Apr 17, 2020
This PR was squashed before being merged into the master branch.

Discussion
----------

Proposal to replace #504 (ESLint/Vue)

This PR add a second argument to `Encore.enableEslintLoader()` that is used to let the ESLint loader lint `.vue` files:

```js
Encore.enableEslintLoader(() => {}, {
    lintVue: true
});
```

Using `lintVue` won't add any ESLint configuration, that the job of the final user (see #504 (comment)).

**EDIT:**

While #657 is being discussed, you can use the following code to:
 - let ESLint process your `.vue` files
 - prevent the error `Use the latest vue-eslint-parser.`, see #656

```js
Encore.enableEslintLoader((options) => {
  delete options.parser;
}, {
  lintVue: true
});
```

**EDIT 2:**

PR #687 has been merged and issue #657 is now resolved. It means that you can use the following code to let eslint-loader handle `.vue` files:
```js
Encore.enableEslintLoader(() => {}, {
    lintVue: true
});
```

Commits
-------

13b0750 chore: remove comment for vue files linting since #687 has been merged
2f1e85b chore: add comment for making .vue files lint working
12b3f77 eslint/vue: add 2nd parameter to Encore#enableEslintLoader
eb85b24 eslint/vue: tweak config-generator
aa782df eslint/vue: implement `getTest()` on ESlint loader helper
bc444ff eslint/vue: tweak `WebpackConfig#enableEslintLoader()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants