-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
fix: add cjs override for esm projects (fixes #59) #63
Conversation
globals: module
in generated .eslintrc.js (fixes #59)/* globals module*/
in generated .eslintrc.js (fixes #59)
lib/init/config-file.js
Outdated
@@ -83,7 +83,7 @@ async function writeYAMLConfigFile(config, filePath) { | |||
async function writeJSConfigFile(config, filePath) { | |||
debug(`Writing JS config file: ${filePath}`); | |||
|
|||
const stringifiedContent = `module.exports = ${stringify(config, { cmp: sortByKey, space: 4 })}\n`; | |||
const stringifiedContent = `/* globals module */\nmodule.exports = ${stringify(config, { cmp: sortByKey, space: 4 })}\n`; |
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.
If we add /* globals module */
unconditionally, then the user will get the A config file was generated, but the config file itself may not follow your linting rules.
message we're trying to avoid, this time if they choose What type of modules does your project use? · commonjs
because of the no-redeclare rule.
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'm having a hard time understanding what you're saying here.
The error message is always output for JS config files, I don't think the point was to eliminate that message. The point was to eliminate a linting error.
Are you saying something else is already declaring module
?
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.
yes, it's happening when
globals: {module: true}
orenv: { commonjs: true}
- rule
no-redeclare
was enabled
In this case, it will introduce a new linting 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 can see a few options to resolve it:
- adding
/*eslint env: node*/
, the drawback is thatenv
will go away in the new config. - adding
/* eslint-disable-next-line no-undef
*/. the comment will be removed by the fixer if the gloabalmodule
has been declared in the eslintrc, e.g.eslint-config-airbnb
. - adding a config item for the
.eslintrc.cjs
, something like
module.exports = {
...,
overrides: [{files: [".eslintrc.cjs"], globals: {"module": 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.
Solution 3 with overrides
sounds good to me.
see the discussion: #59 (comment)
/* globals module*/
in generated .eslintrc.js (fixes #59)8c285e1
to
e84bfaa
Compare
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! Leaving open for @nzakas to verify.
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.
Works for me.
see the discussion: #59 (comment)