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.

lint-staged is very slow when script is npm run xxx

See original GitHub issue

Description

I found my lint-staged was very slow, so I debugged it and found when not use the npm run xxx commands it will be fine, it’s very strange, I want to know why.

Steps to reproduce

  1. Use this config
    npm script:
    "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx",
    lint-staged config:
"lint-staged": {
    "**/*.{js,jsx}": "npm run lint-staged:js"
  }
  1. modify a file (just one) and git add .
  2. npx lint-staged In my computer it will take more than 3 min for result! But if I replace commands to:
"lint-staged": {
   "**/*.{js,jsx}": "eslint --ext .js,.jsx,.ts,.tsx"
 }

it will be ok. That’s strange.

Debug Logs

expand to view
$ npx lint-staged -d > log
2019-10-21T08:20:48.219Z lint-staged:bin Running `lint-staged@9.4.2`
2019-10-21T08:20:48.224Z lint-staged Loading config using `cosmiconfig`
2019-10-21T08:20:48.241Z lint-staged Successfully loaded config from `D:\projects\osms-web\package.json`:
{ '**/*.{js,jsx}': 'npm run lint-staged:js' }
2019-10-21T08:20:48.242Z lint-staged:cfg Validating config
2019-10-21T08:20:48.256Z lint-staged:run Running all linter scripts
2019-10-21T08:20:48.257Z lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ]
2019-10-21T08:20:48.759Z lint-staged:run Resolved git directory to be `D:/Projects/osms-web`
2019-10-21T08:20:48.759Z lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only' ]
2019-10-21T08:20:49.408Z lint-staged:run Loaded list of staged files in git:
[ 'src/pages/WorkloadConfirmation/index.jsx' ]
2019-10-21T08:20:49.408Z lint-staged:gen-tasks Generating linter tasks
2019-10-21T08:20:49.432Z lint-staged:gen-tasks Generated task:
{ pattern: '**/*.{js,jsx}',
  commands: 'npm run lint-staged:js',
  fileList:
   [ 'D:/projects/osms-web/src/pages/WorkloadConfirmation/index.jsx' ] }
2019-10-21T08:20:49.444Z lint-staged:git Running git command [ 'status', '--porcelain' ]
2019-10-21T08:20:50.052Z lint-staged:make-cmd-tasks Creating listr tasks for commands 'npm run lint-staged:js'
2019-10-21T08:20:50.067Z lint-staged:task cmd: npm
2019-10-21T08:20:50.067Z lint-staged:task args: [ 'run',
  'lint-staged:js',
  'D:/projects/osms-web/src/pages/WorkloadConfirmation/index.jsx' ]
2019-10-21T08:20:50.068Z lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false }



× npm run lint-staged:js found some errors. Please fix them and try committing again.

> ant-design-pro@1.0.0 lint-staged:js D:\Projects\osms-web
> eslint --ext .js,.jsx,.ts,.tsx "D:/projects/osms-web/src/pages/WorkloadConfirmation/index.jsx"


D:\projects\osms-web\src\pages\WorkloadConfirmation\index.jsx
 6:36  error  'React' is not defined                   no-undef
27:7   error  'React' must be in scope when using JSX  react/react-in-jsx-scope
28:9   error  'React' must be in scope when using JSX  react/react-in-jsx-scope
29:31  error  'React' must be in scope when using JSX  react/react-in-jsx-scope
30:31  error  'React' must be in scope when using JSX  react/react-in-jsx-scope

✖ 5 problems (5 errors, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ant-design-pro@1.0.0 lint-staged:js: `eslint --ext .js,.jsx,.ts,.tsx "D:/projects/osms-web/src/pages/WorkloadConfirmation/index.jsx"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ant-design-pro@1.0.0 lint-staged:js script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\Users\w13269464702\AppData\Roaming
pm-cache\_logs\2019-10-21T08_21_01_390Z-debug.log

Environment

  • OS: win7 64bit
  • Node.js: 10.13.0
  • lint-staged: 9.4.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
okonetcommented, Oct 22, 2019

The problem is that you provide ESLint with --ext option that runs it on the whole project. lint-staged passes staged files to it directly, so just remove everything from the command and leave it as eslint

0reactions
okonetcommented, Jul 6, 2021

Please provide the debug logs

Read more comments on GitHub >

github_iconTop Results From Across the Web

`npx mrm@2 lint-staged` throw err that `.git` can't be found ...
npx mrm@2 lint-staged. Failed. Fix the npm prepare script ... Reason: package.json file and .git directory are not at the same level.
Read more >
Lint-staged - Run Linters on Git Staged Files - Morioh
lint -staged is a simple to use tool to enforce code quality in teams. ... Instead of writing instructions on “how to setup...
Read more >
Setting up efficient workflows with ESLint, Prettier and ...
In this article I would like to start very easily and go into more depth from topic to topic. In the first step...
Read more >
line 3: 'react' must be in scope when using jsx react/react-in-jsx ...
It seems that the react-scripts was causing the lint errors for me. ... dist", "prebuild": "npm run clean-dist && npm run lint &&...
Read more >
xlsx - npm
Start using xlsx in your project by running `npm i xlsx`. ... a script tag: <script lang="javascript" src="dist/xlsx.full.min.js"></script>.
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