Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(website): Show tsconfig parsing errors in tab#10991

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
developer-bandi wants to merge6 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromdeveloper-bandi:feature/tscofing-view-error
Open
Show file tree
Hide file tree
Changes fromall 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
2 changes: 1 addition & 1 deletionpackages/website/src/components/ErrorsViewer.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,7 +86,7 @@ function ErrorBlock({
</FixButton>
)}
</div>
{item.suggestions.length > 0 && (
{item.suggestions && item.suggestions.length > 0 && (
<div>
{item.suggestions.map((fixer, index) => (
<div
Expand Down
14 changes: 10 additions & 4 deletionspackages/website/src/components/Playground.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,11 @@ function Playground(): React.JSX.Element {
const windowSize = useWindowSize();
const [state, setState] = useHashState(defaultConfig);
const [astModel, setAstModel] = useState<UpdateModel>();
const [markers, setMarkers] = useState<ErrorGroup[]>();
const [markers, setMarkers] = useState<Record<TabType, ErrorGroup[]>>({
code: [],
eslintrc: [],
tsconfig: [],
});
const [ruleNames, setRuleNames] = useState<RuleDetails[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [tsVersions, setTSVersion] = useState<readonly string[]>([]);
Expand DownExpand Up@@ -165,8 +169,10 @@ function Playground(): React.JSX.Element {
active={state.showAST ?? false}
additionalTabsInfo={{
Errors:
markers?.reduce((prev, cur) => prev + cur.items.length, 0) ||
0,
markers[activeTab].reduce(
(prev, cur) => prev + cur.items.length,
0,
) || 0,
}}
change={showAST => setState({ showAST })}
tabs={detailTabs}
Expand DownExpand Up@@ -216,7 +222,7 @@ function Playground(): React.JSX.Element {
/>
)
) : (
<ErrorsViewer value={markers} />
<ErrorsViewer value={markers[activeTab]} />
)}
</div>
</Panel>
Expand Down
19 changes: 17 additions & 2 deletionspackages/website/src/components/editor/LoadedEditor.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,8 +83,23 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
const markers = monaco.editor.getModelMarkers({
resource: model.uri,
});
onMarkersChange(parseMarkers(markers, codeActions, editor));
}, [codeActions, onMarkersChange, editor, monaco.editor]);

const errors = parseMarkers(markers, codeActions, editor);

onMarkersChange(prev => {
const tsconfigErrors =
activeTab === 'tsconfig' &&
!errors.length &&
Object.values(prev[activeTab]).filter(
error => error.group === 'TypeScript',
);

return {
...prev,
[activeTab]: tsconfigErrors || errors,
};
});
}, [activeTab, codeActions, onMarkersChange, editor, monaco.editor]);

useEffect(() => {
webLinter.updateParserOptions(sourceType);
Expand Down
4 changes: 3 additions & 1 deletionpackages/website/src/components/editor/types.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,9 @@ export interface CommonEditorProps extends ConfigModel {
readonly activeTab: TabType;
readonly onASTChange: (value: UpdateModel | undefined) => void;
readonly onChange: (cfg: Partial<ConfigModel>) => void;
readonly onMarkersChange: (value: ErrorGroup[]) => void;
readonly onMarkersChange: React.Dispatch<
React.SetStateAction<Record<TabType, ErrorGroup[]>>
>;
readonly onSelect: (position?: number) => void;
readonly selectedRange?: SelectedRange;
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,6 +116,7 @@ export const useSandboxServices = (
system,
lintUtils,
sandboxInstance.tsvfs,
props.onMarkersChange,
);

onLoaded(
Expand Down
42 changes: 41 additions & 1 deletionpackages/website/src/components/linter/createLinter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,10 @@ import type {
} from '@typescript-eslint/utils/ts-eslint';
import type * as ts from 'typescript';

import type {
ErrorGroup,
TabType,
} from '../../../../website/src/components/types';
import type {
LinterOnLint,
LinterOnParse,
Expand DownExpand Up@@ -42,6 +46,9 @@ export function createLinter(
system: PlaygroundSystem,
webLinterModule: WebLinterModule,
vfs: typeof tsvfs,
onMarkersChange: React.Dispatch<
React.SetStateAction<Record<TabType, ErrorGroup[]>>
>,
): CreateLinter {
const rules: CreateLinter['rules'] = new Map();
const configs = new Map(Object.entries(webLinterModule.configs));
Expand DownExpand Up@@ -153,14 +160,47 @@ export function createLinter(
};

const applyTSConfig = (fileName: string): void => {
let error: ErrorGroup | null = null;

try {
const file = system.readFile(fileName) ?? '{}';
const parsed = parseTSConfig(file).compilerOptions;
compilerOptions = createCompilerOptions(parsed);
console.log('[Editor] Updating', fileName, compilerOptions);
parser.updateConfig(compilerOptions);
} catch (e) {
console.error(e);
if (e instanceof Error) {
error = {
group: 'TypeScript',
items: e.message
.trim()
.split('\n')
.map((message: string) => {
Comment on lines +177 to +178

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Do you have an example of a message that needs to be split? I've only been able to make versions with a single reported error at a time.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not sure if this is realistic, but I used split because I was able to generate two errors with the settings below.

{  "compilerOptions": {    "moduleResolution": "classic",    "resolveJsonModule": true,    "incremental": true,    "outFile": "dist/bundle.js"  }}
스크린샷 2025-04-12 오전 11 12 03

return {
message,
severity: 8, // MarkerSeverity.Error
};
}),
uri: undefined,
};
}
} finally {
onMarkersChange(prev => {
const activeTabErrors = Object.fromEntries(
prev.tsconfig.map(error => [error.group, error]),
);

if (error) {
activeTabErrors.TypeScript = error;
} else {
delete activeTabErrors.TypeScript;
}

return {
...prev,
tsconfig: Object.values(activeTabErrors),
};
});
}
};

Expand Down
4 changes: 2 additions & 2 deletionspackages/website/src/components/types.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,10 +40,10 @@ export type SelectedRange = [number, number];

export interface ErrorItem {
fixer?: { fix(): void; message: string };
location: string;
location?: string;
message: string;
severity: number;
suggestions: { fix(): void; message: string }[];
suggestions?: { fix(): void; message: string }[];
}

export interface ErrorGroup {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp