Skip to content

Commit 768ef63

Browse files
FabioAntunesbradzacher
authored andcommitted
fix(parser): adds TTY check before logging the version mismatch warning (#1121)
1 parent 8dcbf4c commit 768ef63

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Diff for: packages/typescript-estree/src/parser.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ function applyParserOptionsToExtra(options: TSESTreeOptions): void {
224224
}
225225

226226
function warnAboutTSVersion(): void {
227-
if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) {
227+
if (
228+
!isRunningSupportedTypeScriptVersion &&
229+
!warnedAboutTSVersion &&
230+
process.stdout.isTTY
231+
) {
228232
const border = '=============';
229233
const versionWarning = [
230234
border,

Diff for: packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts

+14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,34 @@ import * as parser from '../../src/parser';
33

44
jest.mock('semver');
55

6+
const resetIsTTY = process.stdout.isTTY;
7+
68
describe('Warn on unsupported TypeScript version', () => {
79
afterEach(() => {
810
jest.resetModules();
911
jest.resetAllMocks();
12+
process.stdout.isTTY = resetIsTTY;
1013
});
1114

1215
it('should warn the user if they are using an unsupported TypeScript version', () => {
1316
(semver.satisfies as jest.Mock).mockReturnValue(false);
1417
jest.spyOn(console, 'log').mockImplementation();
18+
process.stdout.isTTY = true;
19+
1520
parser.parse('');
1621
expect(console.log).toHaveBeenCalledWith(
1722
expect.stringContaining(
1823
'WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree',
1924
),
2025
);
2126
});
27+
28+
it('should not warn the user when the user is running on a non TTY process', () => {
29+
(semver.satisfies as jest.Mock).mockReturnValue(false);
30+
jest.spyOn(console, 'log').mockImplementation();
31+
process.stdout.isTTY = false;
32+
33+
parser.parse('');
34+
expect(console.log).not.toHaveBeenCalled();
35+
});
2236
});

0 commit comments

Comments
 (0)