lint-staged: lint-staged hang for nx monorepo
Description
Steps to reproduce
checkout develop branch
git clone https://github.com/xmlking/ngx-starter-kit -b develop
run lint-staged
npx lint-staged
this command hang forever.
you can run lint commands successfully e.g.
npm run affected:lint -- --uncommitted --fix --parallel
if you remove --fix --parallel
from lint-staged
command then the lint-staged
works
Debug Logs
expand to view
npx lint-staged -d
lint-staged:bin Running `lint-staged@8.0.0` +0ms
lint-staged:find-bin Loaded package.json using `process.cwd()` +0ms
lint-staged Loading config using `cosmiconfig` +0ms
lint-staged Successfully loaded config from `/Developer/Work/SPA/ngx-starter-kit/package.json`:
lint-staged { '{apps,libs}/**/*.{ts,json,md,scss}':
lint-staged [ 'npm run affected:lint -- --uncommitted --fix --parallel',
lint-staged 'npm run format:write -- --uncommitted',
lint-staged 'git add' ] } +3ms
lint-staged:cfg Normalizing config +0ms
lint-staged:cfg Validating config +2ms
Running lint-staged with the following config:
{
linters: {
'{apps,libs}/**/*.{ts,json,md,scss}': [
'npm run affected:lint -- --uncommitted --fix --parallel',
'npm run format:write -- --uncommitted',
'git add'
]
},
concurrent: true,
chunkSize: 9007199254740991,
globOptions: {
matchBase: true,
dot: true
},
ignore: [],
subTaskConcurrency: 1,
renderer: 'verbose'
}
lint-staged:run Running all linter scripts +0ms
lint-staged:run Resolved git directory to be `/Developer/Work/SPA/ngx-starter-kit` +1ms
lint-staged:run Loaded list of staged files in git:
lint-staged:run [ 'package.json',
lint-staged:run 'package-lock.json',
lint-staged:run 'libs/ngx-utils/src/lib/directives/router-link-match/router-link-match.directive.spec.ts',
lint-staged:run 'libs/ngx-utils/src/lib/directives/ng-let/ng-let.directive.spec.ts',
lint-staged:run 'libs/chat-box/src/lib/services/speech-to-text.service.ts',
lint-staged:run 'PLAYBOOK.md' ] +29ms
lint-staged:gen-tasks Generating linter tasks +0ms
lint-staged:cfg Normalizing config +34ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '{apps,libs}/**/*.{ts,json,md,scss}',
lint-staged:gen-tasks commands:
lint-staged:gen-tasks [ 'npm run affected:lint -- --uncommitted --fix --parallel',
lint-staged:gen-tasks 'npm run format:write -- --uncommitted',
lint-staged:gen-tasks 'git add' ],
lint-staged:gen-tasks fileList:
lint-staged:gen-tasks [ '/Developer/Work/SPA/ngx-starter-kit/libs/ngx-utils/src/lib/directives/router-link-match/router-link-match.directive.spec.ts',
lint-staged:gen-tasks '/Developer/Work/SPA/ngx-starter-kit/libs/ngx-utils/src/lib/directives/ng-let/ng-let.directive.spec.ts',
lint-staged:gen-tasks '/Developer/Work/SPA/ngx-starter-kit/libs/chat-box/src/lib/services/speech-to-text.service.ts' ] } +17ms
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running linters... [started]
Running tasks for {apps,libs}/**/*.{ts,json,md,scss} [started]
lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'npm run affected:lint -- --uncommitted --fix --parallel', 'npm run format:write -- --uncommitted', 'git add' ] +0ms
lint-staged:find-bin Resolving binary for command `npm run affected:lint -- --uncommitted --fix --parallel` +206ms
lint-staged:find-bin Binary for `npm run affected:lint -- --uncommitted --fix --parallel` resolved to `/Developer/Work/SPA/ngx-starter-kit/node_modules/.bin/npm` +3ms
lint-staged:task ✔ OS: darwin; File path chunking unnecessary +0ms
lint-staged:find-bin Resolving binary for command `npm run format:write -- --uncommitted` +0ms
lint-staged:find-bin Resolving binary for `npm` from cache +0ms
lint-staged:task ✔ OS: darwin; File path chunking unnecessary +0ms
lint-staged:find-bin Resolving binary for command `git add` +0ms
lint-staged:find-bin Binary for `git add` resolved to `/usr/local/bin/git` +1ms
lint-staged:task ✔ OS: darwin; File path chunking unnecessary +1ms
npm run affected:lint -- --uncommitted --fix --parallel [started]
lint-staged:task bin: /Developer/Work/SPA/ngx-starter-kit/node_modules/.bin/npm +0ms
lint-staged:task args: [ 'run',
lint-staged:task 'affected:lint',
lint-staged:task '--',
lint-staged:task '--uncommitted',
lint-staged:task '--fix',
lint-staged:task '--parallel',
lint-staged:task '/Developer/Work/SPA/ngx-starter-kit/libs/ngx-utils/src/lib/directives/router-link-match/router-link-match.directive.spec.ts',
lint-staged:task '/Developer/Work/SPA/ngx-starter-kit/libs/ngx-utils/src/lib/directives/ng-let/ng-let.directive.spec.ts',
lint-staged:task '/Developer/Work/SPA/ngx-starter-kit/libs/chat-box/src/lib/services/speech-to-text.service.ts' ] +0ms
lint-staged:task opts: { reject: false } +1ms
Environment
- OS:
- Node.js: 10
lint-staged
: v8.0.2
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 26 (3 by maintainers)
Dear @iiroj , thanks for coming back with another idea. I tried your approach (i.e., moving the config to a dedicated file and not having it in the package.json).
This separate config file is used - i can see this, because i changed the glob-file-pattern (i.e., i removed the
html
type). However, it still shows the respective error.However, when digging into the
nx affected:lint
command, i found a--files
param, that takes a list of all files to be used - this can be used as a replacement for the--uncommited
.In this context, i changed your config file from above to this one here:
Note that for the
affected:lint
you need to separate the files by,
and for thegit
command by' '
. For now, this command runs as expected… I tried a commit that previously failed and it now properly commits. I will keep an eye 👀 on this 😆Thanks a lot for pointing me into the (hopefully) right direction! You’re awesome!
Enlightening! You saved my life!
Lint like flight~~~
Hi all,
I’m not fully understanding why you nees to run the affected:lint script inside lintstaged. Lintstaged will provide the paths to the files that changed, so we only need to lint these files, not the whole projects affected by these paths, right? By the way, I don’t find any use case for affected:lint script. Could someone clarify this?
Hi guys, I can confirm I have the same issue with almost the same setup, mine just includes stylelint as an additional linter. What do you need me to provide you?
Running into the same issue. Strange because I have my company monorepo with the same configuration and it’s not a problem at all. This is a new package and it just hangs and hangs at the end of the run. Showing complete when I run with
-d
.I think
npm run affected:lint --fix --file
is a bad candidate for linting on commit because it could unwrap a list of changed files into all files in the project.Dear @dsebastien ,
i did something similar. My code, however, looks like this:
Note, that my lint-staged script also adds them back to the git. However, the
git add
command still needs theabsolute paths
, so i need both… kind of stupid, but whatever 😄I could fix it with the following changes:
@johannesschobel You are welcome! A lot of issues with Angular seem to be solvable by using the new javascript syntax for configuration.
Yes,
npm run affected:lint -- --uncommited --fix --parallel
works, but if you append it with the absolute filepaths of staged files (aslint-staged
does), it will fail becauseng
treats them as flags.So after staging changes in
./libs/ngx-utils/src/lib/directives/router-link-match/router-link-match.directive.spec.ts
, this fails:npm run affected:lint -- --uncommitted --fix --parallel /git/ngx-starter-kit/libs/ngx-utils/src/lib/directives/router-link-match/router-link-match.directive.spec.ts
Can you try running it with the example configuration I provided?
This might be because the
ng
command treats the staged filepaths added bylint-staged
as flags rather than input files.For what it’s worth, when trying to run the command found in the debug log it also fails:
View logs
I’d wager to get it working you should write the
lint-staged
config in JS and omit the filenames:This is of course assuming the
--uncommitted
flag means that the command itself finds the files it will lint and format.