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

getEcmaVersionIfUseEspree should respect user-installed espree, too #238

Open
4 tasks done
haoqunjiang opened this issue Oct 10, 2024 · 1 comment · May be fixed by #239
Open
4 tasks done

getEcmaVersionIfUseEspree should respect user-installed espree, too #238

haoqunjiang opened this issue Oct 10, 2024 · 1 comment · May be fixed by #239
Labels

Comments

@haoqunjiang
Copy link
Member

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

  • I'm using eslint-plugin-vue.
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-vue repo and open the issue in eslint-plugin-vue repo if there is no solution.
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

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 vuejs/eslint-config-typescript#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

if (parserOptions.ecmaVersion === "latest") {
return normalizeEcmaVersion(getLatestEcmaVersion(getNewestEspree()))
}

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:
eslint/js@b068cea
The getEcmaVersionIfUseEspree can be removed entirely.

@ota-meshi ota-meshi added the bug label Oct 23, 2024
@ota-meshi
Copy link
Member

ota-meshi commented Oct 23, 2024

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 🤔

@ota-meshi ota-meshi linked a pull request Oct 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants