Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
feat(audit-argument-checks): check default assignments (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
dferber90 authored Sep 4, 2020
1 parent 832380a commit 4816e4d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rules/audit-argument-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ module.exports = {
if (checkedParams.indexOf(param.name) === -1) {
context.report(param, `"${param.name}" is not checked`);
}
} else if (
// check params with default assignments
param.type === 'AssignmentPattern' &&
param.left.type === 'Identifier'
) {
if (checkedParams.indexOf(param.left.name) === -1) {
context.report(param.left, `"${param.left.name}" is not checked`);
}
}
});
}
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/rules/audit-argument-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ ruleTester.run('audit-argument-checks', rule, {
`,
parserOptions: { ecmaVersion: 6 },
},
{
code: `
Meteor.methods({
barWellChecked (bar = null) {
check(bar, Match.OneOf(Object, null));
}
})
`,
parserOptions: { ecmaVersion: 6 },
},
{
code: `
Meteor.methods({
barWellChecked (foo, bar = null) {
check(foo, String);
check(bar, Match.OneOf(Object, null));
}
})
`,
parserOptions: { ecmaVersion: 6 },
},
],

invalid: [
Expand Down Expand Up @@ -219,5 +240,21 @@ ruleTester.run('audit-argument-checks', rule, {
],
parserOptions: { ecmaVersion: 6 },
},
{
code: `
Meteor.methods({
barBadlyChecked (bar = null) {
check(foo, Match.OneOf(Object, null));
}
})
`,
errors: [
{
message: '"bar" is not checked',
type: 'Identifier',
},
],
parserOptions: { ecmaVersion: 6 },
},
],
});

0 comments on commit 4816e4d

Please sign in to comment.