File is not getting added back to stage
See original GitHub issueDescription
Hey thanks for lint-staged
!!
It is not adding eslint --fix
ed files back to the commit after fixing them.
Steps to reproduce
Here’s a copy/paste from my terminal. You’ll see that after eslint fixes test.js
file, the commit happens but that file was not included in it and remains unstaged.
git status
On branch initial-dev-setup
Your branch is ahead of 'origin/initial-dev-setup' by 1 commit.
Changes to be committed:
new file: .eslintignore
new file: package-lock.json
modified: package.json
new file: test.js
> cat test.js
const a = [
1, 2, 3];
> g ca "chore: add eslint"
husky > pre-commit (node v14.4.0)
✔ Preparing...
✔ Running tasks...
✔ Applying modifications...
✔ Cleaning up...
[initial-dev-setup 1b9100d] chore: add eslint
4 files changed, 1834 insertions(+), 3 deletions(-)
create mode 100644 .eslintignore
create mode 100644 package-lock.json
create mode 100644 test.js
> g status
On branch initial-dev-setup
Your branch is ahead of 'origin/initial-dev-setup' by 2 commits.
Changes not staged for commit:
modified: test.js
no changes added to commit
> cat test.js
const a = [1, 2, 3];
### Debug Logs
<!--
Run `lint-staged` in debug mode using the command line flag `--debug`. You can
either modify your pre-commit script/command to include the flag or invoke
`lint-staged` manually(`./node_modules/.bin/lint-staged --debug`). Read more
about debug mode here -
https://github.com/okonet/lint-staged#command-line-flags.
NOTE: This requires `lint-staged` version >= `6.0.0`.
-->
<details>
<summary>expand to view</summary>
husky > pre-commit (node v14.4.0)
lint-staged:bin Running lint-staged@10.2.9
+0ms
lint-staged:bin Options parsed from command-line: {
allowEmpty: false,
concurrent: true,
configPath: undefined,
debug: true,
maxArgLength: 131072,
stash: true,
quiet: false,
relative: false,
shell: false,
verbose: false
} +1ms
lint-staged Loading config using cosmiconfig
+0ms
lint-staged Successfully loaded config from /Users/xxx/package.json
:
lint-staged { ‘.{json,css,md}': ‘npm run format --’, '.{js}’: ‘eslint --fix’ } +25ms
lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
‘.{json,css,md}': ‘npm run format --’,
'.{js}’: ‘eslint --fix’
}
lint-staged Unset GIT_LITERAL_PATHSPECS (was undefined
) +2ms
lint-staged:run Running all linter scripts +0ms
lint-staged:resolveGitRepo Resolving git repo from /Users/xxx
+0ms
lint-staged:resolveGitRepo Unset GIT_DIR (was undefined
) +0ms
lint-staged:git Running git command [ ‘rev-parse’, ‘–show-toplevel’ ] +0ms
lint-staged:resolveGitRepo Resolved git directory to be /Users/xxx
+18ms
lint-staged:resolveGitRepo Resolved git config directory to be /Users/xxx/.git
+0ms
lint-staged:git Running git command [ ‘log’, ‘-1’ ] +18ms
lint-staged:git Running git command [ ‘diff’, ‘–staged’, ‘–diff-filter=ACMR’, ‘–name-only’, ‘-z’ ] +19ms
lint-staged:run Loaded list of staged files in git:
lint-staged:run [ ‘.eslintignore’, ‘package-lock.json’, ‘package.json’, ‘test.js’ ] +48ms
lint-staged:chunkFiles Resolved an argument string length of 224 characters from 4 files +0ms
lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
lint-staged:gen-tasks Generating linter tasks +0ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks {
lint-staged:gen-tasks pattern: ‘.{json,css,md}',
lint-staged:gen-tasks commands: ‘npm run format --’,
lint-staged:gen-tasks fileList: [
lint-staged:gen-tasks ‘/Users/xxx/package-lock.json’,
lint-staged:gen-tasks ‘/Users/xxx/package.json’
lint-staged:gen-tasks ]
lint-staged:gen-tasks } +3ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '.{js}’, commands: ‘eslint --fix’, fileList: [] } +1ms
lint-staged:make-cmd-tasks Creating listr tasks for commands ‘npm run format --’ +0ms
lint-staged:task cmd: npm +0ms
lint-staged:task args: [ ‘run’, ‘format’, ‘–’ ] +0ms
lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
lint-staged:make-cmd-tasks Creating listr tasks for commands ‘eslint --fix’ +1ms
lint-staged:task cmd: eslint +1ms
lint-staged:task args: [ ‘–fix’ ] +0ms
lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
lint-staged:chunkFiles Resolved an argument string length of 116 characters from 2 files +6ms
lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
[STARTED] Preparing…
lint-staged:git Backing up original state… +0ms
lint-staged:git Getting partially staged files… +1ms
lint-staged:git Running git command [ ‘status’, ‘-z’ ] +20ms
lint-staged:git Found partially staged files: [] +16ms
lint-staged:git Backing up merge state… +1ms
lint-staged:file Reading file /Users/xxx/.git/MERGE_HEAD
+0ms
lint-staged:file Reading file /Users/xxx/.git/MERGE_MODE
+0ms
lint-staged:file Reading file /Users/xxx/.git/MERGE_MSG
+0ms
lint-staged:file File /Users/xxx/.git/MERGE_HEAD
doesn’t exist, ignoring… +1ms
lint-staged:file File /Users/xxx/.git/MERGE_MODE
doesn’t exist, ignoring… +0ms
lint-staged:file File /Users/xxx/.git/MERGE_MSG
doesn’t exist, ignoring… +0ms
lint-staged:git Done backing up merge state! +1ms
lint-staged:git Getting deleted files… +0ms
lint-staged:git Running git command [ ‘ls-files’, ‘–deleted’ ] +18ms
lint-staged:git Found deleted files: [] +13ms
lint-staged:git Running git command [ ‘stash’, ‘create’ ] +13ms
lint-staged:git Running git command [
‘stash’,
‘store’,
‘–quiet’,
‘–message’,
‘lint-staged automatic backup’,
‘2a976dc8166934d56292d6f73895b8ffea5da4b8’
] +34ms
lint-staged:git Done backing up original state! +58ms
[SUCCESS] Preparing…
[STARTED] Running tasks…
[STARTED] Running tasks for *.{json,css,md}
[STARTED] Running tasks for *.{js}
[STARTED] npm run format –
[SUCCESS] npm run format –
[SUCCESS] Running tasks for *.{json,css,md}
[SUCCESS] Running tasks…
[STARTED] Applying modifications…
lint-staged:git Adding task modifications to index… +848ms
lint-staged:git Running git command [
‘add’,
‘–’,
‘/Users/xxx/package-lock.json’,
‘/Users/xxx/package.json’
] +872ms
lint-staged:git Done adding task modifications to index! +14ms
lint-staged:git Running git command [ ‘diff’, ‘–name-only’, ‘–cached’ ] +14ms
[SUCCESS] Applying modifications…
[STARTED] Cleaning up…
lint-staged:git Dropping backup stash… +17ms
lint-staged:git Running git command [ ‘stash’, ‘list’ ] +17ms
lint-staged:git Running git command [ ‘stash’, ‘drop’, ‘–quiet’, ‘stash@{0}’ ] +35ms
lint-staged:git Done dropping backup stash! +75ms
[SUCCESS] Cleaning up…
lint-staged Tasks were executed successfully! +1s
[initial-dev-setup 5578a54] chore: add eslint
4 files changed, 1835 insertions(+), 4 deletions(-)
create mode 100644 .eslintignore
create mode 100644 package-lock.json
create mode 100644 test.js
</details>
### Environment
<!-- Tell us about your development environment -->
- **OS:** macOS Mojave
- **Node.js:** 14
- **`lint-staged`:** 10.2.9
- **husky**: 4.2.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top GitHub Comments
after fiddling a little, this was what did the trick, very strange:
changed:
"*.{js}": "eslint --fix"
to"*.js": "eslint --fix"
(removed the{}
).Cool, glad you got it fixed!