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 hang for nx monorepo

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:26 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
johannesschobelcommented, Sep 18, 2019

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:

module.exports = {
  '{apps,libs}/**/*.{ts,json,md,scss,html}': files => {
    return [
      `npm run affected:lint -- --fix --parallel --files=${files.join(',')}`,
      'npm run format:write -- --uncommitted',
      `git add ${files.join(' ')}`,
    ];
  },
};

Note that for the affected:lint you need to separate the files by , and for the git 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!

4reactions
Stupidismcommented, Dec 25, 2020

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?

Enlightening! You saved my life!

  "scripts": {
+    "eslint:fix": "eslint --fix",
  },
  "lint-staged": {
    "**/*.{ts,tsx,js,jsx,json,md,scss,html}": [
-      "npm run affected:lint  -- --uncommitted --parallel -- --fix",
+      "npm run eslint:fix",
      "npm run format:write -- --uncommitted"
    ]

Lint like flight~~~

Read more comments on GitHub >

github_iconTop Results From Across the Web

affected:lint with lint-staged hangs in nx monorepo · Issue #869
I am using affected:lint with lint-staged and noticed it hangs forever when I run npx lint-staged . wonder if I am doing something...
Read more >
affected:lint with lint-staged hangs in nx monorepo
I am using affected:lint with lint-staged and noticed it hangs forever when I run npx lint-staged . wonder if I am doing something...
Read more >
Create an Nx Workspace with prettier, husky and lint-staged
In this lesson we create a new empty Nx Workspace by running `yarn create ... the a pre-commit hook in husky and make...
Read more >
Affected - Nx
As your workspace grows, retesting all projects becomes too slow. To address this Nx implements code change analysis to get the min set...
Read more >
Add env-var, lint-staged and etc. for nx workspace
Add env-var, lint-staged and etc. for nx workspace ; Add env-var. npm i --save env-var · $ · --save env-var added 1 package,...
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