Skip to content

Commit 594116e

Browse files
authored
chore(website): pass user defined compilerOptions to linter (typescript-eslint#5080)
1 parent 0bfab6c commit 594116e

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

packages/website/src/components/editor/LoadedEditor.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { WebLinter } from '../linter/WebLinter';
88
import { debounce } from '../lib/debounce';
99
import { lintCode, LintCodeAction } from '../linter/lintCode';
1010
import { createProvideCodeActions } from './createProvideCodeActions';
11+
import { createCompilerOptions } from '@site/src/components/editor/config';
1112
import { parseMarkers } from '../linter/utils';
1213

1314
export interface LoadedEditorProps extends CommonEditorProps {
@@ -39,13 +40,7 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
3940
const fixes = useRef(new Map<string, LintCodeAction[]>()).current;
4041

4142
useEffect(() => {
42-
const config = {
43-
noResolve: true,
44-
target: main.languages.typescript.ScriptTarget.ESNext,
45-
module: main.languages.typescript.ModuleKind.ESNext,
46-
...tsConfig,
47-
jsx: jsx ? main.languages.typescript.JsxEmit.React : undefined,
48-
};
43+
const config = createCompilerOptions(jsx, tsConfig);
4944

5045
webLinter.updateOptions(config);
5146
sandboxInstance.setCompilerSettings(config);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type Monaco from 'monaco-editor';
2+
3+
export function createCompilerOptions(
4+
jsx = false,
5+
tsConfig: Record<string, unknown> = {},
6+
): Monaco.languages.typescript.CompilerOptions {
7+
return {
8+
noResolve: true,
9+
lib: ['es2021', 'esnext'],
10+
// ts and monaco has different type as monaco types are not changing base on ts version
11+
target: window.ts.ScriptTarget.ESNext as number,
12+
module: window.ts.ModuleKind.ESNext as number,
13+
...tsConfig,
14+
jsx: jsx ? window.ts.JsxEmit.Preserve : window.ts.JsxEmit.None,
15+
};
16+
}

packages/website/src/components/editor/useSandboxServices.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { WebLinter } from '../linter/WebLinter';
1212
import { sandboxSingleton } from './loadSandbox';
1313
import { editorEmbedId } from './EditorEmbed';
1414
import { useColorMode } from '@docusaurus/theme-common';
15+
import { createCompilerOptions } from '@site/src/components/editor/config';
1516

1617
export interface SandboxServicesProps {
1718
readonly jsx?: boolean;
@@ -51,13 +52,7 @@ export const useSandboxServices = (
5152

5253
sandboxSingleton(props.ts)
5354
.then(async ({ main, sandboxFactory, ts, lintUtils }) => {
54-
const compilerOptions: Monaco.languages.typescript.CompilerOptions = {
55-
noResolve: true,
56-
target: main.languages.typescript.ScriptTarget.ESNext,
57-
jsx: props.jsx ? main.languages.typescript.JsxEmit.React : undefined,
58-
lib: ['es2021', 'esnext'],
59-
module: main.languages.typescript.ModuleKind.ESNext,
60-
};
55+
const compilerOptions = createCompilerOptions(props.jsx);
6156

6257
const sandboxConfig: Partial<SandboxConfig> = {
6358
text: '',

0 commit comments

Comments
 (0)