using --fail-on-changes does not create stash and discards all unstaged changes from partially staged file
envgap__lint-staged__lint-staged-1666
01 / FAILURE SIGNATURE
As reported upstream
- stage a single line from a file, to make staged version trigger linting error
Not a benchmark task.
- In a clean container the reported failure did not reproduce, or the known fix did not make the project run.
02 / ENVIRONMENT RECIPE
- Base commit
7edaee98e9a74a4e0a8646bb452a8139c8563619- Manifest
package.json- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
lint-staged/lint-staged #1666 · read the original issue
I am just starting with `lint-staged`, and instantly hit this issue :( Luckily, I was experimenting on a small change and was able to recover my losses from VSCode file history. This is not related to VSCode per se, as repro below is done purely from command line and produced the same outcome.
The most basic config:
```
"*.{js,jsx}": "eslint"
```
**git version 2.34.1**
## Repro steps:
- stage a single line from a file, to make staged version trigger linting error
- run `npx lint-staged --fail-on-changes`
- surprisingly, `lint-staged` fails, despite our config with`eslint` _without_ `--fix` flag
- ALL unstaged changes to the staged file are GONE. And stash is not created!
Running without ` --fail-on-changes` flag works fine, but I would not want unverified linter's modifications in my repo, so really want to make this work.
Full log is below.
_p.s. In addition, I also managed to wipe out ALL unstaged changes to **all files** when ran `npx lint-staged --fail-on-changes --hide-unstaged`. As those changes included freshly installed `lint-staged` config, it ended up with a very vanilla error message from git: `No valid configuration found`, which defo can be improved (example of confusion: https://github.com/desktop/desktop/issues/16870). I have also checked https://github.com/lint-staged/lint-staged/issues/1657 and https://github.com/lint-staged/lint-staged/issues/1402, and do not think my case falls into those._
## Repro log:
```shell
$ git status
Changes not staged for commit:
modified: bots/restart-trading.js
### STAGED SINGLE LINE from restart-trading.js to produce linting error on staged code
$ git status
Changes to be committed:
modified: bots/restart-trading.js
Changes not staged for commit:
modified: bots/restart-trading.js
$ npx lint-staged --fail-on-changes
✔ Backed up original state in git stash (b3adf7b5)
✔ Hiding unstaged changes to partially staged files...
⚠ Running tasks for staged files...
❯ package.json — 1 file
❯ *.{js,jsx} — 1 file
✖ eslint [FAILED]
↓ *.mjs — no files
↓ **/*.ts?(x) — no files
✖ Tasks modified files and --fail-on-changes was used!
↓ Skipped because of errors from tasks.
✔ Cleaning up temporary files...
✖ lint-staged failed because `--fail-on-changes` was used.
✖ eslint:
(node:2632900) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/home/ubuntu/jesse-bot/bots/restart-trading.js
260:35 error 'maxUptime' is not defined no-undef
393:24 error 'maxUptime' is not defined no-undef
✖ 2 problems (2 errors, 0 warnings)
$ git status
Changes to be committed:
modified: bots/restart-trading.js
### ALL UNSTAGED CHANGES ARE GONE!!!
$ git stash show
No stash entries found.
```04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]