Skip to content

Commit

Permalink
feat(functional-parameters): allow overriding options based on where …
Browse files Browse the repository at this point in the history
…the function type is declared
  • Loading branch information
RebeccaStevens committed Apr 14, 2024
1 parent 58bb185 commit 0a6bd90
Show file tree
Hide file tree
Showing 11 changed files with 484 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ The [below section](#rules) gives details on which rules are enabled by each rul

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

### No Exceptions

Expand Down
35 changes: 35 additions & 0 deletions docs/rules/functional-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

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

💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).

<!-- end auto-generated rule header -->

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

Note: type information is only required when using the [overrides](#overrides) option.

## Rule Details

In functions, `arguments` is a special variable that is implicitly available.
Expand Down Expand Up @@ -65,6 +69,17 @@ type Options = {
ignoreIIFE: boolean;
ignoreGettersAndSetters: boolean;
};
overrides?: Array<
{
match: TypeDeclarationSpecifier | TypeDeclarationSpecifier[];
options: {
allowRestParameter: boolean;
allowArgumentsKeyword: boolean;
enforceParameterCount: "see above";
};
disable: boolean;
}
>;
ignoreIdentifierPattern?: string[] | string;
ignorePrefixSelector?: string[] | string;
};
Expand Down Expand Up @@ -170,6 +185,26 @@ If true, this option allows for the use of [IIFEs](https://developer.mozilla.org

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`.

### `overrides`

Allows for applying overrides to the options based on where the function's type is defined.
This can be used to override the settings for types coming from 3rd party libraries.

Note: Using this option requires type infomation.
Note 2: Only the first matching override will be used.

#### `overrides[n].specifiers`

A specifier, or an array of specifiers to match the function type against.

#### `overrides[n].options`

The options to use when a specifiers matches.

#### `overrides[n].disable`

If true, when a specifier matches, this rule will not be applied to the matching node.

### `ignorePrefixSelector`

This allows for ignore functions where one of the given selectors matches the parent node in the AST of the function node.\
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
"escape-string-regexp": "^4.0.0",
"is-immutable-type": "^2.0.4",
"semver": "^7.6.0",
"ts-api-utils": "^1.3.0"
"ts-api-utils": "^1.3.0",
"ts-declaration-location": "1.0.0"
},
"devDependencies": {
"@babel/eslint-parser": "7.24.1",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a6bd90

Please sign in to comment.