Skip to content

Commit

Permalink
Fix: Location info in dot-notation rule (fixes #5397)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyandeeps committed Feb 25, 2016
1 parent 27b25bf commit 784d3bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/rules/dot-notation.js
Expand Up @@ -29,15 +29,15 @@ module.exports = function(context) {
(allowKeywords || keywords.indexOf("" + node.property.value) === -1)
) {
if (!(allowPattern && allowPattern.test(node.property.value))) {
context.report(node, "[" + JSON.stringify(node.property.value) + "] is better written in dot notation.");
context.report(node.property, "[" + JSON.stringify(node.property.value) + "] is better written in dot notation.");
}
}
if (
!allowKeywords &&
!node.computed &&
keywords.indexOf("" + node.property.name) !== -1
) {
context.report(node, "." + node.property.name + " is a syntax error.");
context.report(node.property, "." + node.property.name + " is a syntax error.");
}
}
};
Expand Down
32 changes: 31 additions & 1 deletion tests/lib/rules/dot-notation.js
Expand Up @@ -52,6 +52,36 @@ ruleTester.run("dot-notation", rule, {
{ code: "a['b'];", errors: [{ message: "[\"b\"] is better written in dot notation." }] },
{ code: "a.b['c'];", errors: [{ message: "[\"c\"] is better written in dot notation." }] },
{ code: "a['_dangle'];", options: [{allowPattern: "^[a-z]+(_[a-z]+)+$"}], errors: [{ message: "[\"_dangle\"] is better written in dot notation." }] },
{ code: "a['SHOUT_CASE'];", options: [{allowPattern: "^[a-z]+(_[a-z]+)+$"}], errors: [{ message: "[\"SHOUT_CASE\"] is better written in dot notation." }] }
{ code: "a['SHOUT_CASE'];", options: [{allowPattern: "^[a-z]+(_[a-z]+)+$"}], errors: [{ message: "[\"SHOUT_CASE\"] is better written in dot notation." }] },
{
code:
"a\n" +
" ['SHOUT_CASE'];",
errors: [{
message: "[\"SHOUT_CASE\"] is better written in dot notation.",
line: 2,
column: 4
}]
},
{
code:
"getResource()\n" +
" .then(function(){})\n" +
" [\"catch\"](function(){})\n" +
" .then(function(){})\n" +
" [\"catch\"](function(){});",
errors: [
{
message: "[\"catch\"] is better written in dot notation.",
line: 3,
column: 6
},
{
message: "[\"catch\"] is better written in dot notation.",
line: 5,
column: 6
}
]
}
]
});

0 comments on commit 784d3bf

Please sign in to comment.