DEV Community

Discussion on: Remove all console.log() from your project in less than a minute

Collapse
ayc0 profile image
Ayc0

That's cool!
But this has a few issues:

  • it won't work with multi line console.log,
  • it won't work if you have something else in the same line after the console,
  • it won't work with if you do something like const fn = console.log (I mean it will remove the console, but the expression will become wrong).

I'd recommend instead using AST based tools like a webpack plugin, or a eslint custom rule, to detect a CallExpression with the callee being a MemberExpression with the object being console and the property log.

Collapse
suhailkakar profile image
Suhail Kakar Author

Thanks @ayc0
For multiline you need to use console\.log\(([^)]+)\);

Collapse
ayc0 profile image
Ayc0

It still won't work for code snippet like those:

console.log(
  'hello',
   world(1)
)
Enter fullscreen mode Exit fullscreen mode

(As it contains a closing parenthesis)