From 4816e4d3f857d011ee6c9929a1ff93a3fef933ac Mon Sep 17 00:00:00 2001 From: Dominik Ferber Date: Fri, 4 Sep 2020 15:52:55 +0300 Subject: [PATCH] feat(audit-argument-checks): check default assignments (#776) --- lib/rules/audit-argument-checks.js | 8 +++++ tests/lib/rules/audit-argument-checks.js | 37 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/rules/audit-argument-checks.js b/lib/rules/audit-argument-checks.js index e3535cc..f357776 100644 --- a/lib/rules/audit-argument-checks.js +++ b/lib/rules/audit-argument-checks.js @@ -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`); + } } }); } diff --git a/tests/lib/rules/audit-argument-checks.js b/tests/lib/rules/audit-argument-checks.js index f1a4ad9..548ffa9 100644 --- a/tests/lib/rules/audit-argument-checks.js +++ b/tests/lib/rules/audit-argument-checks.js @@ -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: [ @@ -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 }, + }, ], });