affected:lint with lint-staged hangs in nx monorepo

See original GitHub issue

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 wrong.

The command npm run affected:lint -- --uncommitted --fix --parallel itself runs fine.

  "lint-staged": {
    "{apps,libs}/**/*.{ts,json,md,scss}": [
      "npm run affected:lint  -- --uncommitted --fix --parallel",
      "npm run format:write -- --uncommitted",
      "git add"
    ]
  },

Ref: https://github.com/okonet/lint-staged/issues/522

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:23 (3 by maintainers)

github_iconTop GitHub Comments

29reactions
JoA-MoScommented, Jan 26, 2022

Thanks @meeroslav for confirming the = is not necessary. To amend the previous solution there is no need to use the lint-staged js configuration the following should work, and long list of files that exceed the command length max will be chunked correctly

.husky/pre-commit

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged --relative 

.lintstagedrc.json

{
  "*": ["nx affected:lint --fix --files", "nx format:write --files"]
}
3reactions
sourciercommented, Mar 19, 2022

The above is not working for me I get the following error:

❯ yarn run lint-staged
yarn run v1.22.17
$ /Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/.bin/lint-staged
✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ .lintstagedrc.json — 2 files
    ❯ * — 2 files
      ✖ nx affected:lint --fix --files [FAILED]
      ◼ nx format:write --files
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ nx affected:lint --fix --files:
nx affected:lint

Lint projects affected by changes

Run command using --base=[SHA1] (affected by the committed, uncommitted and untracked changes):
  --base  Base of the current branch (usually main)  [string]

or using --base=[SHA1] --head=[SHA2] (affected by the committed changes):
  --base  Base of the current branch (usually main)  [string]
  --head  Latest commit of the current branch (usually HEAD)  [string]

or using:
  --files        Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas  [array]
  --uncommitted  Uncommitted changes  [boolean]
  --untracked    Untracked changes  [boolean]

Options:
  --help           Show help  [boolean]
  --version        Show version number  [boolean]
  --parallel       Max number of parallel processes [default is 3]  [string]
  --all            All projects  [boolean]
  --exclude        Exclude certain projects from being processed  [array] [default: []]
  --runner         This is the name of the tasks runner configured in nx.json  [string]
  --skip-nx-cache  Rerun the tasks even when the results are available in the cache  [boolean] [default: false]
  --configuration  This is the configuration to use when performing tasks on projects  [string]
  --only-failed    Isolate projects which previously failed  [deprecated: The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.] [boolean] [default: false]
  --verbose        Print additional error stack trace on failure

Examples:
  affected:lint --parallel=5                     Run lint in parallel
  affected:lint --all                            Run the lint target for all projects
  affected:lint --files=libs/mylib/src/index.ts  Run lint for all the projects affected by changing the index.ts file
  affected:lint --base=main --head=HEAD          Run lint for all the projects affected by the changes between main and HEAD (e.g., PR)
  affected:lint --base=main~1 --head=main        Run lint for all the projects affected by the last commit on main

Find more information and examples at https://nx.dev/cli/affected-lint

RangeError: path should be a `path.relative()`d string, but got "/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/.lintstagedrc.json"
    at throwError (/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/ignore/index.js:364:9)
    at checkPath (/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/ignore/index.js:383:12)
    at Ignore._test (/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/ignore/index.js:504:5)
    at Ignore.ignores (/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/ignore/index.js:549:17)
    at /Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/@nrwl/workspace/src/core/file-utils.js:34:41
    at Array.filter (<anonymous>)
    at calculateFileChanges (/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/@nrwl/workspace/src/core/file-utils.js:34:19)
    at projectsToRun (/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/@nrwl/workspace/src/command-line/affected.js:91:108)
    at Object.<anonymous> (/Users/rrajaratnam/Tresors/Code/2022/sourcier-web/node_modules/@nrwl/workspace/src/command-line/affected.js:25:26)
    at Generator.next (<anonymous>)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
~/T/Code/2022/sourcier-web develop +3 ❯                                                         ▼ 02:30:38
Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
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 >
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 >
require is not defined in es module scope, you can use import ...
its in a nrwl/nx monorepo. any help is appreciated. I got my angular client side (well everything is housed in a monorepo apps...
Read more >
Using lint-staged, husky, and pre-commit hooks to fail fast and ...
Context switching kills productivity. Needlessly failed CI checks drag us between contexts after we have assumed our work is done.
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