Won't this only work if the console command is the only thing until the end of the line? If you have anything else on the same line after it it will delete that as well. So if your line has multiple console commands in a ternary shortcut (? :, I get that this is not readability friendly, but since it's just debug anyway it's still common) or any other regular commands then you'll have a problem.
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.
Suhail is a software developer specializing in full-stack web and mobile application development. He is interested in contributing to open source and building Web3 applications.
Suhail is a software developer specializing in full-stack web and mobile application development. He is interested in contributing to open source and building Web3 applications.
Suhail is a software developer specializing in full-stack web and mobile application development. He is interested in contributing to open source and building Web3 applications.
Won't this only work if the
consolecommand is the only thing until the end of the line? If you have anything else on the same line after it it will delete that as well. So if your line has multipleconsolecommands in a ternary shortcut (? :, I get that this is not readability friendly, but since it's just debug anyway it's still common) or any other regular commands then you'll have a problem.That's cool!
But this has a few issues:
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
CallExpressionwith the callee being aMemberExpressionwith the object beingconsoleand the propertylog.Thanks @ayc0
For multiline you need to use
console\.log\(([^)]+)\);It still won't work for code snippet like those:
(As it contains a closing parenthesis)
console\.log\((.|\n)*?\);?It matches anything until it encounters ) again, with an optional whitespace and ;
this is helpful
it only selected the console.log which are commented not uncommented ones
It's funny how console.log.*$ can read like an wildcard *, but it's not. This regular expression matches also:
function console2log() {
return "A super important function in the script";
}
That's because the dot (.) in regex matches anything. The * means that it can occur 0 or more times.
PS: visual code treats the regex case insensitive
This matches also multi lines:
console\.log\((.|\n)*?\);?PS: if you have ) in your message this one won't work
console.log("check function() {}")
Nice tip!
Thank you Deyvison, Glad you liked it : )
great
Thanks Jahid :D
This is a beautiful illustration of the โnow you have two problemsโ principle of regex.
Doesn't work for multi-line console logs