Skip to content

Commit

Permalink
only warn if reserved key is directly used on this or self objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ideadapt committed May 5, 2015
1 parent fb2c604 commit 9857bb6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/**
build/**
build/**
coverage/**
4 changes: 3 additions & 1 deletion lib/rules/reserved-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ module.exports = function(context) {

"MemberExpression": function(node){
var reservedPropertyKey = reservedWords.indexOf(node.property.name) > -1;
var memberOfThisOrSelf = node.object.type === "ThisExpression" || node.object.name === "self";

if (reservedPropertyKey && memberOfThisOrSelf){

if (reservedPropertyKey){
failures.push(context.report.bind(null, node,
"Property name '{{name}}' is a reserved identifier name. It might be used by another framework in this context.",
{ name: node.property.name }));
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/reserved-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ eslintTester.addRuleTest("lib/rules/reserved-keys", {
{
args: [1, {keywords: [":)"]}],
code: "this.id = 1; expect();"
},
{
code: "this.selectedCard.id = 1; expect();"
},
{
code: "other.id = 1; expect();"
}
],

Expand All @@ -40,6 +46,13 @@ eslintTester.addRuleTest("lib/rules/reserved-keys", {
message: "Property name 'id' is a reserved identifier name. It might be used by another framework in this context.",
type: "MemberExpression"
}]
},
{
code: "self.id = 1; expect();",
errors: [{
message: "Property name 'id' is a reserved identifier name. It might be used by another framework in this context.",
type: "MemberExpression"
}]
}
]
});

0 comments on commit 9857bb6

Please sign in to comment.