lint-staged / lint-staged

🚫💩 — Run linters on git staged files
https://www.npmjs.com/package/lint-staged
MIT License
13.3k stars 418 forks source link

ESLint can't find a configuration file when running lint-staged pre-commit hook #1140

Closed nc-csl closed 2 years ago

nc-csl commented 2 years ago

Description

I am trying to add pre-commit hooks to my project. I had some issues when running npx mrm@2 lint-staged because my package.json is not in the same folder as my .git folder. So that gave me an error. I then created an empty .git folder next to my package.json, and installation went fine. The .husky folder was created, which I then moved next to the .git folder in my root directory.

After I moved the .husky folder, my lint-staged commands are now running, but I get an error when trying to run eslint. For some reason it can't find eslint config. If I run my command (npx eslint --fix) directly from powershell, it works fine.

I believe the issue is that my .husky/.git folder is not in the same folder as my package.json and my eslint config. So how do I tell lint-staged/husky that eslint config is placed in a different folder? Below you can see the error I get.

image

Debug Logs

expand to view ``` lint-staged:bin Running `lint-staged@12.4.0` +0ms lint-staged:bin Options parsed from command-line: { allowEmpty: false, concurrent: true, configPath: undefined, cwd: undefined, debug: true, maxArgLength: null, 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 `C:\Users\csl\Documents\Arbejde\BBR` +0ms lint-staged:resolveGitRepo Resolving git repo from `C:\Users\csl\Documents\Arbejde\BBR` +0ms lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`) +1ms lint-staged:execGit Running git command [ 'rev-parse', '--show-prefix' ] +0ms lint-staged:resolveGitRepo Resolved git directory to be `C:/Users/csl/Documents/Arbejde/BBR` +71ms lint-staged:resolveGitRepo Resolved git config directory to be `C:/Users/csl/Documents/Arbejde/BBR/.git` +1ms lint-staged:execGit Running git command [ 'log', '-1' ] +73ms lint-staged:execGit Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +66ms lint-staged:runAll Loaded list of staged files in git: lint-staged:runAll [ lint-staged:runAll 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/website/package.json', lint-staged:runAll 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/website/src/stores/modal.ts' lint-staged:runAll ] +213ms lint-staged:searchConfigs Searching for configuration files... +0ms lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ] +75ms lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ] +105ms lint-staged:searchConfigs Found possible config files: [ 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-animate/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-hotkeys/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-local-storage/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-smart-table/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-ui-router-title/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/bootstrap-sass-official/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/circular-json/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/javascript-detect-element-resize/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/jszip/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/website/package.json', 'C:/Users/csl/Documents/Arbejde/BBR/package.json' ] +603ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-animate/package.json`... +0ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-hotkeys/package.json`... +4ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-local-storage/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-smart-table/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular-ui-router-title/package.json`... +0ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/angular/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/bootstrap-sass-official/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/circular-json/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/javascript-detect-element-resize/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/content/_source/js/bower_components/jszip/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/BBR.UI/package.json`... +2ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/website/package.json`... +1ms lint-staged:loadConfig Loading configuration from `C:/Users/csl/Documents/Arbejde/BBR/package.json`... +1ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\angular-animate\package.json`: lint-staged:loadConfig null +2ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\angular-hotkeys\package.json`: lint-staged:loadConfig null +0ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\angular-local-storage\package.json`: lint-staged:loadConfig null +1ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\angular-smart-table\package.json`: lint-staged:loadConfig null +0ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\angular-ui-router-title\package.json`: lint-staged:loadConfig null +1ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\angular\package.json`: lint-staged:loadConfig null +0ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\bootstrap-sass-official\package.json`: lint-staged:loadConfig null +1ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\circular-json\package.json`: lint-staged:loadConfig null +1ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\javascript-detect-element-resize\package.json`: lint-staged:loadConfig null +0ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\content\_source\js\bower_components\jszip\package.json`: lint-staged:loadConfig null +1ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\BBR.UI\package.json`: lint-staged:loadConfig null +0ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\package.json`: lint-staged:loadConfig null +1ms lint-staged:loadConfig Successfully loaded config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\website\package.json`: lint-staged:loadConfig { lint-staged:loadConfig '*.{js,jsx,vue,ts,tsx}': [ lint-staged:loadConfig 'npx prettier --write "**/*.{vue,ts}"', lint-staged:loadConfig 'npx eslint "**/*.{ts,vue}" --fix' lint-staged:loadConfig ] lint-staged:loadConfig } +0ms lint-staged:validateConfig Validating config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\website\package.json`... +0ms lint-staged:validateConfig Validated config from `C:\Users\csl\Documents\Arbejde\BBR\Code\BBR\website\package.json`: +5ms lint-staged:validateConfig { lint-staged:validateConfig '*.{js,jsx,vue,ts,tsx}': [ 'npx prettier --write "**/*.{vue,ts}"', 'npx eslint "**/*.{ts,vue}" --fix' ] lint-staged:validateConfig } +2ms lint-staged:searchConfigs Found 1 config files +33ms lint-staged:groupFilesByConfig Grouping 2 files by 1 configurations +0ms lint-staged:chunkFiles Skip chunking files because of undefined maxArgLength +0ms lint-staged:generateTasks Generating linter tasks +0ms lint-staged:generateTasks Generated task: lint-staged:generateTasks { lint-staged:generateTasks pattern: '*.{js,jsx,vue,ts,tsx}', lint-staged:generateTasks commands: [ lint-staged:generateTasks 'npx prettier --write "**/*.{vue,ts}"', lint-staged:generateTasks 'npx eslint "**/*.{ts,vue}" --fix' lint-staged:generateTasks ], lint-staged:generateTasks fileList: [ lint-staged:generateTasks 'C:/Users/csl/Documents/Arbejde/BBR/Code/BBR/website/src/stores/modal.ts' lint-staged:generateTasks ] lint-staged:generateTasks } +4ms lint-staged:makeCmdTasks Creating listr tasks for commands [ 'npx prettier --write "**/*.{vue,ts}"', 'npx eslint "**/*.{ts,vue}" --fix' ] +0ms lint-staged:resolveTaskFn cmd: npx +0ms lint-staged:resolveTaskFn args: [ 'prettier', '--write', '**/*.{vue,ts}' ] +1ms lint-staged:resolveTaskFn execaOptions: { cwd: 'C:\\Users\\csl\\Documents\\Arbejde\\BBR', preferLocal: true, reject: false, shell: false } +0ms lint-staged:resolveTaskFn cmd: npx +2ms lint-staged:resolveTaskFn args: [ 'eslint', '**/*.{ts,vue}', '--fix' ] +0ms lint-staged:resolveTaskFn execaOptions: { cwd: 'C:\\Users\\csl\\Documents\\Arbejde\\BBR', preferLocal: true, reject: false, shell: false } +1ms lint-staged:chunkFiles Skip chunking files because of undefined maxArgLength +16ms [STARTED] Preparing lint-staged... lint-staged:GitWorkflow Backing up original state... +0ms lint-staged:GitWorkflow Getting partially staged files... +1ms lint-staged:execGit Running git command [ 'status', '-z' ] +558ms lint-staged:GitWorkflow Found partially staged files: [ 'Code/BBR/website/package.json' ] +225ms lint-staged:execGit Running git command [ 'diff', '--binary', '--unified=0', '--no-color', '--no-ext-diff', '--src-prefix=a/', '--dst-prefix=b/', '--patch', '--submodule=short', '--output', 'C:\\Users\\csl\\Documents\\Arbejde\\BBR\\.git\\lint-staged_unstaged.patch', '--', 'Code/BBR/website/package.json' ] +221ms lint-staged:GitWorkflow Backing up merge state... +91ms lint-staged:file Reading file `C:\Users\csl\Documents\Arbejde\BBR\.git\MERGE_HEAD` +0ms lint-staged:file Reading file `C:\Users\csl\Documents\Arbejde\BBR\.git\MERGE_MODE` +2ms lint-staged:file Reading file `C:\Users\csl\Documents\Arbejde\BBR\.git\MERGE_MSG` +2ms lint-staged:file File `C:\Users\csl\Documents\Arbejde\BBR\.git\MERGE_HEAD` doesn't exist, ignoring... +1ms lint-staged:file File `C:\Users\csl\Documents\Arbejde\BBR\.git\MERGE_MODE` doesn't exist, ignoring... +1ms lint-staged:file File `C:\Users\csl\Documents\Arbejde\BBR\.git\MERGE_MSG` doesn't exist, ignoring... +0ms lint-staged:GitWorkflow Done backing up merge state! +8ms lint-staged:GitWorkflow Getting deleted files... +0ms lint-staged:execGit Running git command [ 'ls-files', '--deleted' ] +100ms lint-staged:GitWorkflow Found deleted files: [] +1s lint-staged:execGit Running git command [ 'stash', 'create' ] +1s lint-staged:execGit Running git command [ 'stash', 'store', '--quiet', '--message', 'lint-staged automatic backup', '618a020addcbfa7e7d826f538f7d3b5fb4f3a20d' ] +327ms lint-staged:GitWorkflow Done backing up original state! +402ms [SUCCESS] Preparing lint-staged... [STARTED] Hiding unstaged changes to partially staged files... lint-staged:execGit Running git command [ 'checkout', '--force', '--', 'Code/BBR/website/package.json' ] +77ms [SUCCESS] Hiding unstaged changes to partially staged files... [STARTED] Running tasks for staged files... [STARTED] Code/BBR/website/package.json — 2 files [STARTED] *.{js,jsx,vue,ts,tsx} — 1 file [STARTED] npx prettier --write "**/*.{vue,ts}" [SUCCESS] npx prettier --write "**/*.{vue,ts}" [STARTED] npx eslint "**/*.{ts,vue}" --fix [FAILED] npx eslint "**/*.{ts,vue}" --fix [FAILED] [FAILED] npx eslint "**/*.{ts,vue}" --fix [FAILED] [SUCCESS] Running tasks for staged files... lint-staged:GitWorkflow Restoring original state... +23s [STARTED] Applying modifications from tasks... [SKIPPED] Skipped because of errors from tasks. [STARTED] Restoring unstaged changes to partially staged files... [SKIPPED] Skipped because of errors from tasks. [STARTED] Reverting to original state because of errors... lint-staged:execGit Running git command [ 'reset', '--hard', 'HEAD' ] +23s lint-staged:execGit Running git command [ 'stash', 'list' ] +1s lint-staged:execGit Running git command [ 'stash', 'apply', '--quiet', '--index', 'refs/stash@{0}' ] +102ms lint-staged:GitWorkflow Restoring merge state... +2s lint-staged:GitWorkflow Done restoring merge state! +1ms lint-staged:file Removing file `C:\Users\csl\Documents\Arbejde\BBR\.git\lint-staged_unstaged.patch` +27s lint-staged:GitWorkflow Done restoring original state! +5ms [SUCCESS] Reverting to original state because of errors... [STARTED] Cleaning up temporary files... lint-staged:GitWorkflow Dropping backup stash... +3ms lint-staged:execGit Running git command [ 'stash', 'list' ] +686ms lint-staged:execGit Running git command [ 'stash', 'drop', '--quiet', 'refs/stash@{0}' ] +97ms lint-staged:GitWorkflow Done dropping backup stash! +205ms [SUCCESS] Cleaning up temporary files... ```

Environment

nc-csl commented 2 years ago

I found the solution right here: https://github.com/okonet/lint-staged/issues/961