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

fix(parser): disallow errorOnTypeScriptSyntacticAndSemanticIssues #8784

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ function parseForESLint(
const parserOptions: TSESTreeOptions = {};
Object.assign(parserOptions, options, {
jsx: validateBoolean(options.ecmaFeatures.jsx),
/**
* Override errorOnTypeScriptSyntacticAndSemanticIssues and set it to false to prevent use from user config
* https://github.com/typescript-eslint/typescript-eslint/issues/8681#issuecomment-2000411834
*/
errorOnTypeScriptSyntacticAndSemanticIssues: false,
});
const analyzeOptions: AnalyzeOptions = {
globalReturn: options.ecmaFeatures.globalReturn,
Expand All @@ -123,6 +128,7 @@ function parseForESLint(
options.warnOnUnsupportedTypeScriptVersion,
true,
);

if (!warnOnUnsupportedTypeScriptVersion) {
parserOptions.loggerFn = false;
}
Expand Down
31 changes: 31 additions & 0 deletions packages/parser/tests/lib/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,42 @@ describe('parser', () => {
});
});

it('parseAndGenerateServices() should be called with options.errorOnTypeScriptSyntacticAndSemanticIssues overriden to false', () => {
const code = 'const valid = true;';
const spy = jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
const config: ParserOptions = {
loc: false,
comment: false,
range: false,
tokens: false,
sourceType: 'module' as const,
ecmaFeatures: {
globalReturn: false,
jsx: false,
},
// ts-estree specific
filePath: './isolated-file.src.ts',
project: 'tsconfig.json',
errorOnTypeScriptSyntacticAndSemanticIssues: true,
tsconfigRootDir: path.resolve(__dirname, '../fixtures/services'),
extraFileExtensions: ['.foo'],
};
parseForESLint(code, config);
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenLastCalledWith(code, {
jsx: false,
...config,
errorOnTypeScriptSyntacticAndSemanticIssues: false,
});
});

it('`warnOnUnsupportedTypeScriptVersion: false` should set `loggerFn: false` on typescript-estree', () => {
const code = 'const valid = true;';
const spy = jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: true });
expect(spy).toHaveBeenCalledWith(code, {
ecmaFeatures: {},
errorOnTypeScriptSyntacticAndSemanticIssues: false,
jsx: false,
sourceType: 'script',
warnOnUnsupportedTypeScriptVersion: true,
Expand All @@ -64,6 +94,7 @@ describe('parser', () => {
ecmaFeatures: {},
jsx: false,
sourceType: 'script',
errorOnTypeScriptSyntacticAndSemanticIssues: false,
loggerFn: false,
warnOnUnsupportedTypeScriptVersion: false,
});
Expand Down
Loading