question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignoring .eslintrc.json

See original GitHub issue

Description

When lint-staged is run the .eslintrc.json file is ignored. Running eslint from the command line works fine, but when eslint is run via husky/lint-staged it does not yield the same result as it ignores my .eslintrc.json file

Steps to reproduce

Try to git commit changes

Debug Logs

expand to view
➜  webapp git:(master) ✗ clear
➜  webapp git:(master) ✗ git commit -m "crossed"

Warning: Setting pre-commit script in package.json > scripts will be deprecated
Please move it to husky.hooks in package.json, a .huskyrc file, or a husky.config.js file
Or run ./node_modules/.bin/husky-upgrade for automatic update

See https://github.com/typicode/husky for usage

husky > pre-commit (node v12.7.0)
  lint-staged:bin Running `lint-staged@9.2.5` +0ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/Applications/MAMP/htdocs/reactjs/ui/webapp/package.json`:
  lint-staged { '*.js': [ 'eslint', 'git add' ] } +4ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '*.js': [
    'eslint',
    'git add'
  ]
}
  lint-staged:run Running all linter scripts +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:run Resolved git directory to be `/Applications/MAMP/htdocs/reactjs/ui/webapp` +16ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only' ] +17ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [
  lint-staged:run   'src/actions/authentication.actions.js',
  lint-staged:run   'src/actions/index.js',
  lint-staged:run   'src/actions/user.actions.js',
  lint-staged:run   'src/api/api.js',
  lint-staged:run   'src/api/authentication.js',
  lint-staged:run   'src/components/Alert/Alert.js',
  lint-staged:run   'src/components/Alert/index.js',
  lint-staged:run   'src/components/FeedbackMessage/FeedbackMessage.js',
  lint-staged:run   'src/components/FeedbackMessage/FeedbackMessage.scss',
  lint-staged:run   'src/components/FeedbackMessage/index.js',
  lint-staged:run   'src/components/PrivateRoute/PrivateRoute.js',
  lint-staged:run   'src/components/PrivateRoute/index.js',
  lint-staged:run   'src/components/TextInput/TextInput.js',
  lint-staged:run   'src/components/TextInput/TextInput.scss',
  lint-staged:run   'src/components/TextInput/index.js',
  lint-staged:run   'src/components/buttons/Button/Button.js',
  lint-staged:run   'src/components/buttons/Button/Button.scss',
  lint-staged:run   'src/components/buttons/Button/Button.test.js',
  lint-staged:run   'src/components/buttons/Button/__snapshots__/Button.test.js.snap',
  lint-staged:run   'src/components/buttons/Button/index.js',
  lint-staged:run   'src/components/buttons/SubmitButton/SubmitButton.js',
  lint-staged:run   'src/components/buttons/SubmitButton/index.js',
  lint-staged:run   'src/constants/application.js',
  lint-staged:run   'src/constants/authentication.action.types.js',
  lint-staged:run   'src/constants/index.js',
  lint-staged:run   'src/constants/user.action.types.js',
  lint-staged:run   'src/containers/App/App.js',
  lint-staged:run   'src/containers/App/index.js',
  lint-staged:run   ... 29 more items
  lint-staged:run ] +27ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: '*.js',
  lint-staged:gen-tasks   commands: [ 'eslint', 'git add' ],
  lint-staged:gen-tasks   fileList: [
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/authentication.actions.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/user.actions.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/api/api.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/api/authentication.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/Alert/Alert.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/Alert/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/FeedbackMessage/FeedbackMessage.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/FeedbackMessage/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/PrivateRoute/PrivateRoute.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/PrivateRoute/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/TextInput/TextInput.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/TextInput/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/Button/Button.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/Button/Button.test.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/Button/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/SubmitButton/SubmitButton.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/SubmitButton/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/application.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/authentication.action.types.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/user.action.types.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/App/App.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/App/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/Header/Header.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/Header/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/MainNavigation/MainNavigation.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/MainNavigation/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/authentication.reducer.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/initialState.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/routes/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/routes/routes.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Dashboard/Dashboard.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Dashboard/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/Login.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginBanner/LoginBanner.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginBanner/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginForm/LoginForm.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginForm/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginMessage/LoginMessage.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginMessage/index.js',
  lint-staged:gen-tasks     '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/index.js'
  lint-staged:gen-tasks   ]
  lint-staged:gen-tasks } +9ms
Stashing changes... [started]
  lint-staged:git Running git command [ 'status', '--porcelain' ] +51ms
  lint-staged:git Stashing files... +0ms
  lint-staged:git Running git command [ 'write-tree' ] +74ms
  lint-staged:git Running git command [ 'add', '.' ] +21ms
  lint-staged:git Running git command [ 'write-tree' ] +52ms
  lint-staged:git Running git command [ 'read-tree', '3ea1488802eb2d6e4f0b743a8d3359368df11adb' ] +11ms
  lint-staged:git Running git command [ 'checkout-index', '-af' ] +21ms
  lint-staged:git Done stashing files! +330ms
Stashing changes... [completed]
Running tasks... [started]
Running tasks for *.js [started]
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'eslint', 'git add' ] +0ms
eslint [started]
  lint-staged:task cmd: eslint +0ms
  lint-staged:task args: [
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/authentication.actions.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/user.actions.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/api/api.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/api/authentication.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/Alert/Alert.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/Alert/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/FeedbackMessage/FeedbackMessage.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/FeedbackMessage/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/PrivateRoute/PrivateRoute.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/PrivateRoute/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/TextInput/TextInput.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/TextInput/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/Button/Button.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/Button/Button.test.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/Button/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/SubmitButton/SubmitButton.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/SubmitButton/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/application.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/authentication.action.types.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/constants/user.action.types.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/App/App.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/App/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/Header/Header.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/Header/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/MainNavigation/MainNavigation.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/MainNavigation/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/authentication.reducer.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/initialState.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/routes/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/routes/routes.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Dashboard/Dashboard.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Dashboard/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/Login.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginBanner/LoginBanner.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginBanner/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginForm/LoginForm.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginForm/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginMessage/LoginMessage.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginMessage/index.js',
  '/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/index.js'
] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +7ms
eslint [failed]
→
Running tasks for *.js [failed]
→
Running tasks... [failed]
Updating stash... [started]
Updating stash... [skipped]
→ Skipping stash update since some tasks exited with errors
Restoring local changes... [started]
  lint-staged:git Restoring working copy +5s
  lint-staged:git Running git command [ 'read-tree', '4af36fb112468a75896cb9328d12378d4bd4eadb' ] +5s
  lint-staged:git Running git command [ 'checkout-index', '-af' ] +20ms
  lint-staged:git Restoring index +165ms
  lint-staged:git Running git command [ 'read-tree', '3ea1488802eb2d6e4f0b743a8d3359368df11adb' ] +146ms
Restoring local changes... [completed]



✖ eslint found some errors. Please fix them and try committing again.

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/authentication.actions.js
1:17  error  Unable to resolve path to module 'api/api'  import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/actions/user.actions.js
1:29  error  Unable to resolve path to module 'constants/user.action.types'  import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/api/api.js
1:1  error  'axios' should be listed in the project's dependencies. Run 'npm i -S axios' to add it  import/no-extraneous-dependencies

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/TextInput/TextInput.js
27:5  error  Form label must have ALL of the following types of associated control: nesting, id  jsx-a11y/label-has-for

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/Button/Button.test.js
2:1  error  'react-test-renderer' should be listed in the project's dependencies. Run 'npm i -S react-test-renderer' to add it  import/no-extraneous-dependencies
6:1  error  'it' is not defined                                                                                                 no-undef
8:3  error  'expect' is not defined                                                                                             no-undef

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/components/buttons/SubmitButton/SubmitButton.js
2:20  error  Unable to resolve path to module 'components/buttons/Button'  import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/App/App.js
 6:20  error  Unable to resolve path to module 'routes'                     import/no-unresolved
 7:21  error  Unable to resolve path to module 'helpers/history'            import/no-unresolved
 8:20  error  Unable to resolve path to module 'containers/Header'          import/no-unresolved
 9:28  error  Unable to resolve path to module 'containers/MainNavigation'  import/no-unresolved
11:34  error  Unable to resolve path to module 'constants/application'      import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/containers/Header/Header.js
8:35  error  Unable to resolve path to module 'actions/authentication.actions'  import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/index.js
5:17  error  Unable to resolve path to module 'containers/App'  import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/authentication.reducer.js
1:39  error  Unable to resolve path to module 'constants/authentication.action.types'  import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/reducers/initialState.js
1:1  error  'lodash' should be listed in the project's dependencies. Run 'npm i -S lodash' to add it  import/no-extraneous-dependencies

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/routes/routes.js
4:26  error  Unable to resolve path to module 'components/PrivateRoute'  import/no-unresolved
5:23  error  Unable to resolve path to module 'screens/Dashboard'        import/no-unresolved
6:19  error  Unable to resolve path to module 'screens/Login'            import/no-unresolved

/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/Login.js
 5:39  error  Unable to resolve path to module 'actions'          import/no-unresolved
 6:21  error  Unable to resolve path to module 'helpers/history'  import/no-unresolved
77:13  error  'token' is assigned a value but never used          no-unused-vars


/Applications/MAMP/htdocs/reactjs/ui/webapp/src/screens/Login/components/LoginForm/LoginForm.js
3:1   error  'formik' should be listed in the project's dependencies. Run 'npm i -S formik' to add it  import/no-extraneous-dependencies
5:20  error  Unable to resolve path to module 'components/buttons/Button'                              import/no-unresolved
6:23  error  Unable to resolve path to module 'components/TextInput'                                   import/no-unresolved
7:29  error  Unable to resolve path to module 'components/FeedbackMessage'                             import/no-unresolved

✖ 30 problems (30 errors, 0 warnings)

husky > pre-commit hook failed (add --no-verify to bypass)

Environment

  • OS: MacOS 10.14.2
  • Node.js: v12.7.0
  • lint-staged: v9.2.5

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:9

github_iconTop GitHub Comments

2reactions
tcourtqtmcommented, Dec 16, 2019

+1

I am also experiencing this with husky and lint-staged with an .eslintrc.js file. No changes I make to my eslintrc are observed when running with lint-staged. I have eslint@6.7.2, lint-staged@8.2.1.

1reaction
IAMtheIAMcommented, May 26, 2020

I don’t think this is an issue with lint-staged but with eslint itself. see eslint/eslint#9977

From what i gather lint-staged (or whatever other mechanism you can use) tells eslint to run over whatever files match the glob pattern, eslint takes that as an explicit command. This is different to running eslint through the command line were it applies any eslint ignore file and rules.

I tested this hypothesis and here’s what I found.

Running the command directly on the file i.e. eslint C:\dev\my-filecomponent.html as lint-staged would results in eslint running correctly and applying the .eslintrc.js config the same as it would when running just eslint

Interestingly enough, running eslint --debug shows that both eslint and lint-staged do in fact load the config. See output

2020-05-26T21:31:35.496Z eslint:config-array-factory Config file found: C:\dev\.eslintrc.js

Still trying to figure out why it’s erroring out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignoring Code - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Disable eslint rules for folder - Stack Overflow
To ignore some folder from eslint rules we could create the file .eslintignore in root directory and add there the path to the...
Read more >
Configuring ESLint - ESLint - Pluggable JavaScript linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Ignoring ESLint - next.config.js
When ESLint is detected in your project, Next.js fails your production build ( next build ) when errors are present. If you'd like...
Read more >
ESLint | WebStorm Documentation - JetBrains
If you have several package.json files with ESLint listed as a ... from the ESLint configuration so that WebStorm ignores them and shows ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found