codemod
codemod copied to clipboard
lint: Add linter rule to ban unexplained `console.error` calls
This PR is partially completes https://github.com/sourcegraph/sourcegraph/issues/26582. Next step would be to create a PR in the sourcegraph repo to console.error errors captured by Sentry.
This rule bans logging errors directly to the console using console.error() calls, unless supported with a comment explaining why it's required. Otherwise, it's recommended to pass the error through Sentry.captureException().
Bad code
try {
// do something
} catch (error) {
console.error(error)
}
Okay code
try {
// do something
} catch (error) {
// We need to log this to the browser console because XYZ
console.error(error)
}
(Bonus) Awesome code
try {
// do something
} catch (error) {
Sentry.captureException(error)
}