Permalink
Browse files

Fix: Location info in `dot-notation` rule (fixes #5397)

  • Loading branch information...
gyandeeps committed Feb 25, 2016
1 parent 27b25bf commit 784d3bf3651a79f5e0c3df8d0a637230aa17ad8e
Showing with 33 additions and 3 deletions.
  1. +2 −2 lib/rules/dot-notation.js
  2. +31 −1 tests/lib/rules/dot-notation.js
@@ -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.");
}
}
};
@@ -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.