question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File is not getting added back to stage

See original GitHub issue

Description

Hey thanks for lint-staged!! It is not adding eslint --fixed 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
lfilhocommented, Jun 11, 2020

after fiddling a little, this was what did the trick, very strange:

changed: "*.{js}": "eslint --fix" to "*.js": "eslint --fix" (removed the {}).

0reactions
iirojcommented, Jun 11, 2020

Cool, glad you got it fixed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding file to git's stage does nothing and cannot be committed
I have run into this same situation where I add or modify few files and they start showing as both staged and unstaged....
Read more >
Git changes not staged for commit Explanation - Career Karma
The “changes not staged for commit” message shows when you run the “git status” command and have a file that has been changed...
Read more >
How can I restore a deleted file in Git? - Tower Git Client
Short of deleting the entire repository directory (and not having a remote), few operations will result in a state where you're unable to...
Read more >
Cannot stage modified code and designer files in Team ...
In a Web Forms project, whenever I make a change to an .aspx file that results in an automated change to the designer...
Read more >
Querying Data in Staged Files - Snowflake Documentation
Snowflake supports using standard SQL to query data files located in an internal (i.e. Snowflake) stage or named external (Amazon S3, Google Cloud...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found