diff --git a/packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts b/packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts index 91e908015fbb..eddfd57bb994 100644 --- a/packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-optional-chain/prefer-optional-chain.test.ts @@ -1946,24 +1946,66 @@ describe('hand-crafted cases', () => { declare const thing1: string | null; thing1 && thing1.toString(); `, + output: null, options: [{ requireNullish: true }], - errors: [{ messageId: 'preferOptionalChain' }], + errors: [ + { + messageId: 'preferOptionalChain', + suggestions: [ + { + messageId: 'optionalChainSuggest', + output: ` + declare const thing1: string | null; + thing1?.toString(); + `, + }, + ], + }, + ], }, { code: ` declare const thing1: string | null; thing1 && thing1.toString() && true; `, + output: null, options: [{ requireNullish: true }], - errors: [{ messageId: 'preferOptionalChain' }], + errors: [ + { + messageId: 'preferOptionalChain', + suggestions: [ + { + messageId: 'optionalChainSuggest', + output: ` + declare const thing1: string | null; + thing1?.toString() && true; + `, + }, + ], + }, + ], }, { code: ` declare const foo: string | null; foo && foo.toString() && foo.toString(); `, + output: null, options: [{ requireNullish: true }], - errors: [{ messageId: 'preferOptionalChain' }], + errors: [ + { + messageId: 'preferOptionalChain', + suggestions: [ + { + messageId: 'optionalChainSuggest', + output: ` + declare const foo: string | null; + foo?.toString() && foo.toString(); + `, + }, + ], + }, + ], }, { code: ` @@ -1994,24 +2036,66 @@ describe('hand-crafted cases', () => { declare const foo: string | null; (foo || {}).toString(); `, + output: null, options: [{ requireNullish: true }], - errors: [{ messageId: 'preferOptionalChain' }], + errors: [ + { + messageId: 'preferOptionalChain', + suggestions: [ + { + messageId: 'optionalChainSuggest', + output: ` + declare const foo: string | null; + foo?.toString(); + `, + }, + ], + }, + ], }, { code: ` declare const foo: string; (foo || undefined || {}).toString(); `, + output: null, options: [{ requireNullish: true }], - errors: [{ messageId: 'preferOptionalChain' }], + errors: [ + { + messageId: 'preferOptionalChain', + suggestions: [ + { + messageId: 'optionalChainSuggest', + output: ` + declare const foo: string; + (foo || undefined)?.toString(); + `, + }, + ], + }, + ], }, { code: ` declare const foo: string | null; (foo || undefined || {}).toString(); `, + output: null, options: [{ requireNullish: true }], - errors: [{ messageId: 'preferOptionalChain' }], + errors: [ + { + messageId: 'preferOptionalChain', + suggestions: [ + { + messageId: 'optionalChainSuggest', + output: ` + declare const foo: string | null; + (foo || undefined)?.toString(); + `, + }, + ], + }, + ], }, // allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing diff --git a/packages/typescript-estree/src/create-program/createProjectService.ts b/packages/typescript-estree/src/create-program/createProjectService.ts index c355033191c4..b63273ad1265 100644 --- a/packages/typescript-estree/src/create-program/createProjectService.ts +++ b/packages/typescript-estree/src/create-program/createProjectService.ts @@ -48,10 +48,10 @@ export function createProjectService( logger: { close: doNothing, endGroup: doNothing, - getLogFileName: () => undefined, - hasLevel: () => false, + getLogFileName: (): undefined => undefined, + hasLevel: (): boolean => false, info: doNothing, - loggingEnabled: () => false, + loggingEnabled: (): boolean => false, msg: doNothing, perftrc: doNothing, startGroup: doNothing,