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

fix #575
  • Loading branch information
RebeccaStevens committed Apr 16, 2024
1 parent a089581 commit 61e4e86
Show file tree
Hide file tree
Showing 10 changed files with 489 additions and 71 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ The [below section](#rules) gives details on which rules are enabled by each rul

### Currying

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

### No Exceptions

Expand Down
44 changes: 43 additions & 1 deletion docs/rules/functional-parameters.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Enforce functional parameters (`functional/functional-parameters`)

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

💭 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 @@ -67,6 +71,23 @@ type Options = {
};
ignoreIdentifierPattern?: string[] | string;
ignorePrefixSelector?: string[] | string;
overrides?: Array<{
match:
| {
from: "file";
path?: string;
}
| {
from: "lib";
}
| {
from: "package";
package?: string;
}
| TypeDeclarationSpecifier[];
options: Omit<Options, "overrides">;
disable: boolean;
}>;
};
```

Expand Down Expand Up @@ -196,3 +217,24 @@ const sum = [1, 2, 3].reduce((carry, current) => current, 0);

This option takes a RegExp string or an array of RegExp strings.
It allows for the ability to ignore violations based on a function's name.

### `overrides`

_Using this option requires type infomation._

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: 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.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"escape-string-regexp": "^4.0.0",
"is-immutable-type": "^3.1.0",
"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
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

Loading

0 comments on commit 61e4e86

Please sign in to comment.