48

I'm new to eslint and am using it to enforce coding style. However, when I write a TODO item into my code I get an eslint warning, alright that's fine. But, now when I try to git commit, it comes back with:

**** ESLint errors found :     
line 145, col 9, Warning - Unexpected 'todo' comment. (no-warning-comments)

How can I prevent eslint from blocking me from committing? I want it to still warn me about TODOs etc, but I would like to be able to commit my code as well.

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
Tevon Strand-Brown
  • 1,283
  • 3
  • 16
  • 28

5 Answers5

100

You have a pre-commit hook.

git commit --no-verify

allows to avoid it once. Or you can remove it completely from .git/hooks.

phd
  • 82,685
  • 13
  • 120
  • 165
13

Use --no-verify pre-commit hooks when commit.

git commit --no-verify -m "Commit message"
Miraj Khandaker
  • 772
  • 10
  • 11
5

In my case the culprit were package.json entries automatically created by a project creating CLI (nuxt.js). I removed from my package.json these entries:

"lint-staged": { ... },
"husky": { ... }

and it solved the problem.

Eggon
  • 2,032
  • 2
  • 19
  • 38
2

Usually warnings don't block commits only errors. If it's set to error you can switch it to warning, but looks like you may already have it set to warning.

"rules": {
 ...
 
 "no-warning-comments": 0,
 ...
}

The other option is to disable the rule for the given line

// eslint-disable-next-line no-warning-comments
// TODO disable eslint warning for this todo ;)

This would prevent the warning from showing up at all though

Otherwise you would need to look at what is being set up to prevent the commit, most likely something in your pre-commit hook located at root/.git/hooks/pre-commit and tell it to allow warnings and block errors

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
0

Solution

I navigated to my .git/hooks directory and found a pre-commit bash script. I changed the return value from 1 to 0 in the case where eslint failed and that solved the problem.

A 0 value represents a pass and will allow the commit to continue, a non-zero represents a fail state and will cancel the commit.

Tevon Strand-Brown
  • 1,283
  • 3
  • 16
  • 28