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
Running in a subdirectory of a git repo incorrectly runs in other directories #1132
Comments
Please post debug logs using |
oops sorry, here they are: expand to view
|
Thanks... looks like the multiple config feature now means it will find all configs from the git repo, even if your |
The monorepo section in the README indicates that cwd only is the expected behavior. That’s how we (and I’m assuming many others) are using the tool, with different lint configurations per directory. |
Getting a related issue with my monorepo setup in I would like to avoid moving linting to the root, to leverage each sub-project's configuration and for them to be stay self-contained. Note : I do not have ESLint, Prettier, or TS installed on the root, they are in each sub-project. Added debug logs there, where a similar error message was found: |
I can leave out configs outside the So I think this might work:
|
By the way, I can also confirm that version |
@alex-grover and @verekia can you checkout the code in PR #1133 and see if it fixes your issues? The lint-staged npm module is native ESM so you can pretty much just copy-paste the |
Thank you for looking into this so fast :) I loaded Debug logsyarn run v1.22.17 $ lint-staged --debug lint-staged:bin Running `lint-staged@12.3.7` +0ms lint-staged:bin Options parsed from command-line: { allowEmpty: false, concurrent: true, configPath: undefined, cwd: undefined, debug: true, maxArgLength: 131072, quiet: false, relative: false, shell: false, stash: true, verbose: false } +0ms lint-staged:validateOptions Validating options... +0ms lint-staged:validateOptions Validated options! +0ms lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +0ms lint-staged:runAll Running all linter scripts... +0ms lint-staged:runAll Using working directory `/Users/verekia/Local/Code/private-projects/apps/learnthai` +0ms lint-staged:resolveGitRepo Resolving git repo from `/Users/verekia/Local/Code/private-projects/apps/learnthai` +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 `/Users/verekia/Local/Code/private-projects` +13ms lint-staged:resolveGitRepo Resolved git config directory to be `/Users/verekia/Local/Code/private-projects/.git` +0ms lint-staged:execGit Running git command [ 'log', '-1' ] +13ms lint-staged:execGit Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +15ms lint-staged:runAll Loaded list of staged files in git: lint-staged:runAll [ lint-staged:runAll '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:runAll ] +38ms lint-staged:searchConfigs Searching for configuration files... +0ms lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ] +11ms lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ] +12ms lint-staged:searchConfigs Found possible config files: [ '/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json' ] +26ms lint-staged:loadConfig Loading configuration from `/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json`... +0ms lint-staged:loadConfig Successfully loaded config from `/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json`: lint-staged:loadConfig { lint-staged:loadConfig '*.{ts,tsx}': [ 'tsc-files' ], lint-staged:loadConfig '*.{js,jsx,ts,tsx}': [ 'eslint' ], lint-staged:loadConfig '*.{js,jsx,ts,tsx,json,html,css,md,gql,graphql}': [ 'prettier -c' ] lint-staged:loadConfig } +0ms lint-staged:validateConfig Validating config from `/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json`... +0ms lint-staged:validateConfig Validated config from `/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json`: +1ms lint-staged:validateConfig { lint-staged:validateConfig '*.{ts,tsx}': [ 'tsc-files' ], lint-staged:validateConfig '*.{js,jsx,ts,tsx}': [ 'eslint' ], lint-staged:validateConfig '*.{js,jsx,ts,tsx,json,html,css,md,gql,graphql}': [ 'prettier -c' ] lint-staged:validateConfig } +0ms lint-staged:searchConfigs Found 1 config files +2ms lint-staged:groupFilesByConfig Grouping 1 files by 1 configurations +0ms lint-staged:chunkFiles Resolved an argument string length of 78 characters from 1 files +0ms lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms lint-staged:generateTasks Generating linter tasks +0ms lint-staged:generateTasks Generated task: lint-staged:generateTasks { lint-staged:generateTasks pattern: '*.{ts,tsx}', lint-staged:generateTasks commands: [ 'tsc-files' ], lint-staged:generateTasks fileList: [ lint-staged:generateTasks '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:generateTasks ] lint-staged:generateTasks } +1ms lint-staged:generateTasks Generated task: lint-staged:generateTasks { lint-staged:generateTasks pattern: '*.{js,jsx,ts,tsx}', lint-staged:generateTasks commands: [ 'eslint' ], lint-staged:generateTasks fileList: [ lint-staged:generateTasks '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:generateTasks ] lint-staged:generateTasks } +0ms lint-staged:generateTasks Generated task: lint-staged:generateTasks { lint-staged:generateTasks pattern: '*.{js,jsx,ts,tsx,json,html,css,md,gql,graphql}', lint-staged:generateTasks commands: [ 'prettier -c' ], lint-staged:generateTasks fileList: [ lint-staged:generateTasks '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:generateTasks ] lint-staged:generateTasks } +0ms lint-staged:makeCmdTasks Creating listr tasks for commands [ 'tsc-files' ] +0ms lint-staged:resolveTaskFn cmd: tsc-files +0ms lint-staged:resolveTaskFn args: [] +0ms lint-staged:resolveTaskFn execaOptions: { cwd: '/Users/verekia/Local/Code/private-projects/apps/learnthai', preferLocal: true, reject: false, shell: false } +0ms lint-staged:makeCmdTasks Creating listr tasks for commands [ 'eslint' ] +1ms lint-staged:resolveTaskFn cmd: eslint +1ms lint-staged:resolveTaskFn args: [] +0ms lint-staged:resolveTaskFn execaOptions: { cwd: '/Users/verekia/Local/Code/private-projects/apps/learnthai', preferLocal: true, reject: false, shell: false } +0ms lint-staged:makeCmdTasks Creating listr tasks for commands [ 'prettier -c' ] +1ms lint-staged:resolveTaskFn cmd: prettier +0ms lint-staged:resolveTaskFn args: [ '-c' ] +0ms lint-staged:resolveTaskFn execaOptions: { cwd: '/Users/verekia/Local/Code/private-projects/apps/learnthai', preferLocal: true, reject: false, shell: false } +0ms lint-staged:chunkFiles Resolved an argument string length of 78 characters from 1 files +3ms lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms [STARTED] Preparing lint-staged... lint-staged:GitWorkflow Backing up original state... +0ms lint-staged:GitWorkflow Getting partially staged files... +0ms lint-staged:execGit Running git command [ 'status', '-z' ] +22ms lint-staged:GitWorkflow Found partially staged files: [] +16ms lint-staged:GitWorkflow Backing up merge state... +0ms lint-staged:file Reading file `/Users/verekia/Local/Code/private-projects/.git/MERGE_HEAD` +0ms lint-staged:file Reading file `/Users/verekia/Local/Code/private-projects/.git/MERGE_MODE` +0ms lint-staged:file Reading file `/Users/verekia/Local/Code/private-projects/.git/MERGE_MSG` +0ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/MERGE_MODE` doesn't exist, ignoring... +0ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/MERGE_MSG` doesn't exist, ignoring... +0ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/MERGE_HEAD` doesn't exist, ignoring... +0ms lint-staged:GitWorkflow Done backing up merge state! +0ms lint-staged:GitWorkflow Getting deleted files... +0ms lint-staged:execGit Running git command [ 'ls-files', '--deleted' ] +16ms lint-staged:GitWorkflow Found deleted files: [] +11ms lint-staged:execGit Running git command [ 'stash', 'create' ] +12ms lint-staged:execGit Running git command [ 'stash', 'store', '--quiet', '--message', 'lint-staged automatic backup', '32c3e48de5aae5d0b2462235b1623777ab973041' ] +24ms lint-staged:GitWorkflow Done backing up original state! +35ms [SUCCESS] Preparing lint-staged... [STARTED] Running tasks for staged files... [STARTED] package.json — 1 file [STARTED] *.{ts,tsx} — 1 file [STARTED] *.{js,jsx,ts,tsx} — 1 file [STARTED] *.{js,jsx,ts,tsx,json,html,css,md,gql,graphql} — 1 file [STARTED] tsc-files [STARTED] eslint [STARTED] prettier -c [FAILED] prettier -c [FAILED] [FAILED] prettier -c [FAILED] [SUCCESS] Running tasks for staged files... [STARTED] Applying modifications from tasks... [SKIPPED] Skipped because of errors from tasks. [STARTED] Reverting to original state because of errors... lint-staged:GitWorkflow Restoring original state... +324ms lint-staged:execGit Running git command [ 'reset', '--hard', 'HEAD' ] +334ms lint-staged:execGit Running git command [ 'stash', 'list' ] +44ms lint-staged:execGit Running git command [ 'stash', 'apply', '--quiet', '--index', 'refs/stash@{0}' ] +17ms [FAILED] eslint [KILLED] [FAILED] eslint [KILLED] lint-staged:GitWorkflow Restoring merge state... +119ms lint-staged:GitWorkflow Done restoring merge state! +0ms lint-staged:file Removing file `/Users/verekia/Local/Code/private-projects/.git/lint-staged_unstaged.patch` +489ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/lint-staged_unstaged.patch` doesn't exist, ignoring... +1ms lint-staged:GitWorkflow Done restoring original state! +1ms [SUCCESS] Reverting to original state because of errors... [STARTED] Cleaning up temporary files... lint-staged:GitWorkflow Dropping backup stash... +0ms lint-staged:execGit Running git command [ 'stash', 'list' ] +59ms lint-staged:execGit Running git command [ 'stash', 'drop', '--quiet', 'refs/stash@{0}' ] +13ms lint-staged:GitWorkflow Done dropping backup stash! +27ms [SUCCESS] Cleaning up temporary files... |
That seems to be a separate issue related to #1117. Maybe I can add some try/catch, because if the process is not found, it's probably already quit. |
@verekia I pushed a commit that ignores errors from |
The I run 3 tasks : Prettier, ESLint, and TS check Also, when using Debug logs$ lint-staged --debug lint-staged:bin Running `lint-staged@12.3.7` +0ms lint-staged:bin Options parsed from command-line: { allowEmpty: false, concurrent: true, configPath: undefined, cwd: undefined, debug: true, maxArgLength: 131072, quiet: false, relative: false, shell: false, stash: true, verbose: false } +1ms lint-staged:validateOptions Validating options... +0ms lint-staged:validateOptions Validated options! +0ms lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +0ms lint-staged:runAll Running all linter scripts... +0ms lint-staged:runAll Using working directory `/Users/verekia/Local/Code/private-projects/apps/learnthai` +0ms lint-staged:resolveGitRepo Resolving git repo from `/Users/verekia/Local/Code/private-projects/apps/learnthai` +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 `/Users/verekia/Local/Code/private-projects` +13ms lint-staged:resolveGitRepo Resolved git config directory to be `/Users/verekia/Local/Code/private-projects/.git` +0ms lint-staged:execGit Running git command [ 'log', '-1' ] +13ms lint-staged:execGit Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +13ms lint-staged:runAll Loaded list of staged files in git: lint-staged:runAll [ lint-staged:runAll '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:runAll ] +36ms lint-staged:searchConfigs Searching for configuration files... +0ms lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ] +10ms lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ] +11ms lint-staged:searchConfigs Found possible config files: [ '/Users/verekia/Local/Code/private-projects/apps/learnthai/.lintstagedrc.js', '/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json' ] +27ms lint-staged:loadConfig Loading configuration from `/Users/verekia/Local/Code/private-projects/apps/learnthai/.lintstagedrc.js`... +0ms lint-staged:loadConfig Loading configuration from `/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json`... +0ms lint-staged:loadConfig Successfully loaded config from `/Users/verekia/Local/Code/private-projects/apps/learnthai/package.json`: lint-staged:loadConfig null +1ms lint-staged:loadConfig Successfully loaded config from `/Users/verekia/Local/Code/private-projects/apps/learnthai/.lintstagedrc.js`: lint-staged:loadConfig { lint-staged:loadConfig '*.{ts,tsx}': [ 'tsc-files' ], lint-staged:loadConfig '*.{js,jsx,ts,tsx}': [ 'eslint' ], lint-staged:loadConfig '*.{js,jsx,ts,tsx,json,html,css,md,gql,graphql}': [ 'prettier -c' ] lint-staged:loadConfig } +2ms lint-staged:validateConfig Validating config from `/Users/verekia/Local/Code/private-projects/apps/learnthai/.lintstagedrc.js`... +0ms lint-staged:validateConfig Validated config from `/Users/verekia/Local/Code/private-projects/apps/learnthai/.lintstagedrc.js`: +0ms lint-staged:validateConfig { lint-staged:validateConfig '*.{ts,tsx}': [ 'tsc-files' ], lint-staged:validateConfig '*.{js,jsx,ts,tsx}': [ 'eslint' ], lint-staged:validateConfig '*.{js,jsx,ts,tsx,json,html,css,md,gql,graphql}': [ 'prettier -c' ] lint-staged:validateConfig } +1ms lint-staged:searchConfigs Found 1 config files +4ms lint-staged:groupFilesByConfig Grouping 1 files by 1 configurations +0ms lint-staged:chunkFiles Resolved an argument string length of 78 characters from 1 files +0ms lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms lint-staged:generateTasks Generating linter tasks +0ms lint-staged:generateTasks Generated task: lint-staged:generateTasks { lint-staged:generateTasks pattern: '*.{ts,tsx}', lint-staged:generateTasks commands: [ 'tsc-files' ], lint-staged:generateTasks fileList: [ lint-staged:generateTasks '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:generateTasks ] lint-staged:generateTasks } +1ms lint-staged:generateTasks Generated task: lint-staged:generateTasks { lint-staged:generateTasks pattern: '*.{js,jsx,ts,tsx}', lint-staged:generateTasks commands: [ 'eslint' ], lint-staged:generateTasks fileList: [ lint-staged:generateTasks '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:generateTasks ] lint-staged:generateTasks } +0ms lint-staged:generateTasks Generated task: lint-staged:generateTasks { lint-staged:generateTasks pattern: '*.{js,jsx,ts,tsx,json,html,css,md,gql,graphql}', lint-staged:generateTasks commands: [ 'prettier -c' ], lint-staged:generateTasks fileList: [ lint-staged:generateTasks '/Users/verekia/Local/Code/private-projects/apps/learnthai/src/lib/create-id.ts' lint-staged:generateTasks ] lint-staged:generateTasks } +0ms lint-staged:makeCmdTasks Creating listr tasks for commands [ 'tsc-files' ] +0ms lint-staged:resolveTaskFn cmd: tsc-files +0ms lint-staged:resolveTaskFn args: [] +1ms lint-staged:resolveTaskFn execaOptions: { cwd: '/Users/verekia/Local/Code/private-projects/apps/learnthai', preferLocal: true, reject: false, shell: false } +0ms lint-staged:makeCmdTasks Creating listr tasks for commands [ 'eslint' ] +1ms lint-staged:resolveTaskFn cmd: eslint +0ms lint-staged:resolveTaskFn args: [] +0ms lint-staged:resolveTaskFn execaOptions: { cwd: '/Users/verekia/Local/Code/private-projects/apps/learnthai', preferLocal: true, reject: false, shell: false } +0ms lint-staged:makeCmdTasks Creating listr tasks for commands [ 'prettier -c' ] +0ms lint-staged:resolveTaskFn cmd: prettier +0ms lint-staged:resolveTaskFn args: [ '-c' ] +0ms lint-staged:resolveTaskFn execaOptions: { cwd: '/Users/verekia/Local/Code/private-projects/apps/learnthai', preferLocal: true, reject: false, shell: false } +0ms lint-staged:chunkFiles Resolved an argument string length of 78 characters from 1 files +4ms lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms [STARTED] Preparing lint-staged... lint-staged:GitWorkflow Backing up original state... +0ms lint-staged:GitWorkflow Getting partially staged files... +0ms lint-staged:execGit Running git command [ 'status', '-z' ] +26ms lint-staged:GitWorkflow Found partially staged files: [] +16ms lint-staged:GitWorkflow Backing up merge state... +1ms lint-staged:file Reading file `/Users/verekia/Local/Code/private-projects/.git/MERGE_HEAD` +0ms lint-staged:file Reading file `/Users/verekia/Local/Code/private-projects/.git/MERGE_MODE` +0ms lint-staged:file Reading file `/Users/verekia/Local/Code/private-projects/.git/MERGE_MSG` +0ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/MERGE_HEAD` doesn't exist, ignoring... +0ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/MERGE_MODE` doesn't exist, ignoring... +0ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/MERGE_MSG` doesn't exist, ignoring... +0ms lint-staged:GitWorkflow Done backing up merge state! +0ms lint-staged:GitWorkflow Getting deleted files... +0ms lint-staged:execGit Running git command [ 'ls-files', '--deleted' ] +17ms lint-staged:GitWorkflow Found deleted files: [] +11ms lint-staged:execGit Running git command [ 'stash', 'create' ] +11ms lint-staged:execGit Running git command [ 'stash', 'store', '--quiet', '--message', 'lint-staged automatic backup', '7277eb434393358570d52128224e3e6d3902306d' ] +22ms lint-staged:GitWorkflow Done backing up original state! +33ms [SUCCESS] Preparing lint-staged... [STARTED] Running tasks for staged files... [STARTED] .lintstagedrc.js — 1 file [STARTED] *.{ts,tsx} — 1 file [STARTED] *.{js,jsx,ts,tsx} — 1 file [STARTED] *.{js,jsx,ts,tsx,json,html,css,md,gql,graphql} — 1 file [STARTED] tsc-files [STARTED] eslint [STARTED] prettier -c [FAILED] prettier -c [FAILED] [FAILED] prettier -c [FAILED] [SUCCESS] Running tasks for staged files... [STARTED] Applying modifications from tasks... [SKIPPED] Skipped because of errors from tasks. [STARTED] Reverting to original state because of errors... lint-staged:GitWorkflow Restoring original state... +355ms lint-staged:execGit Running git command [ 'reset', '--hard', 'HEAD' ] +366ms lint-staged:execGit Running git command [ 'stash', 'list' ] +71ms [FAILED] eslint [KILLED] [FAILED] eslint [KILLED] lint-staged:execGit Running git command [ 'stash', 'apply', '--quiet', '--index', 'refs/stash@{0}' ] +27ms lint-staged:GitWorkflow Restoring merge state... +144ms lint-staged:GitWorkflow Done restoring merge state! +0ms lint-staged:file Removing file `/Users/verekia/Local/Code/private-projects/.git/lint-staged_unstaged.patch` +543ms lint-staged:file File `/Users/verekia/Local/Code/private-projects/.git/lint-staged_unstaged.patch` doesn't exist, ignoring... +0ms lint-staged:GitWorkflow Done restoring original state! +0ms [SUCCESS] Reverting to original state because of errors... [STARTED] Cleaning up temporary files... lint-staged:GitWorkflow Dropping backup stash... +0ms lint-staged:execGit Running git command [ 'stash', 'list' ] +46ms lint-staged:execGit Running git command [ 'stash', 'drop', '--quiet', 'refs/stash@{0}' ] +12ms lint-staged:GitWorkflow Done dropping backup stash! +28ms [SUCCESS] Cleaning up temporary files... Edit: @iiroj I corrected this comment. It previously said that ESLint and TS should not run at all, but that was wrong. It's just that they should not report any problem. |
I mean, looks like one of your tasks failed and so the others were killed as well. That was the goal of PR #1117. |
But it doesn't exit cleanly. |
Are they still running when the failing task exits? If they are killed mid-run, how can one know they're not going to fail as well? Or do you just mean visually that the tasks should look like "skipped" instead of "failed"? |
You're right, sorry I didn't really understand what was going on, it's more clear now thanks to your comment. Also, the "TS build artifacts" I mentioned is not lint-staged's fault per se. It's because tsc-files creates temporary Anyway, so I guess it's just a matter of UI then, because it looks very messy when the processes are killed. The tree view appears 2 times which is quite overwhelming. I don't think that's intentional. If not I can open a new issue to stop polluting this one :) |
Can you open a separate issue of the duplicate log output? It might be because of an update to |
Opened here: #1134 |
@iiroj that PR does fix the issue for me! thanks for looking into this so quickly. here are the debug logs in case you need them. expand to view
|
Thanks for confirming, @alex-grover! I'll add some missing unit test coverage and try to get it released soon. |
I still observe the behaviour with lint-staged & husky, eg when I have changes in two separate folders with two separate rc files, both folders are validated. Debug log
|
Description
Running
lint-staged
in a subdirectory of a monorepo incorrectly runs scripts in other parts of the monorepo. Based on a quick look at recent issues and PRs I suspect it might be related to this change, but I'm not positive: #1093This bug does not exist in
lint-staged@11.2.6
, but does in12.3.7
(latest).Steps to reproduce
Basic reproduction:
https://github.com/alex-grover/lint-staged-bug
See the
run.sh
script for steps. It's a repo that looks like the following:Each
package.json
has alint-staged
configuration. If you make and stage changes in every directory, then runlint-staged
from inside ofa
orb
, all 3 scripts run rather than just the one in the current child directory.Debug Logs
expand to view
Environment
lint-staged
: 12.3.7The text was updated successfully, but these errors were encountered: