Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not all lintstagedrc.json files are found in the rush.js monorepo #1375

Open
maximilianfixl opened this issue Dec 9, 2023 · 4 comments
Open

Comments

@maximilianfixl
Copy link

maximilianfixl commented Dec 9, 2023

Description

In a rush.js monorepo, I expect lint-staged to report problems that eslint . --fix cannot solve independently and aborts the commit.
Currently all commits go through and malformed code is committed.

I assume that the child configuration files are not taken into account because the following echo commands do not appear on the console. The echo string appears in the configuration file in the root directory. I suspect this is also because the message No staged files found. appears.

Steps to reproduce

I have a monorepo with rush.js that has a /frontend and a /backend repository under the apps/ directory. These two repos are integrated as git submodules in the monorepo.

lint-staged is implemented in an autoinstaller package under common/autoinstallers/rush-lint-staged and is executed via the rush command rush lint-staged-apps.

According to the faqs for monorepos, I have stored the first (nearest) lintstagedrc.json in the root directory, the second lintstagedrc.json in /apps/frontend and also in /apps/backend.

I try to avoid the part of writing the configuration files in js and merging them, because in the project almost all configuration files are written in .json or .yaml and I want to keep the TypeScript project as js-free as possible. In addition, merging is not necessary because no configuration cascade is needed. Unless it leads to the solution of my problem.

monorepo   <-- own github repo
│   lintstagedrc.json
│   ...
│
└───apps
│   │
│   └───frontend   <-- own github repo (submodule in monorepo)
│   |   │   lintstagedrc.json
│   |
│   └───backend   <-- own github repo (submodule in monorepo)
│       │   lintstagedrc.json

lintstagedrc.json (root)

{
  "*": "echo lint-staged config file found! Go ahead..."
}

lintstagedrc.json (frontend and backend)

{
 "*": "echo lint-staged config file found in submodule! Lets lint!",
  "**/*.{js|ts|vue}": "eslint . --fix"
}

The eslintrc.json and .eslintignore files are available in the submodules. If I execute the eslint command on the console, I get the expected behavior.

I have already tested with all configurations in lint-staged and different patterns (micromatch), but I am not able to create the expected setup.

What else do I need to consider in my setup? Are there currently known problems that I have not yet recognized?

Debug Logs

expand to view
  lint-staged:bin Running `lint-staged@15.2.0` on Node.js v18.18.2 (win32) +0ms
  lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  cwd: undefined,
  debug: true,
  diff: undefined,
  diffFilter: undefined,
  maxArgLength: undefined,
  quiet: false,
  relative: false,
  shell: false,
  stash: false,
  hidePartiallyStaged: false,
  verbose: false
} +1ms
  lint-staged:validateOptions Validating options... +0ms
  lint-staged:validateOptions Validated options! +1ms
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +0ms
  lint-staged:runAll Running all linter scripts... +0ms
  lint-staged:runAll Using working directory `D:\Development\Projects\Xsigns\Vacarema\App\v2\monorepo` +0ms
  lint-staged:resolveGitRepo Resolving git repo from `D:\Development\Projects\Xsigns\Vacarema\App\v2\monorepo` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`) +0ms
  lint-staged:execGit Running git command [ 'rev-parse', '--show-prefix' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `D:/Development/Projects/Xsigns/Vacarema/App/v2/monorepo` +54ms
  lint-staged:resolveGitRepo Resolved git config directory to be `D:/Development/Projects/Xsigns/Vacarema/App/v2/monorepo/.git` +0ms
  lint-staged:execGit Running git command [ 'log', '-1' ] +54ms
‼ Skipping backup because `--no-stash` was used.

‼ Skipping hiding unstaged changes from partially staged files because `--no-stash` was used.

  lint-staged:execGit Running git command [ 'diff', '--name-only', '-z', '--diff-filter=ACMR', '--staged' ] +53ms
  lint-staged:runAll Loaded list of staged files in git:
  lint-staged:runAll [] +161ms
  lint-staged Tasks were executed successfully! +162ms
→ No staged files found.

Environment

  • OS: Windows 11, WSL
  • Node.js: 18.18.2
  • lint-staged: 15.2.0
@iiroj
Copy link
Member

iiroj commented Dec 9, 2023

In your debug logs there are no staged files, so can't really tell anything further...

Does it work as expected if you only have a single lint-staged config file?

@iiroj
Copy link
Member

iiroj commented Dec 9, 2023

Also, this file contains all the valid config filenames: https://github.com/lint-staged/lint-staged/blob/master/lib/configFiles.js

@maximilianfixl
Copy link
Author

In your debug logs there are no staged files, so can't really tell anything further...

Does it work as expected if you only have a single lint-staged config file?

Hi @iiroj,
thank you for your feedback.

Yes, that's what I wrote in my description. I probably should have worded the headline better.
Because no stages files can be found, I can assume that:

  • the configuration files in the children directories are not found and therefore the linter is not called at all
  • the glob pattern of the configuration file in the root directory does not point correctly to the underlying directories.

I suspect that since the actual lint-staged process in the rush project structure is called in common/scripts/install-run-rush.js, the path in the linstagedrc.json in the root directory does not actually arrive at apps/frontend.

@iiroj
Copy link
Member

iiroj commented Dec 10, 2023

In this case, lint-staged exists early without even getting to the configuration file loading part. Here's the relevant snip from your log:

  lint-staged:resolveGitRepo Resolved git directory to be `D:/Development/Projects/Xsigns/Vacarema/App/v2/monorepo` +54ms
  lint-staged:resolveGitRepo Resolved git config directory to be `D:/Development/Projects/Xsigns/Vacarema/App/v2/monorepo/.git` +0ms

...

  lint-staged:execGit Running git command [ 'diff', '--name-only', '-z', '--diff-filter=ACMR', '--staged' ] +53ms
  lint-staged:runAll Loaded list of staged files in git:
  lint-staged:runAll [] +161ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants