From 34610c6a07b3edc3acde8ae158a0f7472ced0f53 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 7 Dec 2024 18:58:28 +0200 Subject: [PATCH 1/7] use consistent naming for asserting types and casting values --- .../docs/rules/non-nullable-type-assertion-style.mdx | 2 +- .../eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx | 2 +- packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts | 4 ++-- .../eslint-plugin/src/rules/prefer-reduce-type-parameter.ts | 2 +- .../prefer-reduce-type-parameter.shot | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx index cbb1dc0fa11e..9f386c554372 100644 --- a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx +++ b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx @@ -15,7 +15,7 @@ There are two common ways to assert to TypeScript that a value is its type witho - `as`: Traditional type assertion with a coincidentally equivalent type `!` non-null assertions are generally preferred for requiring less code and being harder to fall out of sync as types change. -This rule reports when an `as` cast is doing the same job as a `!` would, and suggests fixing the code to be an `!`. +This rule reports when an `as` assertion is doing the same job as a `!` would, and suggests fixing the code to be an `!`. ## Examples diff --git a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx index 2c8e1ed65d11..602023ec955b 100644 --- a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx +++ b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx @@ -176,7 +176,7 @@ Also, if you would like to ignore all primitives types, you can set `ignorePrimi {/* insert option description */} -Whether to ignore expressions that coerce a value into a boolean: `Boolean(...)`. +Whether to ignore expressions that cast a value into a boolean: `Boolean(...)`. Incorrect code for `ignoreBooleanCoercion: false`, and correct code for `ignoreBooleanCoercion: true`: diff --git a/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts index 06c3dd44615a..df3c964c8137 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts @@ -22,9 +22,9 @@ export default createRule({ }, messages: { unsafeOfAnyTypeAssertion: - 'Unsafe cast from {{type}} detected: consider using type guards or a safer cast.', + 'Unsafe assertion from {{type}} detected: consider using type guards or a safer assertion.', unsafeToAnyTypeAssertion: - 'Unsafe cast to {{type}} detected: consider using a more specific type to ensure safety.', + 'Unsafe assertion to {{type}} detected: consider using a more specific type to ensure safety.', unsafeTypeAssertion: "Unsafe type assertion: type '{{type}}' is more narrow than the original type.", }, diff --git a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts index e3ff336f2b70..fddb8a49418b 100644 --- a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts +++ b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts @@ -28,7 +28,7 @@ export default createRule({ fixable: 'code', messages: { preferTypeParameter: - 'Unnecessary cast: Array#reduce accepts a type parameter for the default value.', + 'Unnecessary assertion: Array#reduce accepts a type parameter for the default value.', }, schema: [], }, diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/prefer-reduce-type-parameter.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/prefer-reduce-type-parameter.shot index 5babf0ea8978..adf8cc67ea4c 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/prefer-reduce-type-parameter.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/prefer-reduce-type-parameter.shot @@ -4,7 +4,7 @@ exports[`Validating rule docs prefer-reduce-type-parameter.mdx code examples ESL "Incorrect [1, 2, 3].reduce((arr, num) => arr.concat(num * 2), [] as number[]); - ~~~~~~~~~~~~~~ Unnecessary cast: Array#reduce accepts a type parameter for the default value. + ~~~~~~~~~~~~~~ Unnecessary assertion: Array#reduce accepts a type parameter for the default value. ['a', 'b'].reduce( (accum, name) => ({ @@ -12,7 +12,7 @@ exports[`Validating rule docs prefer-reduce-type-parameter.mdx code examples ESL [name]: true, }), {} as Record, - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Unnecessary cast: Array#reduce accepts a type parameter for the default value. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Unnecessary assertion: Array#reduce accepts a type parameter for the default value. ); " `; From cf0d4946e31fc506ec82c5bef7686a06e766e61c Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 7 Dec 2024 20:56:21 +0200 Subject: [PATCH 2/7] address remaining wrong usages of 'cast' --- .../docs/rules/explicit-function-return-type.mdx | 4 ++-- .../docs/rules/explicit-module-boundary-types.mdx | 4 ++-- .../docs/rules/non-nullable-type-assertion-style.mdx | 2 +- .../eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx | 2 +- packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts | 2 +- .../src/rules/non-nullable-type-assertion-style.ts | 2 +- .../eslint-plugin/src/rules/prefer-reduce-type-parameter.ts | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx b/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx index 1bc1a56e50e6..6d2934516290 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx @@ -161,7 +161,7 @@ let funcExpr: FuncType = function () { }; let asTyped = (() => '') as () => string; -let castTyped = <() => string>(() => ''); +let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -172,7 +172,7 @@ let objectProp: ObjectType = { let objectPropAs = { foo: () => 1, } as ObjectType; -let objectPropCast = { +let objectPropAssertion = { foo: () => 1, }; diff --git a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx index fadbfa296975..5403b0f72c0f 100644 --- a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx +++ b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx @@ -242,7 +242,7 @@ export let funcExpr: FuncType = function () { }; export let asTyped = (() => '') as () => string; -export let castTyped = <() => string>(() => ''); +export let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -253,7 +253,7 @@ export let objectProp: ObjectType = { export let objectPropAs = { foo: () => 1, } as ObjectType; -export let objectPropCast = { +export let objectPropAssertion = { foo: () => 1, }; diff --git a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx index 9f386c554372..90ec607e5dc9 100644 --- a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx +++ b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx @@ -1,5 +1,5 @@ --- -description: 'Enforce non-null assertions over explicit type casts.' +description: 'Enforce non-null assertions over explicit type assertions.' --- import Tabs from '@theme/Tabs'; diff --git a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx index eff53ee96c84..ba6b62eaa2a4 100644 --- a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx +++ b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx @@ -1,5 +1,5 @@ --- -description: 'Enforce using type parameter when calling `Array#reduce` instead of casting.' +description: 'Enforce using type parameter when calling `Array#reduce` instead of using a type assertion.' --- import Tabs from '@theme/Tabs'; diff --git a/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts index df3c964c8137..649dfd12ae27 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-type-assertion.ts @@ -62,7 +62,7 @@ export default createRule({ return; } - // handle cases when casting unknown ==> any. + // handle cases when asserting unknown ==> any. if (isTypeAnyType(assertedType) && isTypeUnknownType(expressionType)) { context.report({ node, diff --git a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts index 547f5e64147b..a6bf5985e26a 100644 --- a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts +++ b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts @@ -16,7 +16,7 @@ export default createRule({ meta: { type: 'suggestion', docs: { - description: 'Enforce non-null assertions over explicit type casts', + description: 'Enforce non-null assertions over explicit type assertions', recommended: 'stylistic', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts index fddb8a49418b..3c148bb8d777 100644 --- a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts +++ b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts @@ -21,7 +21,7 @@ export default createRule({ type: 'problem', docs: { description: - 'Enforce using type parameter when calling `Array#reduce` instead of casting', + 'Enforce using type parameter when calling `Array#reduce` instead of using a type assertion', recommended: 'strict', requiresTypeChecking: true, }, From d4fbfecba1126e9dff9c1dab139a2aac6e6dcc05 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 7 Dec 2024 20:56:50 +0200 Subject: [PATCH 3/7] don't change 'coerce' into 'cast' --- packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx index 602023ec955b..2c8e1ed65d11 100644 --- a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx +++ b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx @@ -176,7 +176,7 @@ Also, if you would like to ignore all primitives types, you can set `ignorePrimi {/* insert option description */} -Whether to ignore expressions that cast a value into a boolean: `Boolean(...)`. +Whether to ignore expressions that coerce a value into a boolean: `Boolean(...)`. Incorrect code for `ignoreBooleanCoercion: false`, and correct code for `ignoreBooleanCoercion: true`: From ef89183f5458d28c10a9ebe7acc01ccd2ab92ba9 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 7 Dec 2024 20:59:29 +0200 Subject: [PATCH 4/7] leftovers and snapshots --- .../eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx | 2 +- .../explicit-function-return-type.shot | 4 ++-- .../explicit-module-boundary-types.shot | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx index ba6b62eaa2a4..999e0e39f502 100644 --- a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx +++ b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.mdx @@ -19,7 +19,7 @@ A common solution to this problem is to use an `as` assertion on the initial val While this will work, it's not the most optimal solution as type assertions have subtle effects on the underlying types that can allow bugs to slip in. A better solution is to pass the type in as a generic type argument to `Array#reduce` explicitly. -This means that TypeScript doesn't have to try to infer the type, and avoids the common pitfalls that come with casting. +This means that TypeScript doesn't have to try to infer the type, and avoids the common pitfalls that come with assertions. This rule looks for calls to `Array#reduce`, and reports if an initial value is being passed & asserted. It will suggest instead pass the asserted type to `Array#reduce` as a generic type argument. diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot index 1bce8870ade7..4ff470795f7c 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot @@ -113,7 +113,7 @@ let funcExpr: FuncType = function () { }; let asTyped = (() => '') as () => string; -let castTyped = <() => string>(() => ''); +let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -124,7 +124,7 @@ let objectProp: ObjectType = { let objectPropAs = { foo: () => 1, } as ObjectType; -let objectPropCast = { +let objectPropAssertion = { foo: () => 1, }; diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot index 707536a970d6..87b3d4dd9bb5 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot @@ -177,7 +177,7 @@ export let funcExpr: FuncType = function () { }; export let asTyped = (() => '') as () => string; -export let castTyped = <() => string>(() => ''); +export let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -188,7 +188,7 @@ export let objectProp: ObjectType = { export let objectPropAs = { foo: () => 1, } as ObjectType; -export let objectPropCast = { +export let objectPropAssertion = { foo: () => 1, }; From 5e067a088006ccfd7f53adddc3c0393c699f1460 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 7 Dec 2024 21:29:24 +0200 Subject: [PATCH 5/7] rename documentation variable to match one another --- .../eslint-plugin/docs/rules/explicit-function-return-type.mdx | 2 +- .../eslint-plugin/docs/rules/explicit-module-boundary-types.mdx | 2 +- .../explicit-function-return-type.shot | 2 +- .../explicit-module-boundary-types.shot | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx b/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx index 6d2934516290..56449575dc87 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx @@ -172,7 +172,7 @@ let objectProp: ObjectType = { let objectPropAs = { foo: () => 1, } as ObjectType; -let objectPropAssertion = { +let objectPropAssert = { foo: () => 1, }; diff --git a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx index 5403b0f72c0f..438517b735a5 100644 --- a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx +++ b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx @@ -253,7 +253,7 @@ export let objectProp: ObjectType = { export let objectPropAs = { foo: () => 1, } as ObjectType; -export let objectPropAssertion = { +export let objectPropAssert = { foo: () => 1, }; diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot index 4ff470795f7c..75d798480390 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot @@ -124,7 +124,7 @@ let objectProp: ObjectType = { let objectPropAs = { foo: () => 1, } as ObjectType; -let objectPropAssertion = { +let objectPropAssert = { foo: () => 1, }; diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot index 87b3d4dd9bb5..4dd4290752db 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot @@ -188,7 +188,7 @@ export let objectProp: ObjectType = { export let objectPropAs = { foo: () => 1, } as ObjectType; -export let objectPropAssertion = { +export let objectPropAssert = { foo: () => 1, }; From 06056b8642c99ef38884870538ca9aa91a24ed4b Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 14 Dec 2024 17:06:11 +0200 Subject: [PATCH 6/7] replace 'cast' terminology in sbe to use 'convert' instead --- .../docs/rules/strict-boolean-expressions.mdx | 12 ++++++------ .../src/rules/strict-boolean-expressions.ts | 4 ++-- .../strict-boolean-expressions.shot | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.mdx b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.mdx index a48b3a37247d..94e647872a4f 100644 --- a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.mdx +++ b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.mdx @@ -84,7 +84,7 @@ function foo(bool?: boolean) { } } -// `any` types should be cast to boolean explicitly +// `any` types should be converted to boolean explicitly const foo = (arg: any) => (Boolean(arg) ? 1 : 0); ``` @@ -176,14 +176,14 @@ This rule provides following fixes and suggestions for particular types in boole - `string` - (when `allowString` is `false`) - Provides following suggestions: - Change condition to check string's length (`str` → `str.length > 0`) - Change condition to check for empty string (`str` → `str !== ""`) - - Explicitly cast value to a boolean (`str` → `Boolean(str)`) + - Explicitly convert value to a boolean (`str` → `Boolean(str)`) - `number` - (when `allowNumber` is `false`): - For `array.length` - Provides **autofix**: - Change condition to check for 0 (`array.length` → `array.length > 0`) - For other number values - Provides following suggestions: - Change condition to check for 0 (`num` → `num !== 0`) - Change condition to check for NaN (`num` → `!Number.isNaN(num)`) - - Explicitly cast value to a boolean (`num` → `Boolean(num)`) + - Explicitly convert value to a boolean (`num` → `Boolean(num)`) - `object | null | undefined` - (when `allowNullableObject` is `false`) - Provides **autofix**: - Change condition to check for null/undefined (`maybeObj` → `maybeObj != null`) - `boolean | null | undefined` - Provides following suggestions: @@ -192,13 +192,13 @@ This rule provides following fixes and suggestions for particular types in boole - `string | null | undefined` - Provides following suggestions: - Change condition to check for null/undefined (`maybeStr` → `maybeStr != null`) - Explicitly treat nullish value the same as an empty string (`maybeStr` → `maybeStr ?? ""`) - - Explicitly cast value to a boolean (`maybeStr` → `Boolean(maybeStr)`) + - Explicitly convert value to a boolean (`maybeStr` → `Boolean(maybeStr)`) - `number | null | undefined` - Provides following suggestions: - Change condition to check for null/undefined (`maybeNum` → `maybeNum != null`) - Explicitly treat nullish value the same as 0 (`maybeNum` → `maybeNum ?? 0`) - - Explicitly cast value to a boolean (`maybeNum` → `Boolean(maybeNum)`) + - Explicitly convert value to a boolean (`maybeNum` → `Boolean(maybeNum)`) - `any` and `unknown` - Provides following suggestions: - - Explicitly cast value to a boolean (`value` → `Boolean(value)`) + - Explicitly convert value to a boolean (`value` → `Boolean(value)`) ## When Not To Use It diff --git a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts index eb127d434d78..395cf8524f8d 100644 --- a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts +++ b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts @@ -68,7 +68,7 @@ export default createRule({ messages: { conditionErrorAny: 'Unexpected any value in conditional. ' + - 'An explicit comparison or type cast is required.', + 'An explicit comparison or type conversion is required.', conditionErrorNullableBoolean: 'Unexpected nullable boolean value in conditional. ' + 'Please handle the nullish case explicitly.', @@ -100,7 +100,7 @@ export default createRule({ 'Unexpected string value in conditional. ' + 'An explicit empty string check is required.', conditionFixCastBoolean: - 'Explicitly cast value to a boolean (`Boolean(value)`)', + 'Explicitly convert value to a boolean (`Boolean(value)`)', conditionFixCompareEmptyString: 'Change condition to check for empty string (`value !== ""`)', diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/strict-boolean-expressions.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/strict-boolean-expressions.shot index a62ee559e04e..ba1353e67dcc 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/strict-boolean-expressions.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/strict-boolean-expressions.shot @@ -27,7 +27,7 @@ function foo(bool?: boolean) { // \`any\`, unconstrained generics and unions of more than one primitive type are disallowed const foo = (arg: T) => (arg ? 1 : 0); - ~~~ Unexpected any value in conditional. An explicit comparison or type cast is required. + ~~~ Unexpected any value in conditional. An explicit comparison or type conversion is required. // always-truthy and always-falsy types are disallowed let obj = {}; @@ -64,7 +64,7 @@ function foo(bool?: boolean) { } } -// \`any\` types should be cast to boolean explicitly +// \`any\` types should be converted to boolean explicitly const foo = (arg: any) => (Boolean(arg) ? 1 : 0); " `; From f003891f1beaa6e509d75e59d6a67ba09346f36d Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 14 Dec 2024 20:31:35 +0200 Subject: [PATCH 7/7] remove unnecessary angle-bracket examples --- .../docs/rules/explicit-function-return-type.mdx | 4 ---- .../docs/rules/explicit-module-boundary-types.mdx | 4 ---- .../explicit-function-return-type.shot | 4 ---- .../explicit-module-boundary-types.shot | 4 ---- 4 files changed, 16 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx b/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx index 56449575dc87..c4493059f108 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.mdx @@ -161,7 +161,6 @@ let funcExpr: FuncType = function () { }; let asTyped = (() => '') as () => string; -let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -172,9 +171,6 @@ let objectProp: ObjectType = { let objectPropAs = { foo: () => 1, } as ObjectType; -let objectPropAssert = { - foo: () => 1, -}; declare function functionWithArg(arg: () => number); functionWithArg(() => 1); diff --git a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx index 438517b735a5..339150327d99 100644 --- a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx +++ b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx @@ -242,7 +242,6 @@ export let funcExpr: FuncType = function () { }; export let asTyped = (() => '') as () => string; -export let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -253,9 +252,6 @@ export let objectProp: ObjectType = { export let objectPropAs = { foo: () => 1, } as ObjectType; -export let objectPropAssert = { - foo: () => 1, -}; type FooType = (bar: string) => void; export const foo: FooType = bar => {}; diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot index 75d798480390..2822695807e4 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-function-return-type.shot @@ -113,7 +113,6 @@ let funcExpr: FuncType = function () { }; let asTyped = (() => '') as () => string; -let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -124,9 +123,6 @@ let objectProp: ObjectType = { let objectPropAs = { foo: () => 1, } as ObjectType; -let objectPropAssert = { - foo: () => 1, -}; declare function functionWithArg(arg: () => number); functionWithArg(() => 1); diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot index 4dd4290752db..8fcda4fd876a 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/explicit-module-boundary-types.shot @@ -177,7 +177,6 @@ export let funcExpr: FuncType = function () { }; export let asTyped = (() => '') as () => string; -export let assertTyped = <() => string>(() => ''); interface ObjectType { foo(): number; @@ -188,9 +187,6 @@ export let objectProp: ObjectType = { export let objectPropAs = { foo: () => 1, } as ObjectType; -export let objectPropAssert = { - foo: () => 1, -}; type FooType = (bar: string) => void; export const foo: FooType = bar => {};