Skip to content

Commit 0a6bd90

Browse files
feat(functional-parameters): allow overriding options based on where the function type is declared
1 parent 58bb185 commit 0a6bd90

File tree

11 files changed

+484
-66
lines changed

11 files changed

+484
-66
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ The [below section](#rules) gives details on which rules are enabled by each rul
108108

109109
| Name | Description | 💼 | ⚠️ | 🚫 | 🔧 | 💡 | 💭 ||
110110
| :----------------------------------------------------------- | :----------------------------- | :-------------------------- | :- | :- | :- | :- | :- | :- |
111-
| [functional-parameters](docs/rules/functional-parameters.md) | Enforce functional parameters. | ☑️ ✅ 🔒 ![badge-currying][] | | | | | | |
111+
| [functional-parameters](docs/rules/functional-parameters.md) | Enforce functional parameters. | ☑️ ✅ 🔒 ![badge-currying][] | | | | | 💭 | |
112112

113113
### No Exceptions
114114

docs/rules/functional-parameters.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
💼 This rule is enabled in the following configs: `currying`, ☑️ `lite`, ✅ `recommended`, 🔒 `strict`.
44

5+
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).
6+
57
<!-- end auto-generated rule header -->
68

79
Disallow use of rest parameters, the `arguments` keyword and enforces that functions take at least 1 parameter.
810

11+
Note: type information is only required when using the [overrides](#overrides) option.
12+
913
## Rule Details
1014

1115
In functions, `arguments` is a special variable that is implicitly available.
@@ -65,6 +69,17 @@ type Options = {
6569
ignoreIIFE: boolean;
6670
ignoreGettersAndSetters: boolean;
6771
};
72+
overrides?: Array<
73+
{
74+
match: TypeDeclarationSpecifier | TypeDeclarationSpecifier[];
75+
options: {
76+
allowRestParameter: boolean;
77+
allowArgumentsKeyword: boolean;
78+
enforceParameterCount: "see above";
79+
};
80+
disable: boolean;
81+
}
82+
>;
6883
ignoreIdentifierPattern?: string[] | string;
6984
ignorePrefixSelector?: string[] | string;
7085
};
@@ -170,6 +185,26 @@ If true, this option allows for the use of [IIFEs](https://developer.mozilla.org
170185

171186
Getters should always take zero parameters, and setter one. If for some reason you want to treat these function like any other function, then you can set this option to `false`.
172187

188+
### `overrides`
189+
190+
Allows for applying overrides to the options based on where the function's type is defined.
191+
This can be used to override the settings for types coming from 3rd party libraries.
192+
193+
Note: Using this option requires type infomation.
194+
Note 2: Only the first matching override will be used.
195+
196+
#### `overrides[n].specifiers`
197+
198+
A specifier, or an array of specifiers to match the function type against.
199+
200+
#### `overrides[n].options`
201+
202+
The options to use when a specifiers matches.
203+
204+
#### `overrides[n].disable`
205+
206+
If true, when a specifier matches, this rule will not be applied to the matching node.
207+
173208
### `ignorePrefixSelector`
174209

175210
This allows for ignore functions where one of the given selectors matches the parent node in the AST of the function node.\

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
"escape-string-regexp": "^4.0.0",
9696
"is-immutable-type": "^2.0.4",
9797
"semver": "^7.6.0",
98-
"ts-api-utils": "^1.3.0"
98+
"ts-api-utils": "^1.3.0",
99+
"ts-declaration-location": "1.0.0"
99100
},
100101
"devDependencies": {
101102
"@babel/eslint-parser": "7.24.1",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)