codemod icon indicating copy to clipboard operation
codemod copied to clipboard

lint: Add linter rule to ban unexplained `console.error` calls

Open plibither8 opened this issue 3 years ago • 0 comments

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)
}
Code 2022-07-08 at 17 00 18 000174@2x

plibither8 avatar Jul 08 '22 11:07 plibither8