SeinopSys
SeinopSys

Reputation: 8937

Is there an inspection in PHPStorm that detects JavaScript debugging-only code?

When I've finished debugging an issue, occasionally, one or two console.log() calls and debugger; statements go unnoticed, and end up in source control as a result, which I'd like to avoid.

Is there an inspection that would detect this, and maybe even allow setting its severity (e.g. to treat it like an error), similar to other inspections?

Upvotes: 1

Views: 138

Answers (2)

SeinopSys
SeinopSys

Reputation: 8937

To detect console.log calls, it's possible to create a Structural Search Inspection, found under Editor > Inspections > General > Structural Search Inspection. After enabling it, you need to click the + icon in the bottom half of the right side, and pick "Add Search template…".

Add Search template for structural search

Then, use the following settings:

  • Use console.log($log$); as Search template
  • Tick Case-sensitive
  • Select JavaScript as the File type

Structural Search Inspection example with console.log

And finally, click OK, and give your new inspection a name that will be shown when it matches, e.g. "Console logging detected".

Structural search inspection in its natural habitat

Upvotes: 2

LazyOne
LazyOne

Reputation: 165088

  1. Settings/Preferences | Editor | Inspections
  2. JavaScript | JavaScript validity issues
  3. 'debugger' statement

This inspection reports JavaScript 'debugger' statements, used for interaction with Javascript debuggers. Such statements should probably not be found in production code.

Unfortunately I do not know about similar inspection for console statements.

P.S. If it would be a PHP code .. it could be done via "Php Inspections (EA Extended)" plugin where in similar by functionality inspection you can provide your own functions/classes.

Upvotes: 1

Related Questions