-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[javascript] New rule AvoidConsoleStatements
Fixes pmd#5105
- Loading branch information
Showing
5 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...java/net/sourceforge/pmd/lang/ecmascript/rule/performance/AvoidConsoleStatementsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.lang.ecmascript.rule.performance; | ||
|
||
import net.sourceforge.pmd.test.PmdRuleTst; | ||
|
||
class AvoidConsoleStatementsTest extends PmdRuleTst { | ||
// no additional unit tests | ||
} |
46 changes: 46 additions & 0 deletions
46
...urces/net/sourceforge/pmd/lang/ecmascript/rule/performance/xml/AvoidConsoleStatements.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<test-data | ||
xmlns="http://pmd.sourceforge.net/rule-tests" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests https://pmd.github.io/schema/rule-tests_1_0_0.xsd"> | ||
|
||
<test-code> | ||
<description>Default console methods should be flagged</description> | ||
<expected-problems>6</expected-problems> | ||
<code><![CDATA[ | ||
console.log('foo'); // bad | ||
console.error('foo'); // bad | ||
console.info('foo'); // bad | ||
console.warn('foo'); // bad | ||
console.debug('foo'); // bad | ||
console.trace('foo'); // bad | ||
]]></code> | ||
</test-code> | ||
|
||
<test-code> | ||
<description>Default console methods via window.console should be flagged</description> | ||
<expected-problems>6</expected-problems> | ||
<code><![CDATA[ | ||
window.console.log('foo'); // bad | ||
window.console.error('foo'); // bad | ||
window.console.info('foo'); // bad | ||
window.console.warn('foo'); // bad | ||
window.console.debug('foo'); // bad | ||
window.console.trace('foo'); // bad | ||
]]></code> | ||
</test-code> | ||
|
||
<test-code> | ||
<description>Other similar methods shouldn't be flagged</description> | ||
<expected-problems>0</expected-problems> | ||
<code><![CDATA[ | ||
var MyFoo = { | ||
debug: function(a) { | ||
// ... | ||
} | ||
}; | ||
MyFoo.debug('bar'); // ok, it is not console.debug | ||
]]></code> | ||
</test-code> | ||
</test-data> |