Skip to content

Commit 9656e13

Browse files
authored
feat(typescript-estree): skip isTTY version check if user passes loggerFn on unsupported TypeScript version warning (#7739)
1 parent be2777c commit 9656e13

3 files changed

Lines changed: 47 additions & 21 deletions

File tree

‎packages/typescript-estree/src/parseSettings/createParseSettings.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function createParseSettings(
3333
typeof options.tsconfigRootDir === 'string'
3434
? options.tsconfigRootDir
3535
: process.cwd();
36+
const passedLoggerFn = typeof options.loggerFn === 'function';
3637
const parseSettings: MutableParseSettings = {
3738
allowInvalidAST: options.allowInvalidAST === true,
3839
code,
@@ -135,7 +136,7 @@ export function createParseSettings(
135136
});
136137
}
137138

138-
warnAboutTSVersion(parseSettings);
139+
warnAboutTSVersion(parseSettings, passedLoggerFn);
139140

140141
return parseSettings;
141142
}

‎packages/typescript-estree/src/parseSettings/warnAboutTSVersion.ts‎

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,31 @@ const isRunningSupportedTypeScriptVersion = semver.satisfies(
2323

2424
let warnedAboutTSVersion = false;
2525

26-
export function warnAboutTSVersion(parseSettings: ParseSettings): void {
27-
if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) {
28-
const isTTY =
29-
typeof process === 'undefined' ? false : process.stdout?.isTTY;
30-
if (isTTY) {
31-
const border = '=============';
32-
const versionWarning = [
33-
border,
34-
'WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.',
35-
'You may find that it works just fine, or you may not.',
36-
`SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
37-
`YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
38-
'Please only submit bug reports when using the officially supported version.',
39-
border,
40-
];
41-
parseSettings.log(versionWarning.join('\n\n'));
42-
}
43-
warnedAboutTSVersion = true;
26+
export function warnAboutTSVersion(
27+
parseSettings: ParseSettings,
28+
passedLoggerFn: boolean,
29+
): void {
30+
if (isRunningSupportedTypeScriptVersion || warnedAboutTSVersion) {
31+
return;
4432
}
33+
34+
if (
35+
passedLoggerFn ||
36+
(typeof process === 'undefined' ? false : process.stdout?.isTTY)
37+
) {
38+
const border = '=============';
39+
const versionWarning = [
40+
border,
41+
'WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.',
42+
'You may find that it works just fine, or you may not.',
43+
`SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
44+
`YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
45+
'Please only submit bug reports when using the officially supported version.',
46+
border,
47+
].join('\n\n');
48+
49+
parseSettings.log(versionWarning);
50+
}
51+
52+
warnedAboutTSVersion = true;
4553
}

‎packages/typescript-estree/tests/lib/warn-on-unsupported-ts.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import semver from 'semver';
22

3-
import * as parser from '../../src/parser';
3+
import type * as Parser from '../../src/parser';
44

55
jest.mock('semver');
66

77
const resetIsTTY = process.stdout.isTTY;
88

99
describe('Warn on unsupported TypeScript version', () => {
10+
let parser: typeof Parser;
11+
12+
beforeEach(async () => {
13+
// @ts-expect-error -- We don't support ESM imports of local code yet.
14+
parser = await import('../../src/parser');
15+
});
1016
afterEach(() => {
1117
jest.resetModules();
1218
jest.resetAllMocks();
@@ -26,7 +32,18 @@ describe('Warn on unsupported TypeScript version', () => {
2632
);
2733
});
2834

29-
it('should not warn the user when the user is running on a non TTY process', () => {
35+
it('should warn the user if they are running on a non TTY process and a custom loggerFn was passed', () => {
36+
(semver.satisfies as jest.Mock).mockReturnValue(false);
37+
const loggerFn = jest.fn();
38+
process.stdout.isTTY = false;
39+
40+
parser.parse('', {
41+
loggerFn,
42+
});
43+
expect(loggerFn).toHaveBeenCalled();
44+
});
45+
46+
it('should not warn the user if they are running on a non TTY process and a custom loggerFn was not passed', () => {
3047
(semver.satisfies as jest.Mock).mockReturnValue(false);
3148
jest.spyOn(console, 'log').mockImplementation();
3249
process.stdout.isTTY = false;

0 commit comments

Comments
 (0)