Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: Improve report location for no-empty-function (refs #12334) (#…
  • Loading branch information
mdjermanovic committed Mar 31, 2020
1 parent b228f95 commit 6631ef1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-empty-function.js
Expand Up @@ -151,7 +151,7 @@ module.exports = {
) {
context.report({
node,
loc: node.body.loc.start,
loc: node.body.loc,
messageId: "unexpected",
data: { name }
});
Expand Down
63 changes: 62 additions & 1 deletion tests/lib/rules/no-empty-function.js
Expand Up @@ -312,5 +312,66 @@ ruleTester.run("no-empty-function", rule, [
}

],
invalid: []
invalid: [

// location tests
{
code: "function foo() {}",
errors: [{
messageId: "unexpected",
data: { name: "function 'foo'" },
line: 1,
column: 16,
endLine: 1,
endColumn: 18
}]
},
{
code: "var foo = function () {\n}",
errors: [{
messageId: "unexpected",
data: { name: "function" },
line: 1,
column: 23,
endLine: 2,
endColumn: 2
}]
},
{
code: "var foo = () => { \n\n }",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { name: "arrow function" },
line: 1,
column: 17,
endLine: 3,
endColumn: 4
}]
},
{
code: "var obj = {\n\tfoo() {\n\t}\n}",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { name: "method 'foo'" },
line: 2,
column: 8,
endLine: 3,
endColumn: 3
}]
},
{
code: "class A { foo() { } }",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpected",
data: { name: "method 'foo'" },
line: 1,
column: 17,
endLine: 1,
endColumn: 20
}]
}
]
}));

0 comments on commit 6631ef1

Please sign in to comment.