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
chore: update eslint-config-eslint exports #17336
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
rules: { | ||
"n/callback-return": ["error", ["cb", "callback", "next"]], | ||
"n/handle-callback-err": ["error", "err"], | ||
"n/no-deprecated-api": "error", |
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 removed n/no-deprecated-api
from here because I believe it's already in eslint-plugin-n's recommended configs. Is that correct?
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.
👍
Rather than forcing us to mix and match individual configs, what if we just exported an ESM-compatible array by default and included a CommonJS one under That way, the default is equivalent to what we have now and the special case of CommonJS is set off to the side. So you'd be able to do this:
And then in a CommonJS file do:
|
"n/no-mixed-requires": "error", | ||
"n/no-new-require": "error", | ||
"n/no-path-concat": "error" |
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.
These 3 rules will be in the commonjs
config only because I believe they don't apply to ESM. Is that correct?
777d28b
to
7e00e73
Compare
That's another option, but I think the usage would be more complicated in our ESM projects, where we have import eslintConfigESLint from "eslint-config-eslint";
import eslintConfigESLintCJS from "eslint-config-eslint/cjs";
export default [
...eslintConfigESLint.map(config => ({
files: ["**/*.js"],
...config
})),
...eslintConfigESLintCJS.map(config => ({
files: ["**/*.cjs"],
...config
}))
]; |
To me that seems less complicated because you don't have to mix and match a base with specific ESM or CJS configs. I'd like to plan for a future without CommonJS and design a solution that works optimally in that world even if its suboptimal in a current CommonJS repo. |
Makes sense, I'll update the exports. |
If had to choose, I would prefer the simpler way of usage. Can we export something like 4331d3c? |
I've updated exports so that the default export is the full configuration for ESM files, and there is an additional export I also added |
That's another option, but since the new config system doesn't have a feature like eslintrc's |
just wondering the “best practice” should be strictly adhered to - it's much easier for users to move the for esm projects: const esmConfig = require("eslint-config-eslint/esm");
module.exports = [ ...esmConfig]; for cjs projects: const cjsConfig = require("eslint-config-eslint/cjs");
module.exports = [ ...cjsConfig]; |
The problem with |
well, I see your point! in my implementation, it has exported 3 configs:
I am happy with the current implementation, and I am somewhat discovering the flexibility of the new config system, we may need a little time to explore the best way to use it. 😄 |
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.
LGTM, just waiting @nzakas to take another look.
"exports": { | ||
"./package.json": "./package.json", | ||
".": "./index.js", | ||
"./cjs": "./cjs.js" | ||
}, |
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 didn't see a need to add this - we did this in the eslint package to avoid other devs using the internal modules, but this package is (mostly) only used by 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.
I thought it would be good to clarify which modules are intended to be public.
And with this, import "eslint-config-eslint/cjs"
doesn't need .js
extension :)
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.
we need to export ./eslintrc
as well - it was used in .eslintrc.js
:
Line 65 in cdd063c
"eslint/eslintrc" |
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.
Good catch! Updated in 6f71c8e
In general, I agree that a best practice would be to avoid I'm also fine with putting a big warning message on the README to this effect. :) |
All right, I'll update the config to include |
Ready for another review. |
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.
LGTM. 👍
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.
LGTM. Thanks!
* main: (101 commits) docs: Migrating `eslint-env` configuration comments (eslint#17390) Merge pull request from GHSA-qwh7-v8hg-w8rh feat: adds option for allowing empty object patterns as parameter (eslint#17365) fix: FlatESLint#getRulesMetaForResults shouldn't throw on unknown rules (eslint#17393) docs: fix Ignoring Files section in config migration guide (eslint#17392) docs: Update README feat: Improve config error messages (eslint#17385) fix: Update no-loop-func to not overlap with no-undef (eslint#17358) docs: Update README docs: Update README 8.45.0 Build: changelog update for 8.45.0 chore: package.json update for @eslint/js release docs: add playground links to correct and incorrect code blocks (eslint#17306) docs: Expand rule option schema docs (eslint#17198) docs: Config Migration Guide (eslint#17230) docs: Update README fix: Fix suggestion message in `no-useless-escape` (eslint#17339) docs: Update README chore: update eslint-config-eslint exports (eslint#17336) ...
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:
Refs discussion in eslint/espree#577 (comment).
Currently, eslint-config-eslint exports a single config array suitable for CommonJS projects. That's fine for this repo, but most of the other repos are now ESM. Usage in an ESM repo would look like in eslint/espree#577:
That doesn't look very convenient.
What changes did you make? (Give an overview)
This PR changes eslint-config-eslint to export an object with 3 configs:
base
(config array),commonjs
(config object),esm
(config object), so that the usage would look like this:Is there anything you'd like reviewers to focus on?
Do the names make sense?