Skip to content

Commit

Permalink
feat(functional-parameters): allows applying overrides to the options…
Browse files Browse the repository at this point in the history
… based on the function's type

fix #575
  • Loading branch information
RebeccaStevens committed Aug 3, 2024
1 parent 8ba6695 commit c037578
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 91 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,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
64 changes: 63 additions & 1 deletion docs/rules/functional-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

# 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 -->
<!-- markdownlint-restore -->
<!-- markdownlint-restore -->

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 @@ -74,6 +78,36 @@ type Options = {
};
ignoreIdentifierPattern?: string[] | string;
ignorePrefixSelector?: string[] | string;
overrides?: Array<{
match: Array<
| {
from: "file";
path?: string;
name?: string | string[];
pattern?: RegExp | RegExp[];
ignoreName?: string | string[];
ignorePattern?: RegExp | RegExp[];
}
| {
from: "lib";
name?: string | string[];
pattern?: RegExp | RegExp[];
ignoreName?: string | string[];
ignorePattern?: RegExp | RegExp[];
}
| {
from: "package";
package?: string;
name?: string | string[];
pattern?: RegExp | RegExp[];
ignoreName?: string | string[];
ignorePattern?: RegExp | RegExp[];
}
>;
options: Omit<Options, "overrides">;
inherit?: boolean;
disable: boolean;
}>;
};
```

Expand Down Expand Up @@ -208,3 +242,31 @@ 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 the function's type.
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.

In the case of reference types, both the type and its generics will be recursively checked.
If any of them match, the specifier will be considered a match.

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

The options to use when a specifiers matches.

#### `overrides[n].inherit`

Inherit the root options? Default is `true`.

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

If true, when a specifier matches, this rule will not be applied to the matching node.
2 changes: 1 addition & 1 deletion knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "node_modules/knip/schema-jsonc.json",
"entry": ["src/index.ts!", "tests/**/*.test.ts"],
"project": ["src/**/*.ts!", "tests/**/*.{js,ts}"],
"ignore": ["tests/fixture/file.ts", "src/utils/schemas.ts"],
"ignore": ["tests/fixture/file.ts"],
"ignoreDependencies": [
// Unknown reason for issue.
"@vitest/coverage-v8",
Expand Down
Loading

0 comments on commit c037578

Please sign in to comment.