-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[utils] [new] parse
: support flat config
#2714
[utils] [new] parse
: support flat config
#2714
Conversation
utils/parse.js
Outdated
const isFlat = context.languageOptions && | ||
typeof context.languageOptions.parser === 'object'; // May be a string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this test still work with the approach we've taken to have a config shared between flat and legacy? Meaning, the legacy config object still has languageOptions
, I just mark it non-enumerable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand it is that has nothing to do with the read config file, as context.languageOptions.parserOptions
is also set for legacy configs (relevant code). But if the linter runs in "flat" mode it no longer sets the context.parserPath
, context.parserOptions
... .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - it's not that languageOptions is set that IDs it as the flat config, it's that it's set and has an object parser
property?
Are we sure it can't be null, only a string or an object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No as I understand it in the current eslint both properties are set: context.parserOptions
and context.languageOptions.parserOptions
(same with other properties of languageOptions). But in "flat" mode the top-level properties are not set.
To the type of languageOptions.parser
:
- null: I created an extra test case for this case.
- string: is from @types/eslint
- object: is already an object for the current eslint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add runtime checks that throw errors if the types aren't what we expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added runtime checks that context.languageOptions.parser
either has a function parse or parseForESLint
Added support for |
4d70c98
to
9ee5904
Compare
9ee5904
to
dc596a2
Compare
Did some tweaks for style, but also additional ones to handle that FlatRuleTester isn't available in eslint < 8. |
parse
: support flat config
I have a lot of errors like this: |
@azat-io meaning, with eslint-module-utils 2.7 you don't see those, but with 2.8 you do? |
Flat ESLint no longer supports
context.parserPath
which is required for utils/parse.This PR uses
context.languageOptions.parse
which has the loaded parser as an alternative.Some notes:
context.parserPath
is unsetparse
orparseForESLint
incontext.languageOptions.parser
is a function (I do not if "constructed" context objects are officially supported)