diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index c887193365f7..7ee2cdacbc3e 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -224,7 +224,11 @@ function applyParserOptionsToExtra(options: TSESTreeOptions): void { } function warnAboutTSVersion(): void { - if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) { + if ( + !isRunningSupportedTypeScriptVersion && + !warnedAboutTSVersion && + process.stdout.isTTY + ) { const border = '============='; const versionWarning = [ border, diff --git a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts index 9e6a26a39a66..581d28a7e961 100644 --- a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts +++ b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts @@ -3,15 +3,20 @@ import * as parser from '../../src/parser'; jest.mock('semver'); +const resetIsTTY = process.stdout.isTTY; + describe('Warn on unsupported TypeScript version', () => { afterEach(() => { jest.resetModules(); jest.resetAllMocks(); + process.stdout.isTTY = resetIsTTY; }); it('should warn the user if they are using an unsupported TypeScript version', () => { (semver.satisfies as jest.Mock).mockReturnValue(false); jest.spyOn(console, 'log').mockImplementation(); + process.stdout.isTTY = true; + parser.parse(''); expect(console.log).toHaveBeenCalledWith( expect.stringContaining( @@ -19,4 +24,13 @@ describe('Warn on unsupported TypeScript version', () => { ), ); }); + + it('should not warn the user when the user is running on a non TTY process', () => { + (semver.satisfies as jest.Mock).mockReturnValue(false); + jest.spyOn(console, 'log').mockImplementation(); + process.stdout.isTTY = false; + + parser.parse(''); + expect(console.log).not.toHaveBeenCalled(); + }); });