Skip to content

Commit 1ee1902

Browse files
peanutenthusiastyeonjuan
authored andcommitted
fix(parser): disallow errorOnTypeScriptSyntacticAndSemanticIssues (typescript-eslint#8784)
1 parent b040340 commit 1ee1902

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Diff for: packages/parser/src/parser.ts

+6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ function parseForESLint(
106106
const parserOptions: TSESTreeOptions = {};
107107
Object.assign(parserOptions, options, {
108108
jsx: validateBoolean(options.ecmaFeatures.jsx),
109+
/**
110+
* Override errorOnTypeScriptSyntacticAndSemanticIssues and set it to false to prevent use from user config
111+
* https://github.com/typescript-eslint/typescript-eslint/issues/8681#issuecomment-2000411834
112+
*/
113+
errorOnTypeScriptSyntacticAndSemanticIssues: false,
109114
});
110115
const analyzeOptions: AnalyzeOptions = {
111116
globalReturn: options.ecmaFeatures.globalReturn,
@@ -123,6 +128,7 @@ function parseForESLint(
123128
options.warnOnUnsupportedTypeScriptVersion,
124129
true,
125130
);
131+
126132
if (!warnOnUnsupportedTypeScriptVersion) {
127133
parserOptions.loggerFn = false;
128134
}

Diff for: packages/parser/tests/lib/parser.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,42 @@ describe('parser', () => {
4848
});
4949
});
5050

51+
it('parseAndGenerateServices() should be called with options.errorOnTypeScriptSyntacticAndSemanticIssues overriden to false', () => {
52+
const code = 'const valid = true;';
53+
const spy = jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
54+
const config: ParserOptions = {
55+
loc: false,
56+
comment: false,
57+
range: false,
58+
tokens: false,
59+
sourceType: 'module' as const,
60+
ecmaFeatures: {
61+
globalReturn: false,
62+
jsx: false,
63+
},
64+
// ts-estree specific
65+
filePath: './isolated-file.src.ts',
66+
project: 'tsconfig.json',
67+
errorOnTypeScriptSyntacticAndSemanticIssues: true,
68+
tsconfigRootDir: path.resolve(__dirname, '../fixtures/services'),
69+
extraFileExtensions: ['.foo'],
70+
};
71+
parseForESLint(code, config);
72+
expect(spy).toHaveBeenCalledTimes(1);
73+
expect(spy).toHaveBeenLastCalledWith(code, {
74+
jsx: false,
75+
...config,
76+
errorOnTypeScriptSyntacticAndSemanticIssues: false,
77+
});
78+
});
79+
5180
it('`warnOnUnsupportedTypeScriptVersion: false` should set `loggerFn: false` on typescript-estree', () => {
5281
const code = 'const valid = true;';
5382
const spy = jest.spyOn(typescriptESTree, 'parseAndGenerateServices');
5483
parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: true });
5584
expect(spy).toHaveBeenCalledWith(code, {
5685
ecmaFeatures: {},
86+
errorOnTypeScriptSyntacticAndSemanticIssues: false,
5787
jsx: false,
5888
sourceType: 'script',
5989
warnOnUnsupportedTypeScriptVersion: true,
@@ -64,6 +94,7 @@ describe('parser', () => {
6494
ecmaFeatures: {},
6595
jsx: false,
6696
sourceType: 'script',
97+
errorOnTypeScriptSyntacticAndSemanticIssues: false,
6798
loggerFn: false,
6899
warnOnUnsupportedTypeScriptVersion: false,
69100
});

0 commit comments

Comments
 (0)