Skip to content

Commit

Permalink
fix(parser): disallow errorOnTypeScriptSyntacticAndSemanticIssues (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
peanutenthusiast committed Mar 28, 2024
1 parent 5707268 commit d5615d7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
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

0 comments on commit d5615d7

Please sign in to comment.