8000 fix(eslint-plugin): remove allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing option by developer-bandi · Pull Request #9923 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

fix(eslint-plugin): remove allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing option #9923

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 0 additions & 10 deletions packages/eslint-plugin/docs/rules/no-unnecessary-condition.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ for (; true; ) {}
do {} while (true);
```

### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`

If this is set to `false`, then the rule will error on every file whose `tsconfig.json` does _not_ have the `strictNullChecks` compiler option (or `strict`) set to `true`.

Without `strictNullChecks`, TypeScript essentially erases `undefined` and `null` from the types. This means when this rule inspects the types from a variable, **it will not be able to tell that the variable might be `null` or `undefined`**, which essentially makes this rule useless.

You should be using `strictNullChecks` to ensure complete type-safety in your codebase.

If for some reason you cannot turn on `strictNullChecks`, but still want to use this rule - you can use this option to allow it - but know that the behavior of this rule is _undefined_ with the compiler option turned off. We will not accept bug reports if you are using this option.

## When Not To Use It

If your project is not accurately typed, such as if it's in the process of being converted to TypeScript or is susceptible to [trade-offs in control flow analysis](https://github.com/Microsoft/TypeScript/issues/9998), it may be difficult to enable this rule for particularly non-type-safe areas of code.
Expand Down
10 changes: 0 additions & 10 deletions packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ foo ?? 'a string';

Also, if you would like to ignore all primitives types, you can set `ignorePrimitives: true`. It is equivalent to `ignorePrimitives: { string: true, number: true, bigint: true, boolean: true }`.

### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`

Unless this is set to `true`, the rule will error on every file whose `tsconfig.json` does _not_ have the `strictNullChecks` compiler option (or `strict`) set to `true`.

Without `strictNullChecks`, TypeScript essentially erases `undefined` and `null` from the types. This means when this rule inspects the types from a variable, **it will not be able to tell that the variable might be `null` or `undefined`**, which essentially makes this rule useless.

You should be using `strictNullChecks` to ensure complete type-safety in your codebase.

If for some reason you cannot turn on `strictNullChecks`, but still want to use this rule - you can use this option to allow it - but know that the behavior of this rule is _undefined_ with the compiler option turned off. We will not accept bug reports if you are using this option.

## When Not To Use It

If you are not using TypeScript 3.7 (or greater), then you will not be able to use this rule, as the operator is not supported.
Expand Down
10 changes: 0 additions & 10 deletions packages/eslint-plugin/docs/rules/strict-boolean-expressions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,6 @@ Allows `any` in a boolean context.
This is unsafe for obvious reasons.
Set this to `true` at your own risk.

### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`

If this is set to `false`, then the rule will error on every file whose `tsconfig.json` does _not_ have the `strictNullChecks` compiler option (or `strict`) set to `true`.

Without `strictNullChecks`, TypeScript essentially erases `undefined` and `null` from the types. This means when this rule inspects the types from a variable, **it will not be able to tell that the variable might be `null` or `undefined`**, which essentially makes this rule a lot less useful.

You should be using `strictNullChecks` to ensure complete type-safety in your codebase.

If for some reason you cannot turn on `strictNullChecks`, but still want to use this rule - you can use this option to allow it - but know that the behavior of this rule is _undefined_ with the compiler option turned off. We will not accept bug reports if you are using this option.

## Fixes and Suggestions

This rule provides following fixes and suggestions for particular types in boolean context:
Expand Down
22 changes: 2 additions & 20 deletions packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const isLiteral = (type: ts.Type): boolean =>
export type Options = [
{
allowConstantLoopConditions?: boolean;
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
},
];

Expand Down Expand Up @@ -105,11 +104,6 @@ export default createRule<Options, MessageId>({
'Whether to ignore constant loop conditions, such as `while (true)`.',
type: 'boolean',
},
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: {
description:
'Whether to not error when running with a tsconfig that has strictNullChecks turned.',
type: 'boolean',
},
},
additionalProperties: false,
},
Expand Down Expand Up @@ -139,18 +133,9 @@ export default createRule<Options, MessageId>({
defaultOptions: [
{
allowConstantLoopConditions: false,
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
},
],
create(
context,
[
{
allowConstantLoopConditions,
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing,
},
],
) {
create(context, [{ allowConstantLoopConditions }]) {
const services = getParserServices(context);
const checker = services.program.getTypeChecker();

Expand All @@ -160,10 +145,7 @@ export default createRule<Options, MessageId>({
'strictNullChecks',
);

if (
!isStrictNullChecks &&
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing !== true
) {
if (!isStrictNullChecks) {
context.report({
loc: {
start: { line: 0, column: 0 },
Expand Down
13 changes: 1 addition & 12 deletions
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {

export type Options = [
{
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
ignoreConditionalTests?: boolean;
ignoreMixedLogicalExpressions?: boolean;
ignorePrimitives?:
Expand Down Expand Up @@ -64,11 +63,6 @@ export default createRule<Options, MessageIds>({
{
type: 'object',
properties: {
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: {
description:
'Unless this is set to `true`, the rule will error on every file whose `tsconfig.json` does _not_ have the `strictNullChecks` compiler option (or `strict`) set to `true`.',
type: 'boolean',
},
ignoreConditionalTests: {
description:
'Whether to ignore cases that are located within a conditional test.',
Expand Down Expand Up @@ -110,7 +104,6 @@ export default createRule<Options, MessageIds>({
},
defaultOptions: [
{
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
ignoreConditionalTests: true,
ignoreTernaryTests: false,
ignoreMixedLogicalExpressions: false,
Expand All @@ -126,7 +119,6 @@ export default createRule<Options, MessageIds>({
context,
[
{
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing,
ignoreConditionalTests,
ignoreMixedLogicalExpressions,
ignorePrimitives,
Expand All @@ -143,10 +135,7 @@ export default createRule<Options, MessageIds>({
'strictNullChecks',
);

if (
!isStrictNullChecks &&
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing !== true
) {
if (!isStrictNullChecks) {
context.report({
loc: {
start: { line: 0, column: 0 },
Expand Down
10 changes: 1 addition & 9 deletions packages/eslint-plugin/src/rules/strict-boolean-expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export type Options = [
allowNullableNumber?: boolean;
allowNullableEnum?: boolean;
allowAny?: boolean;
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
},
];

Expand Down Expand Up @@ -104,9 +103,6 @@ export default createRule<Options, MessageId>({
description: 'Whether to allow `any` in a boolean context.',
type: 'boolean',
},
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: {
type: 'boolean',
},
},
additionalProperties: false,
},
Expand Down Expand Up @@ -182,7 +178,6 @@ export default createRule<Options, MessageId>({
allowNullableNumber: false,
allowNullableEnum: false,
allowAny: false,
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
},
],
create(context, [options]) {
Expand All @@ -195,10 +190,7 @@ export default createRule<Options, MessageId>({
'strictNullChecks',
);

if (
!isStrictNullChecks &&
options.allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing !== true
) {
if (!isStrictNullChecks) {
context.report({
loc: {
start: { line: 0, column: 0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,24 +721,6 @@ declare const unknownTyped: unknown;
if (!(booleanTyped || unknownTyped)) {
}
`,
{
code: `
declare const x: string[] | null;
// eslint-disable-next-line
if (x) {
}
`,
options: [
{
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: true,
},
],
languageOptions: {
parserOptions: {
tsconfigRootDir: path.join(rootPath, 'unstrict'),
},
},
},
`
interface Foo {
[key: string]: [string] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,6 @@ if (x) {
`,
options: [{ allowNullableEnum: true }],
},

{
code: `
declare const x: string[] | null;
// eslint-disable-next-line
if (x) {
}
`,
options: [
{
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: true,
},
],
languageOptions: {
parserOptions: {
tsconfigRootDir: path.join(rootPath, 'unstrict'),
},
},
},

`
function f(arg: 'a' | null) {
if (arg) console.log(arg);
Expand Down

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

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

4CFA

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

Loading
0