Thanks to visit codestin.com
Credit goes to github.com

Skip to content

docs: add 'When Not To Use It' or an intentional omission notice on all rules #7447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"serializers",
"Sourcegraph",
"stringification",
"stringifying",
"stringly",
"superset",
"thenables",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ export function foo(sn: string | number): void;

## When Not To Use It

If you don't care about the general structure of the code, then you will not need this rule.
It can sometimes be useful to place overload signatures alongside other meaningful parts of a type.
For example, if each of a function's overloads corresponds to a different property, you might wish to put each overloads next to its corresponding property.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

## Related To

- [`unified-signatures`](./unified-signatures.md)
8 changes: 8 additions & 0 deletions packages/eslint-plugin/docs/rules/array-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@ This matrix lists all possible option combinations and their expected results fo
| `generic` | `array` | `Array<number>` | `Array<Foo & Bar>` | `readonly number[]` | `readonly (Foo & Bar)[]` |
| `generic` | `array-simple` | `Array<number>` | `Array<Foo & Bar>` | `readonly number[]` | `ReadonlyArray<Foo & Bar>` |
| `generic` | `generic` | `Array<number>` | `Array<Foo & Bar>` | `ReadonlyArray<number>` | `ReadonlyArray<Foo & Bar>` |

## When Not To Use It

This rule is purely a stylistic rule for maintaining consistency in your project.
You can turn it off if you don't want to keep a consistent style for array types.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
4 changes: 3 additions & 1 deletion packages/eslint-plugin/docs/rules/await-thenable.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ await createValue();
## When Not To Use It

If you want to allow code to `await` non-Promise values.
This is generally not preferred, but can sometimes be useful for visual consistency.
For example, if your framework is in transition from one style of asynchronous code to another, it may be useful to include `await`s unnecessarily.
This is generally not preferred but can sometimes be useful for visual consistency.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
3 changes: 2 additions & 1 deletion packages/eslint-plugin/docs/rules/ban-ts-comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ if (false) {

## When Not To Use It

If you want to use all of the TypeScript directives.
If your project or its dependencies were not architected with strong type safety in mind, it can be difficult to always adhere to proper TypeScript semantics.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

## Further Reading

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/ban-tslint-comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ someCode(); // This is a comment that just happens to mention tslint

## When Not To Use It

If you are still using TSLint.
If you are still using TSLint alongside ESLint.
5 changes: 5 additions & 0 deletions packages/eslint-plugin/docs/rules/ban-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,8 @@ Example configuration:
]
}
```

## When Not To Use It

If your project is a rare one that intentionally deals with the class equivalents of primitives, it might not be worthwhile to enable the default `ban-types` options.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,4 @@ class Mx {

## When Not To Use It

When you have no strong preference, or do not wish to enforce a particular style
for how literal values are exposed by your classes.
When you have no strong preference, or do not wish to enforce a particular style for how literal values are exposed by your classes.
5 changes: 5 additions & 0 deletions packages/eslint-plugin/docs/rules/class-methods-use-this.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@ class X implements Y {
property = () => {};
}
```

## When Not To Use It

If your project dynamically changes `this` scopes around in a way TypeScript has difficulties modeling, this rule may not be viable to use.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ const set: Set<string> = new Set<string>();
## When Not To Use It

You can turn this rule off if you don't want to enforce one kind of generic constructor style over the other.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ type Foo = {
[key: string]: unknown;
};
```

## When Not To Use It

This rule is purely a stylistic rule for maintaining consistency in your project.
You can turn it off if you don't want to keep a consistent style for indexed object types.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ const foo = <Foo props={{ ... } as Bar}/>;
## When Not To Use It

If you do not want to enforce consistent type assertions.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ type T = { x: number };

## When Not To Use It

If you specifically want to use an interface or type literal for stylistic reasons, you can disable this rule.
If you specifically want to use an interface or type literal for stylistic reasons, you can avoid this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.

There are also subtle differences between `Record` and `interface` that can be difficult to catch statically.
For example, if your project is a dependency of another project that relies on a specific type definition style, this rule may be counterproductive.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
9 changes: 7 additions & 2 deletions packages/eslint-plugin/docs/rules/consistent-type-exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,10 @@ export { Button, type ButtonProps } from 'some-library';

## When Not To Use It

- If you specifically want to use both export kinds for stylistic reasons, you can disable this rule.
- If you use `--isolatedModules` the compiler would error if a type is not re-exported using `export type`. If you also don't wish to enforce one style over the other, you can disable this rule.
If you use `--isolatedModules` the compiler would error if a type is not re-exported using `export type`.
This rule may be less useful in those cases.

If you specifically want to use both export kinds for stylistic reasons, or don't wish to enforce one style over the other, you can avoid this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
5 changes: 4 additions & 1 deletion packages/eslint-plugin/docs/rules/consistent-type-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ If you are using [type-aware linting](https://typescript-eslint.io/linting/typed

## When Not To Use It

- If you specifically want to use both import kinds for stylistic reasons, you can disable this rule.
If you specifically want to use both import kinds for stylistic reasons, or don't wish to enforce one style over the other, you can avoid this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.

## Related To

Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-plugin/docs/rules/dot-notation.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ x['hello'] = 123;
```

If the TypeScript compiler option `noPropertyAccessFromIndexSignature` is set to `true`, then the above code is always allowed, even if `allowIndexSignaturePropertyAccess` is `false`.

## When Not To Use It

If you specifically want to use both member access kinds for stylistic reasons, or don't wish to enforce one style over the other, you can avoid this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ var bar = (function () {

## When Not To Use It

If you don't wish to prevent calling code from using function return values in unexpected ways, then
you will not need this rule.
If you don't find the added cost of explicitly writing function return types to be worth the visual clarity, or your project is not large enough for it to be a factor in type checking performance, then you will not need this rule.

## Further Reading

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ class Animal {

## When Not To Use It

If you think defaulting to public is a good default, then you should consider using the `no-public` setting. If you want to mix implicit and explicit public members then disable this rule.
If you think defaulting to public is a good default, then you should consider using the `no-public` setting.
If you want to mix implicit and explicit public members then you can disable this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.

## Further Reading

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ export const foo: FooType = bar => {};

## When Not To Use It

If you wish to make sure all functions have explicit return types, as opposed to only the module boundaries, you can use [explicit-function-return-type](./explicit-function-return-type.md)
If your project is not used by downstream consumers that are sensitive to API types, you can disable this rule.

## Further Reading

- TypeScript [Functions](https://www.typescriptlang.org/docs/handbook/functions.html#function-types)

## Related To

- [explicit-function-return-type](./explicit-function-return-type.md)
5 changes: 4 additions & 1 deletion packages/eslint-plugin/docs/rules/member-delimiter-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,7 @@ type FooBar = { name: string; greet(): string }

## When Not To Use It

If you don't care about enforcing a consistent member delimiter in interfaces and type literals, then you will not need this rule.
If you specifically want to use both member delimiter kinds for stylistic reasons, or don't wish to enforce one style over the other, you can avoid this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
3 changes: 3 additions & 0 deletions packages/eslint-plugin/docs/rules/method-signature-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ type T2 = {
## When Not To Use It

If you don't want to enforce a particular style for object/interface function types, and/or if you don't use `strictFunctionTypes`, then you don't need this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.
9 changes: 8 additions & 1 deletion packages/eslint-plugin/docs/rules/naming-convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,4 +711,11 @@ You can use the `destructured` modifier to match these names, and explicitly set

## When Not To Use It

If you do not want to enforce naming conventions for anything.
This rule can be very strict.
If you don't have strong needs for enforcing naming conventions, we recommend using it only to flag very egregious violations of your naming standards.
Consider documenting your naming conventions and enforcing them in code review if you have processes like that.

If you do not want to enforce naming conventions for anything, you can disable this rule.

However, keep in mind that inconsistent style can harm readability in a project.
We recommend that if you care about naming conventions, pick a single option for this rule that works best for your project.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-base-to-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let text = `${value}`;

## When Not To Use It

If you don't mind `"[object Object]"` in your strings, then you will not need this rule.
If you don't mind a risk of `"[object Object]"` or incorrect type coercions in your values, then you will not need this rule.

## Related To

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ console.log(void alert('Hello, world!'));

The return type of a function can be inspected by going to its definition or hovering over it in an IDE.
If you don't care about being explicit about the void type in actual code then don't use this rule.
Also, if you prefer concise coding style then also don't use it.
Also, if you strongly prefer a concise coding style more strongly than any fear of `void`-related bugs then you can avoid this rule.
8 changes: 8 additions & 0 deletions packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ enum E {
B = 'B',
}
```

## When Not To Use It

It can sometimes be useful to include duplicate enum members for very specific use cases.
For example, when renaming an enum member, it can sometimes be useful to keep the old name until a scheduled major breaking change.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

In general, if your project intentionally duplicates enum member values, you can avoid this rule.
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ When set to true, duplicate checks on intersection type constituents are ignored
### `ignoreUnions`

When set to true, duplicate checks on union type constituents are ignored.

## When Not To Use It

It can sometimes be useful for the sake of documentation to include aliases for the same type.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

> In some of those cases, [branded types](https://basarat.gitbook.io/typescript/main-1/nominaltyping#using-interfaces) might be a type-safe way to represent the underlying data types.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-dynamic-delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ delete container['-Infinity'];
## When Not To Use It

When you know your keys are safe to delete, this rule can be unnecessary.
Some environments such as older browsers might not support `Map` and `Set`.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

Do not consider this rule as performance advice before profiling your code's bottlenecks.
Even repeated minor performance slowdowns likely do not significantly affect your application's general perceived speed.
9 changes: 9 additions & 0 deletions packages/eslint-plugin/docs/rules/no-empty-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ class Foo extends Base {
protected override greet(): void {}
}
```

## When Not To Use It

If you are working with external APIs that require functions even if they do nothing, then you may want to avoid this rule.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

Test code often violates this rule as well.
If your testing setup doesn't support "mock" or "spy" functions such as [`jest.fn()`](https://jestjs.io/docs/mock-functions), [`sinon.spy()`](https://sinonjs.org/releases/latest/spies), or [`vi.fn()`](https://vitest.dev/guide/mocking.html), you may wish to disable this rule in test files.
Again, if those cases aren't extremely common, you might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule in test files.
4 changes: 4 additions & 0 deletions packages/eslint-plugin/docs/rules/no-explicit-any.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ Most commonly:
- If an external package doesn't yet have typings and you want to use `any` pending adding a `.d.ts` for it
- You're working with particularly complex or nuanced code that can't yet be represented in the TypeScript type system

You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

## Related To

- [`no-unsafe-argument`](./no-unsafe-argument.md)
Expand All @@ -148,5 +150,7 @@ Most commonly:

## Further Reading

- TypeScript [`any` type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)
- TypeScript's [`unknown` type](https://www.typescriptlang.org/docs/handbook/2/functions.html#unknown)
- TypeScript [`any` type documentation](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)
- TypeScript [`unknown` type release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type)
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ function foo(bar?: { n: number }) {
return bar?.n;
}
```

<!-- Intentionally Omitted: When Not To Use It -->
3 changes: 2 additions & 1 deletion packages/eslint-plugin/docs/rules/no-extraneous-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,5 @@ class Constants {

## When Not To Use It

You can disable this rule if you are unable -or unwilling- to switch off using classes as namespaces.
If your project was set up before modern class and namespace practices, and you don't have the time to switch over, you might not be practically able to use this rule.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
4 changes: 3 additions & 1 deletion packages/eslint-plugin/docs/rules/no-floating-promises.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ await(async function () {

## When Not To Use It

If you do not use Promise-like values in your codebase, or want to allow them to remain unhandled.
This rule can be difficult to enable on large existing projects that set up many floating Promises.
Alternately, if you're not worried about crashes from floating or misused Promises -such as if you have global unhandled Promise handlers registered- then in some cases it may be safe to not use this rule.
You might consider using `void`s and/or [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.

## Related To

Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/docs/rules/no-for-in-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ for (const [i, value] of array.entries()) {

## When Not To Use It

If you want to iterate through a loop using the indices in an array as strings, you can turn off this rule.
If your project is a rare one that intentionally loops over string indices of arrays, you can turn off this rule.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
3 changes: 2 additions & 1 deletion packages/eslint-plugin/docs/rules/no-implied-eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ setTimeout(Foo.fn, 100);

## When Not To Use It

If you want to allow `new Function()` or `setTimeout()`, `setInterval()`, `setImmediate()` and `execScript()` with string arguments, then you can safely disable this rule.
If your project is a rare one that needs to allow `new Function()` or `setTimeout()`, `setInterval()`, `setImmediate()` and `execScript()` with string arguments, then you can disable this rule.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ import T, { type U } from 'mod';

## When Not To Use It

- If you want to leave behind side effect imports, then you shouldn't use this rule.
- If you're not using TypeScript 5.0's `verbatimModuleSyntax` option, then you don't need this rule.
If you're not using TypeScript 5.0's `verbatimModuleSyntax` option and your project is built with a bundler that manages import side effects for you, this rule may not be as useful for you.

## Related To

Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/no-inferrable-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class Foo {

## When Not To Use It

If you do not want to enforce inferred types.
If you strongly prefer to have explicit types regardless of whether they can be inferred, this rule may not be for you.

## Further Reading

TypeScript [Inference](https://www.typescriptlang.org/docs/handbook/type-inference.html)
- [TpeScript Inference](https://www.typescriptlang.org/docs/handbook/type-inference.html)
Loading