diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts index 3eb36636a839..581cae6fb4e5 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts @@ -6,6 +6,7 @@ import rule from '../../src/rules/no-unnecessary-type-assertion'; const rootDir = path.resolve(__dirname, '../fixtures/'); const ruleTester = new RuleTester({ parserOptions: { + EXPERIMENTAL_useProjectService: false, sourceType: 'module', tsconfigRootDir: rootDir, project: './tsconfig.json', @@ -13,6 +14,11 @@ const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); +const optionsWithOnUncheckedIndexedAccess = { + tsconfigRootDir: rootDir, + project: './tsconfig.noUncheckedIndexedAccess.json', +}; + ruleTester.run('no-unnecessary-type-assertion', rule, { valid: [ ` @@ -242,6 +248,17 @@ const item = arr[0] as object; declare const arr: (object | undefined)[]; const item = arr[0]; `, + { + code: ` +function foo(item: string) {} +function bar(items: string[]) { + for (let i = 0; i < items.length; i++) { + foo(items[i]!); + } +} + `, + parserOptions: optionsWithOnUncheckedIndexedAccess, + }, ], invalid: [ @@ -815,5 +832,31 @@ const foo = (3 + 5); }, ], }, + // onUncheckedIndexedAccess = false + { + code: ` +function foo(item: string) {} +function bar(items: string[]) { + for (let i = 0; i < items.length; i++) { + foo(items[i]!); + } +} + `, + output: ` +function foo(item: string) {} +function bar(items: string[]) { + for (let i = 0; i < items.length; i++) { + foo(items[i]); + } +} + `, + errors: [ + { + messageId: 'unnecessaryAssertion', + line: 5, + column: 9, + }, + ], + }, ], }); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy