vuejs / vue-eslint-parser

The ESLint custom parser for `.vue` files.
MIT License
449 stars 74 forks source link

`getEcmaVersionIfUseEspree` should respect user-installed espree, too #238

Open haoqunjiang opened 4 weeks ago

haoqunjiang commented 4 weeks ago

Before You File a Bug Report Please Confirm You Have Done The Following...

What version of ESLint are you using?

9.12.0

What version of eslint-plugin-vue and vue-eslint-parser are you using?

What did you do?

Use Flat Config in ESLint 9 with the default configuration.

What did you expect to happen?

No parsing error.

What actually happened?

0:0 error Parsing error: Invalid ecmaVersion (If the espree parser is used for an SFC)

Link to Minimal Reproducible Example

The issue report is at https://github.com/vuejs/eslint-config-typescript/issues/87 And a stable reproduction can be found at https://github.com/vuejs/eslint-config-typescript/tree/8954ae82336dc53fecc656bb613af1bd42c808cb/test/fixtures/with-older-espree

Additional comments

I explained the fix at my downstream config here: https://github.com/vuejs/eslint-config-typescript/blob/aae95d60eaae711de8eccd55ee33ffd799cd188a/src/index.ts#L84-L91 But I think there's a bug in vue-eslint-parser too:

According to https://github.com/vuejs/vue-eslint-parser/blob/b0e0ccc6d302bb40c5cb496528536bd355ee5151/src/script/index.ts#L569C10-L603 The espree in the user project takes precedence over the others. However, in https://github.com/vuejs/vue-eslint-parser/blob/b0e0ccc6d302bb40c5cb496528536bd355ee5151/src/common/espree.ts#L96-L98 only the newest espree version is used to determine the latest ecmaVersion.

In the issue report above, as ESLint 9 now depends on espree 10.x, the latest ecmaVersion is 2025, but the project loads the espree 9.x depended by vue-eslint-parser, which doesn't recognize that version, thus the error.


By the way, if I understand correctly, as of espree 8.0.0, ecmaVersion: 'latest' is supported, so vue-eslint-parser doesn't have to normalize the version string before passing it along: https://github.com/eslint/js/commit/b068cea907ef59fe5681f6acedd30b932d496e0a The getEcmaVersionIfUseEspree can be removed entirely.

ota-meshi commented 2 weeks ago

Thank you for posting this issue!

The getEcmaVersionIfUseEspree can be removed entirely.

I think it's a workaround for eslint v6 support, I think the easiest fix would be to just drop support for the older eslint. I don't yet know how to fix this while still supporting the old eslint :thinking: