Skip to content

Commit

Permalink
Fix: Avoid some obvious no-commented-tests false positives (fixes #61)
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure committed Jun 28, 2017
1 parent 17c0351 commit 28005fa
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-commented-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
const sourceCode = context.getSourceCode(),
ERROR_MESSAGE = "Unexpected \"{{callee}}\" in comment. Use QUnit.skip outside of a comment.",
newlineRegExp = /\r\n|\r|\n/g,
warningRegExp = /\b(QUnit\.test|QUnit\.asyncTest|QUnit\.skip|test|asyncTest)\s*\(/g;
warningRegExp = /\b(QUnit\.test|QUnit\.asyncTest|QUnit\.skip|test|asyncTest)\s*\((?=`[^`]*`|'[^']*'|"[^"]*"|[^,)\s]+\s*,\s*[^)]*\))/g;

function getNewlineIndexes(text) {
const indexes = [];
Expand Down
51 changes: 50 additions & 1 deletion tests/lib/rules/no-commented-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ const ruleTester = new RuleTester();
ruleTester.run("no-commented-tests", rule, {

valid: [
"QUnit.skip('Name', function () { ok(true); });"
"QUnit.skip('Name', function () { ok(true); });",

// Not actually a commented test
"// TODO: Add test (ASAP)",
"// TODO: Add test (foo bar)",
"// TODO: Add test (unterminated-paren",
"// TODO: Add test ('unterminated quote)",
"// TODO: refactor with a Component test (instead of an Acceptance test)"
],

invalid: [
Expand Down Expand Up @@ -282,6 +289,48 @@ ruleTester.run("no-commented-tests", rule, {
column: 2
}
]
},

// Not actually tests, but look too suspicious
{
code: "// Using backticks: test (`test`)",
errors: [
{
message: "Unexpected \"test\" in comment. Use QUnit.skip outside of a comment.",
line: 1,
column: 21
}
]
},
{
code: "// Using single quotes: test ('test')",
errors: [
{
message: "Unexpected \"test\" in comment. Use QUnit.skip outside of a comment.",
line: 1,
column: 25
}
]
},
{
code: "// Using double quotes: test (\"test\")",
errors: [
{
message: "Unexpected \"test\" in comment. Use QUnit.skip outside of a comment.",
line: 1,
column: 25
}
]
},
{
code: "// Possible multiple args?: test (foo, bar)",
errors: [
{
message: "Unexpected \"test\" in comment. Use QUnit.skip outside of a comment.",
line: 1,
column: 29
}
]
}
]

Expand Down

0 comments on commit 28005fa

Please sign in to comment.