Skip to content

Commit

Permalink
Chore: add a test for semi
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Apr 18, 2017
1 parent 98e31c3 commit d25c542
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/testers/rule-tester.js
Expand Up @@ -469,9 +469,11 @@ class RuleTester {
)
);

const hasMessageOfThisRule = messages.some(m => m.ruleId === ruleName);

for (let i = 0, l = item.errors.length; i < l; i++) {
assert.ok(!("fatal" in messages[i]), `A fatal parsing error occurred: ${messages[i].message}`);
assert.equal(messages[i].ruleId, ruleName, "Error rule name should be the same as the name of the rule being tested");
assert(!messages[i].fatal, `A fatal parsing error occurred: ${messages[i].message}`);
assert(hasMessageOfThisRule, "Error rule name should be the same as the name of the rule being tested");

if (typeof item.errors[i] === "string" || item.errors[i] instanceof RegExp) {

Expand Down
21 changes: 20 additions & 1 deletion tests/lib/rules/semi.js
Expand Up @@ -169,6 +169,25 @@ ruleTester.run("semi", rule, {
{ code: "export default (foo) => foo.bar();", output: "export default (foo) => foo.bar()", options: ["never"], parserOptions: { sourceType: "module" }, errors: [{ message: "Extra semicolon.", type: "ExportDefaultDeclaration" }] },
{ code: "export default foo = 42;", output: "export default foo = 42", options: ["never"], parserOptions: { sourceType: "module" }, errors: [{ message: "Extra semicolon.", type: "ExportDefaultDeclaration" }] },
{ code: "export default foo += 42;", output: "export default foo += 42", options: ["never"], parserOptions: { sourceType: "module" }, errors: [{ message: "Extra semicolon.", type: "ExportDefaultDeclaration" }] },
{ code: "a;\n++b", output: "a\n++b", options: ["never"], errors: [{ message: "Extra semicolon." }] }
{ code: "a;\n++b", output: "a\n++b", options: ["never"], errors: [{ message: "Extra semicolon." }] },

// https://github.com/eslint/eslint/issues/7928
{
options: ["never"],
code: [
"/*eslint no-extra-semi: error */",
"foo();",
";[0,1,2].forEach(bar)"
].join("\n"),
errors: [
"Extra semicolon.",
"Unnecessary semicolon."
],
output: [
"/*eslint no-extra-semi: error */",
"foo()",
";[0,1,2].forEach(bar)"
].join("\n")
}
]
});

0 comments on commit d25c542

Please sign in to comment.