How to prevent eslint from blocking git commit?

Viewed 48475

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.

5 Answers

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.

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

git commit --no-verify -m "Commit message"

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

Related