-
Notifications
You must be signed in to change notification settings - Fork 268
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
How to configure eslint by useEslintRc? #175
Comments
I have the same issue. Maybe it's the The linting works properly when run manually, and during commit. But webpack explodes. I've given up for now. |
Seems like React team started supporting custom eslint configs from CRA 3.x. This worked for me:
|
@pyyding I came looking at customize-cra because there are still quite a few issues with CRA's option. Particularly with mixed JS/TS code bases (what we have). So When using |
I have the same issue. I also found the I also made a When I use directly eslint it works fine and when it's via Even with
But nothing works. |
See here, there are issues with the |
Experiencing the same problems detailed above with trying load a custom // file: config-overrides.js
const { useBabelRc, override } = require('customize-cra');
// Import your eslint configuration here
const eslintConfig = require('./.eslintrc.js');
const useEslintConfig = configRules => config => {
const updatedRules = config.module.rules.map(
rule => {
// Only target rules that have defined a `useEslintrc` parameter in their options
if (rule.use && rule.use.some( use => use.options && use.options.useEslintrc !== void 0)) {
const ruleUse = rule.use[0];
const baseOptions = ruleUse.options;
const baseConfig = baseOptions.baseConfig || {};
const newOptions = {
useEslintrc: false,
ignore: true,
baseConfig: { ...baseConfig, ...configRules }
}
ruleUse.options = newOptions;
return rule;
// Rule not using eslint. Do not modify.
} else {
return rule;
}
}
);
config.module.rules = updatedRules;
return config;
};
// Support environment -specific settings
const env = process.env.NODE_ENV;
const envs = {
development: override(
useEslintConfig(eslintConfig), // Use your imported .eslintrc.js file here
useBabelRc(),
),
production: override(
useBabelRc(),
),
};
module.exports = envs[env]; Hopefully will help someone. 😊 |
@mikko-tormala Thanks for building this and posting it! It would be great if this was a fix for this project, would you be open to me making this in to a PR? @arackaf Would you be open to a PR addressing this issue? Seems like we have a workable solution and I think it'd be great to incorporate it upstream. |
I have no objections. I'm glad it helped someone 😀 👍 |
this temp fix worked perfectly, now waiting for official supp now |
I found a solution!First, thanks to @mikko-tormala for the solution, you helped me! Fixed this problem with const { override, useEslintRc } = require('customize-cra');
const path = require('path');
module.exports = override(
useEslintRc(path.resolve(__dirname, '.eslintrc.json')),
); |
Thanks for mikko-tormala answer, I made a package https://www.npmjs.com/package/customize-cra-eslint npm i customize-cra-eslint -D |
Thanks for @mikko-tormala, it was useful! |
This solution currently not working, with this react-scripts also load default bad behaviour, only solution from @mikko-tormala |
I'm confused about using customize-cra to configure Eslint, which is always unsuccessful.
I created the required files .eslintrc.js and .config-overrides.js in the root directory. The code is as follows, but it doesn't work after I set the rules. I'm depressed. What should I do?
The text was updated successfully, but these errors were encountered: