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.

lint-staged 10.0.1 fails with no reason on a newly created repo

See original GitHub issue

Description

On the initial repository commit, lint-staged fails for unknown reason (also with --debug no information or error is shown)

Steps to reproduce

  1. create a new project, using latest version 10.0.1 and try to commit
mkdir helloworld
cd helloworld
git init
echo '{"name":"helloworld","version":"1.0.0","private":true,"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.js":["prettier"]}}' > package.json
echo node_modules > .gitignore
npm i --save-dev husky lint-staged prettier
echo 'console.log(123)' > x.js
git add -A
git commit -m 'commit1'

This happens, “Skipped because of previous git error”.

Output:

husky > pre-commit (node v13.5.0)
  ✖ Preparing...
  ↓ Running tasks... [skipped]
    → Skipped because of previous git error.
  ↓ Applying modifications... [skipped]
    → Skipped because of previous git error.
  ↓ Cleaning up... [skipped]
    → Skipped because of previous git error.

  ✖ lint-staged failed due to a git error.
    Any lost modifications can be restored from a git stash:

    > git stash list
    stash@{0}: On master: automatic lint-staged backup
    > git stash pop stash@{0}

This can be fixed after the first --no-fix commit for example doing this:

git commit -m 'commit2' --no-fix
echo 'console.log(123456)' > x.js
git add -A
git commit -m 'commit3'

Output:

husky > pre-commit (node v13.5.0)
  ✔ Preparing...
  ✔ Running tasks...
  ✔ Applying modifications...
  ✔ Cleaning up...
[master c7813b4] commit3
 1 file changed, 1 insertion(+), 1 deletion(-)

in package.json:

Debug Logs

expand to view
⣿ lint-staged --debug
  lint-staged:bin Running `lint-staged@10.0.1` +0ms
  lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  debug: true,
  maxArgLength: 131072,
  quiet: false,
  relative: false,
  shell: false
} +2ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/Users/salvatorep/my/helloworld/package.json`:
  lint-staged { '*.js': [ 'prettier' ] } +16ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '*.js': [
    'prettier'
  ]
}
  lint-staged:run Running all linter scripts +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-superproject-working-tree' ] +11ms
  lint-staged:run Resolved git directory to be `/Users/salvatorep/my/helloworld` +26ms
  lint-staged:run Resolved git config directory to be `/Users/salvatorep/my/helloworld/.git` +0ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only' ] +15ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ '.gitignore', 'package-lock.json', 'package.json', 'x.js' ] +8ms
  lint-staged:chunkFiles Resolved an argument string length of 174 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: '*.js',
  lint-staged:gen-tasks   commands: [ 'prettier' ],
  lint-staged:gen-tasks   fileList: [ '/Users/salvatorep/my/helloworld/x.js' ]
  lint-staged:gen-tasks } +2ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier' ] +0ms
  lint-staged:task cmd: prettier /Users/salvatorep/my/helloworld/x.js +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
Preparing... [started]
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Backing up merge state... +0ms
  lint-staged:file Reading buffer from file `/Users/salvatorep/my/helloworld/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading buffer from file `/Users/salvatorep/my/helloworld/.git/MERGE_MODE` +1ms
  lint-staged:file Reading buffer from file `/Users/salvatorep/my/helloworld/.git/MERGE_MSG` +0ms
  lint-staged:file File `/Users/salvatorep/my/helloworld/.git/MERGE_HEAD` doesn't exist, ignoring... +2ms
  lint-staged:file File `/Users/salvatorep/my/helloworld/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/salvatorep/my/helloworld/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:git Done backing up merge state! +3ms
  lint-staged:git Running git command [
  'stash',
  'save',
  '--quiet',
  '--include-untracked',
  '--keep-index',
  'lint-staged automatic backup'
] +17ms
Preparing... [failed]
→
Running tasks... [started]
Running tasks... [skipped]
→ Skipped because of previous git error.
Applying modifications... [started]
Applying modifications... [skipped]
→ Skipped because of previous git error.
Cleaning up... [started]
Cleaning up... [skipped]
→ Skipped because of previous git error.

  ✖ lint-staged failed due to a git error.
    Any lost modifications can be restored from a git stash:

    > git stash list
    stash@{0}: On master: automatic lint-staged backup
    > git stash pop stash@{0}

Environment

MacOSX Node 13 and 12

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
iirojcommented, Jan 21, 2020

If you’re up for it, sure. Another possibility would be to have your script create an empty initial commit: git commit --no-verify --allow-empty -m "initial commit".

3reactions
okonetcommented, Jan 22, 2020

🎉 This issue has been resolved in version 10.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

lint-staged - npm
Linter commands work on a subset of all staged files, defined by a glob pattern. `lint-staged´ uses micromatch for matching files with the ......
Read more >
lint-staged: what the purpose of 'git add' command
My understand is lint-staged only validate the code in staged area after git add and before git commit . So can't understand why...
Read more >
lint-staged - NPM Package Overview - Socket.dev
Linting makes more sense when run before committing your code. By doing so you can ensure no errors go into the repository and...
Read more >
Lint Staged With Husky for Pre-commit Validations - YouTube
Learn how to use lint staged with husky to implement linting and formatting your code with Prettier and Eslint on pre-commit.
Read more >
SendBird SyncManager bundle issues - JavaScript
If I remove the import statement, the project loads without any error. Following is my package.json { "name": "chat", "version": "0.0.1", ...
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