Files altered by linting tools are not commited anymore in v9.0.1
See original GitHub issueHi, ✋
Description
After upgrading to lint-staged 9 and updated our config file from:
{
"relative": true,
"linters": {
"*.php": [
"./vagrant-wrapper.sh php bin/php-cs-fixer fix --config .php_cs.dist --diff",
"./vagrant-wrapper.sh php bin/phpstan analyse --level 7 --no-ansi --no-progress",
"git add"
],
"assets/**/*.{js,jsx,vue}": [
"eslint --fix",
"git add"
],
"*.{json,yml,yaml,md}": [
"prettier --write",
"git add"
]
}
}
to this (the old way was better, but w/e 😞) :
const path = require('path');
function makeRelativePaths(absolutePaths) {
const cwd = process.cwd();
return absolutePaths.map(file => path.relative(cwd, file));
}
module.exports = {
'*.php': (absolutePaths) => {
const relativePaths = makeRelativePaths(absolutePaths);
return [
`./vagrant-wrapper.sh php bin/php-cs-fixer fix --config .php_cs.dist --diff ${relativePaths.join(' ')}`,
`./vagrant-wrapper.sh php bin/phpstan analyse --level 7 --no-ansi --no-progress ${relativePaths.join(' ')}`,
`git add ${relativePaths.join(' ')}`,
];
},
'assets/**/*.{js,jsx,vue}': (absolutePaths) => {
const relativePaths = makeRelativePaths(absolutePaths);
return [
`eslint --fix ${relativePaths.join(' ')}`,
`git add ${relativePaths.join(' ')}`,
];
},
'*.{json,yml,yaml,md}': (absolutePaths) => {
const relativePaths = makeRelativePaths(absolutePaths);
return [
`prettier --write ${relativePaths.join(' ')}`,
`git add ${relativePaths.join(' ')}`,
];
},
};
It seems that files are not added anymore to the commit after being processed by ESLint, Prettier, PHP-CS-Fixer, […].
Running git diff
, the file has been linted but not commited:
Steps to reproduce
- Edit a file that will be matched by linters glob patterns
- Git add this file
- Git commit this file
- Husky triggers lint-staged, that will execute some commands (ESLint +
git add
in my case) - The file is commited, but not the linted version (after being processed by ESLint)
Debug Logs
expand to view
husky > pre-commit (node v11.5.0)
lint-staged:bin Running `lint-staged@9.0.1` +0ms
lint-staged Loading config using `cosmiconfig` +0ms
lint-staged Successfully loaded config from `/path/to/app/.lintstagedrc.js`:
lint-staged { '*.php': [Function: *.php],
lint-staged 'assets/**/*.{js,jsx,vue}': [Function: assets/**/*.{js,jsx,vue}],
lint-staged '*.{json,yml,yaml,md}': [Function: *.{json,yml,yaml,md}] } +6ms
lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
'*.php': (absolutePaths) => {
const relativePaths = makeRelativePaths(absolutePaths);
return [
`./vagrant-wrapper.sh php bin/php-cs-fixer fix --config .php_cs.dist --diff ${relativePaths.join(' ')}`,
`./vagrant-wrapper.sh php bin/phpstan analyse --level 7 --no-ansi --no-progress ${relativePaths.join(' ')}`,
`git add ${relativePaths.join(' ')}`,
];
},
'assets/**/*.{js,jsx,vue}': (absolutePaths) => {
const relativePaths = makeRelativePaths(absolutePaths);
return [
`eslint --fix ${relativePaths.join(' ')}`,
`git add ${relativePaths.join(' ')}`,
];
},
'*.{json,yml,yaml,md}': (absolutePaths) => {
const relativePaths = makeRelativePaths(absolutePaths);
return [
`prettier --write ${relativePaths.join(' ')}`,
`git add ${relativePaths.join(' ')}`,
];
}
}
lint-staged:run Running all linter scripts +0ms
lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
lint-staged:run Resolved git directory to be `/path/to/app` +13ms
lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACM', '--name-only' ] +13ms
lint-staged:run Loaded list of staged files in git:
lint-staged:run [ 'assets/app/index.js' ] +8ms
lint-staged:gen-tasks Generating linter tasks +0ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '*.php', commands: [Function: *.php], fileList: [] } +2ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: 'assets/**/*.{js,jsx,vue}',
lint-staged:gen-tasks commands: [Function: assets/**/*.{js,jsx,vue}],
lint-staged:gen-tasks fileList: [ '/path/to/app/assets/app/index.js' ] } +2ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '*.{json,yml,yaml,md}',
lint-staged:gen-tasks commands: [Function: *.{json,yml,yaml,md}],
lint-staged:gen-tasks fileList: [] } +0ms
Stashing changes... [started]
lint-staged:git Running git command [ 'status', '--porcelain' ] +16ms
Stashing changes... [skipped]
→ No partially staged files found...
Running linters... [started]
Running tasks for *.php [started]
Running tasks for assets/**/*.{js,jsx,vue} [started]
Running tasks for *.{json,yml,yaml,md} [started]
Running tasks for *.php [skipped]
→ No staged files match *.php
lint-staged:make-cmd-tasks Creating listr tasks for commands [Function: assets/**/*.{js,jsx,vue}] +0ms
Running tasks for *.{json,yml,yaml,md} [skipped]
→ No staged files match *.{json,yml,yaml,md}
eslint --fix [file] [started]
lint-staged:task cmd: eslint +0ms
lint-staged:task args: [ '--fix', 'assets/app/index.js' ] +0ms
lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
lint-staged:task cmd: git +4ms
lint-staged:task args: [ 'add', 'assets/app/index.js' ] +0ms
lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
eslint --fix [file] [completed]
Running tasks for assets/**/*.{js,jsx,vue} [completed]
Running linters... [completed]
lint-staged linters were executed successfully! +2s
[chore/deps-js 1deeb9de] test
1 file changed, 3 insertions(+), 1 deletion(-)
Environment
- OS: Debian 9.9 (Stretch)
- Node.js: v11.5.0
lint-staged
: 9.0.1
That’s weird because in debug logs we can see that git add assets/app/index.js
… 🤔
Thanks! 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
lint-staged not running on precommit - Stack Overflow
this script will create a .husky folder to your working directory and adds pre-commit file to it with script npm run lint-fix to...
Read more >Code linting tools (nf-core/bytesize) - YouTube
This week, Phil Ewels (@ewels) will present: Code linting toolsCode linting tools are now an essential part of the nf-core development ...
Read more >Release notes - OCRmyPDF - Read the Docs
Fixed an exception when attempting to run and Tesseract is not installed. Changed to SPDX license tracking and information files. v13.6.2¶. Added a...
Read more >Release Notes | Firebase - Google
The Realtime Database, Cloud Firestore, Hosting, Cloud Storage and Authentication emulators are now released to general availability (no longer in beta). The ...
Read more >Compose Runtime - Android Developers
Add the dependencies for the artifacts you need in the build.gradle file for ... A find method was added to CompositionData to allow...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you please re-test with
lint-staged@9.0.2
? It’s hopefully fixed.I think I found an issue with how tasks are created from a function linter return an array of commands. Currently, it generates a single task with multiple promises, but I refactored it to return an array of tasks instead, hopefully fixing this issue: https://github.com/okonet/lint-staged/pull/650