You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Best way to ensure no console.log on precommit? #4684
With Husky and Lint-staged, you can run commands with a precommit hook, for example Prettier, Flow, ESLint, etc. In doing so, if you have a Flow or ESLint error in your code, Husky will block the commit process. I do it inside projects bootstrapped with CRA and it works pretty well.
Now I'd like to block the commit process if there are remaining console.log in the code.
The easiest way would be to add https://eslint.org/docs/rules/no-console to the ESLint config. But we can't edit this config without ejecting. So I'm wondering how people achieve this.
Yes, it will not automatically fix it. So if you left out a console.log in your code, precommit with eslint --fix will fail if you have the no-console enabled and the developer needs to manually addreess it by removing it or add an eslint-ignore comment.
This should address the author's intent of blocking commits with console.log. The --fix option is meant to address the other most common issues.
Activity
bugzpodder commentedon Jun 26, 2018
Can you elaborate a little bit more on your question?
ggregoire commentedon Jun 26, 2018
With Husky and Lint-staged, you can run commands with a precommit hook, for example Prettier, Flow, ESLint, etc. In doing so, if you have a Flow or ESLint error in your code, Husky will block the commit process. I do it inside projects bootstrapped with CRA and it works pretty well.
Now I'd like to block the commit process if there are remaining
console.login the code.The easiest way would be to add https://eslint.org/docs/rules/no-console to the ESLint config. But we can't edit this config without ejecting. So I'm wondering how people achieve this.
bugzpodder commentedon Jun 27, 2018
Sure, its actually fairly simple:
Here is mine:
miraage commentedon Jun 27, 2018
@bugzpodder, I see no fix option for
no-consolerule.https://eslint.org/docs/rules/no-console
compare to
https://eslint.org/docs/rules/semi
bugzpodder commentedon Jun 27, 2018
Yes, it will not automatically fix it. So if you left out a console.log in your code, precommit with eslint --fix will fail if you have the no-console enabled and the developer needs to manually addreess it by removing it or add an eslint-ignore comment.
This should address the author's intent of blocking commits with console.log. The --fix option is meant to address the other most common issues.
ggregoire commentedon Jun 30, 2018
@bugzpodder It sounds good. Let me try it then I'll close the issue. :)