Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
developer-bandi wants to merge4 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromdeveloper-bandi:fix/allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing
Draft
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionspackages/eslint-plugin/src/rules/no-unnecessary-condition.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -69,7 +69,6 @@ const isLiteral = (type: ts.Type): boolean =>
export type Options = [
{
allowConstantLoopConditions?: boolean;
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
},
];

Expand DownExpand 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 DownExpand 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,6 @@ import {

export type Options = [
{
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
ignoreConditionalTests?: boolean;
ignoreMixedLogicalExpressions?: boolean;
ignorePrimitives?:
Expand DownExpand 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 DownExpand 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,6 @@ export type Options = [
allowNullableNumber?: boolean;
allowNullableEnum?: boolean;
allowAny?: boolean;
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
},
];

Expand DownExpand 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 DownExpand 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop

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

View file
Open in desktop

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

View file
Open in desktop

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

Loading

[8]ページ先頭

©2009-2025 Movatter.jp