Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with "bad" keyword in object and function definition #554

Merged
merged 2 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rules/avoid-scope-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
},
create: function(context) {
function check(node, name) {
if (bad.indexOf(name) >= 0 && scope.indexOf(node.parent.object.name) >= 0) {
if (bad.indexOf(name) >= 0 && node && node.parent && node.parent.object && scope.indexOf(node.parent.object.name) >= 0) {
context.report(node, `The ${name} method should be replaced by $${name}, or you should rename it in order to avoid confusions`, {});
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/avoid-scope-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const bad = ['new', 'watch', 'watchGroup', 'watchCollection',
'digest', 'destroy', 'eval', 'evalAsync', 'apply',
'applyAsync', 'on', 'emit', 'broadcast'];

const nonReservedBad = ['watch', 'watchGroup', 'watchCollection',
'digest', 'destroy', 'eval', 'evalAsync', 'apply',
'applyAsync', 'on', 'emit', 'broadcast'];

var invalid = [];
var valid = [];

Expand All @@ -43,6 +47,20 @@ valid.push({
code: '$ionicPlatform.on("resume", "blabla")'
});

/** Test the usage of the keyword inside an object */
bad.forEach(function(b) {
valid.push({
code: '$ctrl.test = {' + b + ':\'test\'}'
});
});

/** Test for using none reserved keywords as a function name */
nonReservedBad.forEach(function(b) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test for #507

valid.push({
code: 'function ' + b + '(){}'
});
});

eslintTester.run('avoid-scope-typos', rule, {
valid: valid.concat(commonFalsePositives),
invalid
Expand Down