Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript-estree): skip isTTY version check if user passes loggerFn on unsupported TypeScript version warning #7739

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -33,6 +33,7 @@ export function createParseSettings(
typeof options.tsconfigRootDir === 'string'
? options.tsconfigRootDir
: process.cwd();
const passedLoggerFn = typeof options.loggerFn === 'function';
const parseSettings: MutableParseSettings = {
allowInvalidAST: options.allowInvalidAST === true,
code,
Expand Down Expand Up @@ -135,7 +136,7 @@ export function createParseSettings(
});
}

warnAboutTSVersion(parseSettings);
warnAboutTSVersion(parseSettings, passedLoggerFn);

return parseSettings;
}
Expand Down
39 changes: 24 additions & 15 deletions packages/typescript-estree/src/parseSettings/warnAboutTSVersion.ts
Expand Up @@ -23,23 +23,32 @@ const isRunningSupportedTypeScriptVersion = semver.satisfies(

let warnedAboutTSVersion = false;

export function warnAboutTSVersion(parseSettings: ParseSettings): void {
export function warnAboutTSVersion(
parseSettings: ParseSettings,
passedLoggerFn: boolean,
): void {
if (!isRunningSupportedTypeScriptVersion && !warnedAboutTSVersion) {
const isTTY =
typeof process === 'undefined' ? false : process.stdout?.isTTY;
if (isTTY) {
const border = '=============';
const versionWarning = [
border,
'WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.',
'You may find that it works just fine, or you may not.',
`SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
`YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
'Please only submit bug reports when using the officially supported version.',
border,
];
parseSettings.log(versionWarning.join('\n\n'));
const border = '=============';
const versionWarning = [
border,
'WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.',
'You may find that it works just fine, or you may not.',
`SUPPORTED TYPESCRIPT VERSIONS: ${SUPPORTED_TYPESCRIPT_VERSIONS}`,
`YOUR TYPESCRIPT VERSION: ${ACTIVE_TYPESCRIPT_VERSION}`,
'Please only submit bug reports when using the officially supported version.',
border,
].join('\n\n');

if (passedLoggerFn) {
parseSettings.log(versionWarning);
} else {
const isTTY =
typeof process === 'undefined' ? false : process.stdout?.isTTY;
if (isTTY) {
parseSettings.log(versionWarning);
}
}
hyperupcall marked this conversation as resolved.
Show resolved Hide resolved

warnedAboutTSVersion = true;
}
}
@@ -1,12 +1,18 @@
import semver from 'semver';

import * as parser from '../../src/parser';
import type * as Parser from '../../src/parser';

jest.mock('semver');

const resetIsTTY = process.stdout.isTTY;

describe('Warn on unsupported TypeScript version', () => {
let parser: typeof Parser;

beforeEach(async () => {
// @ts-expect-error -- We don't support ESM imports of local code yet.
parser = await import('../../src/parser.ts');
hyperupcall marked this conversation as resolved.
Show resolved Hide resolved
});
afterEach(() => {
jest.resetModules();
jest.resetAllMocks();
Expand All @@ -26,7 +32,18 @@ describe('Warn on unsupported TypeScript version', () => {
);
});

it('should not warn the user when the user is running on a non TTY process', () => {
it('should warn the user if they are running on a non TTY process and a custom loggerFn was passed', () => {
(semver.satisfies as jest.Mock).mockReturnValue(false);
const loggerFn = jest.fn();
process.stdout.isTTY = false;

parser.parse('', {
loggerFn,
});
expect(loggerFn).toHaveBeenCalled();
});

it('should not warn the user if they are running on a non TTY process and a custom loggerFn was not passed', () => {
(semver.satisfies as jest.Mock).mockReturnValue(false);
jest.spyOn(console, 'log').mockImplementation();
process.stdout.isTTY = false;
Expand Down