From da6ba3281d23c1360955a74ddee93bb38a1fea0d Mon Sep 17 00:00:00 2001 From: Vojtech Prikryl Date: Wed, 1 Apr 2020 17:40:19 +0200 Subject: [PATCH] feat: Improved `selectors-format` rule to forbid optional arguments resolves #65 --- README.md | 6 ++++++ src/rules/selectorsFormatRule.ts | 7 +++++++ test/rules/selectors-format/test.2.tsx.lint | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index eaea595..2376152 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,12 @@ select( ~~~~~~~~~~~~~~ [Default arguments are forbidden.] ); +select( + [Store], + (a?: number) => false, + ~~~~~~~~~~ [Optional arguments are forbidden.] +); + select( [Store], (abc, xyz) => false, diff --git a/src/rules/selectorsFormatRule.ts b/src/rules/selectorsFormatRule.ts index 0d74a44..1eff4ca 100644 --- a/src/rules/selectorsFormatRule.ts +++ b/src/rules/selectorsFormatRule.ts @@ -118,6 +118,13 @@ class SelectorsFormatRule extends Lint.RuleWalker { ); } + if (paramNode.questionToken) { + this.addFailureAtNode( + paramNode, + this.getFormattedError('Optional arguments are forbidden.'), + ); + } + if (!paramNode.type) { this.addFailureAtNode( paramNode, diff --git a/test/rules/selectors-format/test.2.tsx.lint b/test/rules/selectors-format/test.2.tsx.lint index 00c68d6..af1a17e 100644 --- a/test/rules/selectors-format/test.2.tsx.lint +++ b/test/rules/selectors-format/test.2.tsx.lint @@ -45,6 +45,12 @@ select( ~~~~~~~~~~~~~~ [Default arguments are forbidden.] ); +select( + [Store], + (a?: number) => false, + ~~~~~~~~~~ [Optional arguments are forbidden.] +); + select( [Store], (abc, xyz) => false,