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
feat: Avoid dirname for built-in configs #70
Conversation
Load eslint:recommended and eslint:all configs via import instead file paths. Fixes: eslint/eslint#15575
|
eslintRecommendedPath, | ||
eslintAllPath | ||
eslintRecommendedConfig, | ||
eslintAllConfig |
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.
I marked this PR as "breaking" (and we'll have to update the commit tag) because this change is backward-incompatible, so we'd need to bump @eslint/eslintrc to 2.0 to avoid using it from ESLint v8.0.0-v8.9.0.
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 an alternative, we could keep these string options, add new ones for objects, and support both paths and objects (if the objects are passed in, then use them; otherwise, use paths). That wouldn't be a breaking change for this package. Though it would make the code a bit more complicated, and I'm not sure if anyone other than eslint/eslint is using this API.
@nzakas thoughts about this, should we keep the existing API and just add new options?
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.
Yeah, I don’t want to make any breaking changes at this point. It probably makes sense to just add new properties and throw an error if both a path and an object are passed.
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.
Thanks for the comments!
I've updated the code to keep the compatibility.
Load eslint:recommended and eslint:all configs via import instead file paths. Fixes: eslint/eslint#15575
@daidodo can you please sign CLA, so we could merge the PRs when they're ready? Note that your email associated with the commits on these PRs is not the same as the one associated with your GitHub user account. |
eslintAllPath: path.resolve(dirname, "../conf/eslint-all.cjs"), | ||
eslintRecommendedPath: path.resolve(dirname, "../conf/eslint-recommended.cjs") | ||
getEslintAllConfig: () => ({ settings: { "eslint:all": true } }), | ||
getEslintRecommendedConfig: () => ({ settings: { "eslint:recommended": true } }) |
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.
👍
Can you also delete those two .cjs
files, as they are no longer used?
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.
Done.
I marked this as |
tests/lib/config-array-factory.js
Outdated
/** | ||
* Return config data for built-in eslint:all. | ||
* @returns {ConfigData} Config data | ||
*/ | ||
function getEslintAllConfig() { | ||
return import("../fixtures/eslint-all.cjs"); | ||
} | ||
|
||
/** | ||
* Return config data for built-in eslint:recommended. | ||
* @returns {ConfigData} Config data | ||
*/ | ||
function getEslintRecommendedConfig() { | ||
return import("../fixtures/eslint-recommended.cjs"); | ||
} | ||
|
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.
This doesn't work as expected, because import()
returns a Promise. We can probably use require()
here (require
is created on line 24).
I believe that's the reason why one test is failing:
635 passing (2s)
1 failing
1) ConfigArrayFactory
'_normalizeConfigData(configData, ctx)' method should normalize the config data.
'extends' details
if 'extends' property was 'eslint:all', the returned value
should have the config data of 'eslint:all' at the first element.:
AssertionError: expected { type: 'config', …(15) } to deeply equal { …(16) }
+ expected - actual
{
"criteria": [null]
"env": [undefined]
- "filePath": ""
+ "filePath": "/home/runner/work/eslintrc/eslintrc/tests/fixtures/eslint-all.cjs"
"globals": [undefined]
"ignorePattern": [undefined]
"name": ".eslintrc » eslint:all"
"noInlineConfig": [undefined]
--
"plugins": [undefined]
"processor": [undefined]
"reportUnusedDisableDirectives": [undefined]
"root": [undefined]
- "rules": [undefined]
+ "rules": {
+ "curly": [
+ "error"
+ ]
+ "eqeqeq": [
+ "error"
+ ]
+ }
"settings": [undefined]
"type": "config"
}
at assertConfigArrayElement (file:///home/runner/work/eslintrc/eslintrc/tests/lib/config-array-factory.js:[88](https://github.com/eslint/eslintrc/runs/5220072307?check_suite_focus=true#step:5:88):12)
at Context.<anonymous> (file:///home/runner/work/eslintrc/eslintrc/tests/lib/config-array-factory.js:[104](https://github.com/eslint/eslintrc/runs/5220072307?check_suite_focus=true#step:5:104)4:21)
You can run npm test
locally to check.
What's surprising is that only one test is failing. Can we, instead of semi-randomly mixing strings and functions in tests, convert all tests to use the new functions getEslintAllConfig
and getEslintRecommendedConfig
, and then duplicate tests that have eslint:all
and eslint:recommended
to check if they work with eslintAllPath
and eslintRecommendedPath
, for backwards compatibility.
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.
Sorry for missing the failed tests. Will fix it.
Load eslint:recommended and eslint:all configs via import instead file paths. Fixes: eslint/eslint#15575
Sorry, the git accounts have been a mess on my laptop. Closing eslint/eslint#15602 and this PR. |
Load eslint:recommended and eslint:all configs via import instead file paths.
Fixes: eslint/eslint#15575