Skip to content

Extending ESLint with rule overrides: unexpected result with react-scripts build #8266

Closed
@cheezekurl

Description

@cheezekurl

Describe the bug

When applying custom ESLint configuration where you define a rule as error globally but off for a filename pattern, npm run build does not correctly ignore those filename patterns for the rule in question. Running ESLint directly works as expected, disabling the rule for that filename pattern.

Note that I have set up EXTEND_ESLINT=true in my .env and added "react-app" to extends in my .eslintrc.js

Did you try recovering your dependencies?

Yes - I even created a fresh create-react-app to repro this.

Which terms did you search for in User Guide?

Extend ESLint, ESLint

Environment

 System:
    OS: macOS 10.15.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 12.14.0 - ~/.nvm/versions/node/v12.14.0/bin/node
    Yarn: Not Found
    npm: 6.13.4 - ~/.nvm/versions/node/v12.14.0/bin/npm
  Browsers:
    Chrome: 79.0.3945.88
    Firefox: 34.0.5
    Safari: 13.0.4
  npmPackages:
    react: ^16.12.0 => 16.12.0
    react-dom: ^16.12.0 => 16.12.0
    react-scripts: 3.3.0 => 3.3.0
  npmGlobalPackages:
    create-react-app: Not Found

I have also reproduced the same issue on my Windows 10 PC at work, but do not have access to that command output at the moment.

Steps to reproduce

  1. npm install eslint@6.7.2

  2. Create an .eslintrc.js with the following:

module.exports = {
        "extends": ["react-app"],
        "rules": {
            "consistent-return": "error"
        },
        "overrides": [
            {
                "files": "App.js",
                rules: {
                    "consistent-return": "off"
                }
            }
        ]
}
  1. Create a .env with the following
EXTEND_ESLINT=true
  1. Add the following block to App.js somewhere
  const myFunc = () => {
    if (false) {
      return 'foo';
    }
  }
  1. Add a package.json script for linting: "lint": "eslint src"

  2. npm run lint. Observe that there are no lint errors detected

  3. npm run build.

Expected behavior

The build would succeed

Actual behavior

The build failed with the following error

Creating an optimized production build...
Failed to compile.

./src/App.js
  Line 6:21:  Expected to return a value at the end of arrow function  consistent-return

Search for the keywords to learn more about each error.

Reproducible demo

https://github.com/cheezekurl/cra-eslint-bug-repro

Activity

eip1599

eip1599 commented on Jan 2, 2020

@eip1599
Contributor

@cheezekurl I had the same problem, this set as 3.3.1 milestone. Check here.
So I found a temporary answer on stackoverflow.

stale

stale commented on Feb 1, 2020

@stale

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 commented on Feb 6, 2020

@stale

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

locked and limited conversation to collaborators on Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cheezekurl@eip1599

        Issue actions

          Extending ESLint with rule overrides: unexpected result with react-scripts build · Issue #8266 · facebook/create-react-app