Skip to content

EXTEND_ESLINT=true not working #9175

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

Closed
Barik85 opened this issue Jun 17, 2020 · 11 comments
Closed

EXTEND_ESLINT=true not working #9175

Barik85 opened this issue Jun 17, 2020 · 11 comments

Comments

@Barik85
Copy link

Barik85 commented Jun 17, 2020

Describe the bug

Actually it re-opens #9047
I created .env file in root directory with EXTEND_ESLINT=true
then created .eslintrc.json file with my config for eslint
but while running npm start this config doesn't work!

Did you try recovering your dependencies?

(Write your answer here.)

Which terms did you search for in User Guide?

(Write your answer here if relevant.)

Environment

(paste the output of the command here.)

Steps to reproduce

  1. npx create-react-app my-app --template typescript
  2. add .env file in root directory with EXTEND_ESLINT=true
  3. add .eslint.json with some rules, for example "no-unused-vars": ["error"]
  4. Try to check if the rule is working. In App.tsx I added
    const a= '';

Expected behavior

Expect it will consider rules from .eslintrc.json and fail to build app.

Actual behavior

Ignoring rules from .eslintrc.json

Reproducible demo

https://github.com/Barik85/reproduce_issue_eslintrc

@tobiaskraus
Copy link

I quote an answer from #9007 :

I think this is caused by how react-scripts handles ESLint cache. By default, cache is set to true. If you set it to false, any change to eslint rules will be honoured every time. The setting is in node_modules/react-scripts/config/webpack.config.js:

use: [
  {
    options: {
      cache: true, // You can set it to false
      formatter: require.resolve('react-dev-utils/eslintFormatter'),
      eslintPath: require.resolve('eslint'),
      resolvePluginsRelativeTo: __dirname,
      // @remove-on-eject-begin
      ignore: isExtendingEslintConfig,
      baseConfig: isExtendingEslintConfig
        ? undefined
        : {
            extends: [require.resolve('eslint-config-react-app')],
          },
      useEslintrc: isExtendingEslintConfig,
      // @remove-on-eject-end
    },

and if this is your problem, I hope that my proposal #9085 would be accepted, and someone could implement it.

@poozhu
Copy link

poozhu commented Jun 23, 2020

I have test your example project, with the .eslintrc.json file, you can test the rule with another var name: c, it works well.

@JRasmusBm
Copy link

JRasmusBm commented Jul 8, 2020

Following the suggestion from @tobiaskraus I added the following line to the scripts section of our package.json. It should work wherever sed is available and perform the change suggested whenever the dependencies are installed.

"postinstall": "sed \"s/cache: true/cache: false/g\" node_modules/react-scripts/config/webpack.config.js -i",

This resolved the issue such that our custom eslint config started working.

@lafe
Copy link

lafe commented Jul 8, 2020

A cross-plattform solution might be to use the "patch-package" tool that can run as a postinstall-script and can patch files in node_modules. That's the approach we choose when we encountered this issue.

@stale
Copy link

stale bot commented Aug 8, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Aug 8, 2020
@lafe
Copy link

lafe commented Aug 10, 2020

From our point of view, the issue is still present.

@stale stale bot removed the stale label Aug 10, 2020
@croraf
Copy link

croraf commented Aug 18, 2020

This should be closed in favor of #9085 @Barik85

@feyzullahyildiz
Copy link

feyzullahyildiz commented Sep 15, 2020

I quote an answer from #9007 :

I think this is caused by how react-scripts handles ESLint cache. By default, cache is set to true. If you set it to false, any change to eslint rules will be honoured every time. The setting is in node_modules/react-scripts/config/webpack.config.js:

use: [
  {
    options: {
      cache: true, // You can set it to false
      formatter: require.resolve('react-dev-utils/eslintFormatter'),
      eslintPath: require.resolve('eslint'),
      resolvePluginsRelativeTo: __dirname,
      // @remove-on-eject-begin
      ignore: isExtendingEslintConfig,
      baseConfig: isExtendingEslintConfig
        ? undefined
        : {
            extends: [require.resolve('eslint-config-react-app')],
          },
      useEslintrc: isExtendingEslintConfig,
      // @remove-on-eject-end
    },

and if this is your problem, I hope that my proposal #9085 would be accepted, and someone could implement it.

I think there is another env key is needed to disable cache besides EXTEND_ESLINT. This solution is working well but its not a good way and not documented on https://create-react-app.dev/docs/setting-up-your-editor/#experimental-extending-the-eslint-config

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Dec 25, 2020
@lafe
Copy link

lafe commented Dec 26, 2020

Will check on it in the new year...

@stale stale bot removed the stale label Dec 26, 2020
@iansu
Copy link
Contributor

iansu commented Jun 2, 2021

Can you try the latest release and see if this has improved? If not please open a new issue.

@iansu iansu closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants