Skip to content

Commit cd505bf

Browse files
committed
feat(valid-params): add exclude option; fixes #127
1 parent 701279c commit cd505bf

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

__tests__/valid-params.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ ruleTester.run('valid-params', rule, {
6161
'promiseReference.finally(callback)',
6262
'promiseReference.finally(() => {})',
6363

64+
{
65+
code: `
66+
somePromise.then(function() {
67+
return sth();
68+
}).catch(TypeError, function(e) {
69+
//
70+
}).catch(function(e) {
71+
});
72+
`,
73+
options: [
74+
{
75+
exclude: ['catch'],
76+
},
77+
],
78+
},
79+
6480
// integration test
6581
[
6682
'Promise.all([',

docs/rules/valid-params.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ somePromise().finally(() => {
6262
somePromise().finally(console.log)
6363
```
6464

65+
## Options
66+
67+
### `exclude`
68+
69+
Array of method names to exclude from checks. Defaults to an empty array.
70+
6571
## When Not To Use It
6672

6773
If you do not want to be notified when passing an invalid number of arguments to

rules/valid-params.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ module.exports = {
1111
'Enforces the proper number of arguments are passed to Promise functions.',
1212
url: getDocsUrl('valid-params'),
1313
},
14-
schema: [],
14+
schema: [
15+
{
16+
type: 'object',
17+
properties: {
18+
exclude: {
19+
type: 'array',
20+
items: {
21+
type: 'string',
22+
},
23+
},
24+
},
25+
additionalProperties: false,
26+
},
27+
],
1528
messages: {
1629
requireOneOptionalArgument:
1730
'Promise.{{ name }}() requires 0 or 1 arguments, but received {{ numArgs }}',
@@ -22,6 +35,7 @@ module.exports = {
2235
},
2336
},
2437
create(context) {
38+
const { exclude = [] } = context.options[0] || {}
2539
return {
2640
CallExpression(node) {
2741
if (!isPromise(node)) {
@@ -31,6 +45,10 @@ module.exports = {
3145
const name = node.callee.property.name
3246
const numArgs = node.arguments.length
3347

48+
if (exclude.includes(name)) {
49+
return
50+
}
51+
3452
// istanbul ignore next -- `isPromise` filters out others
3553
switch (name) {
3654
case 'resolve':

0 commit comments

Comments
 (0)