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

docs(website): [playground] add links to documentation and improve fixers#5169

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

Merged
Merged
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
7 changes: 5 additions & 2 deletionspackages/website/src/components/ErrorsViewer.module.css
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,9 +13,12 @@
margin: 0;
}

.fixer {
margin: 0.5rem 1.5rem;
.fixerContainer {
display: flex;
justify-content: space-between;
align-items: center;
}

.fixer {
margin: 0.5rem 0 0.5rem 1.5rem;
}
103 changes: 62 additions & 41 deletionspackages/website/src/components/ErrorsViewer.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
import React, { useEffect,useMemo,useState } from 'react';
import React, { useEffect, useState } from 'react';
import type Monaco from 'monaco-editor';
importtype { ErrorItem }from './types';
importclsxfrom 'clsx';

import type { ErrorItem, ErrorGroup } from './types';
import IconExternalLink from '@theme/IconExternalLink';
import styles from './ErrorsViewer.module.css';

export interface ErrorsViewerProps {
readonly value?:ErrorItem[];
readonly value?:ErrorGroup[];
}

export interface ErrorBlockProps {
Expand All@@ -14,6 +16,12 @@ export interface ErrorBlockProps {
readonly isLocked: boolean;
}

export interface FixButtonProps {
readonly fix: () => void;
readonly setIsLocked: (value: boolean) => void;
readonly disabled: boolean;
}

function severityClass(severity: Monaco.MarkerSeverity): string {
switch (severity) {
case 8:
Expand All@@ -26,16 +34,19 @@ function severityClass(severity: Monaco.MarkerSeverity): string {
return 'info';
}

function groupErrorItems(items: ErrorItem[]): [string, ErrorItem[]][] {
return Object.entries(
items.reduce<Record<string, ErrorItem[]>>((acc, obj) => {
if (!acc[obj.group]) {
acc[obj.group] = [];
}
acc[obj.group].push(obj);
return acc;
}, {}),
).sort(([a], [b]) => a.localeCompare(b));
function FixButton(props: FixButtonProps): JSX.Element {
return (
<button
className="button button--primary button--sm"
disabled={props.disabled}
onClick={(): void => {
props.fix();
props.setIsLocked(true);
}}
>
fix
</button>
);
}

function ErrorBlock({
Expand All@@ -46,30 +57,35 @@ function ErrorBlock({
return (
<div className={`admonition alert alert--${severityClass(item.severity)}`}>
<div className="admonition-content">
<div className="row row--no-gutters">
<div className="col col--12">
<div className={clsx(!!item.fixer && styles.fixerContainer)}>
<div>
{item.message} {item.location}
</div>
{item.hasFixers && (
<div className="col col--12">
{item.fixers.map((fixer, index) => (
<div key={index} className={styles.fixer}>
<span>&gt; {fixer.message}</span>
<button
className="button button--primary button--sm"
disabled={isLocked}
onClick={(): void => {
fixer.fix();
setIsLocked(true);
}}
>
fix
</button>
</div>
))}
</div>
{item.fixer && (
<FixButton
disabled={isLocked}
fix={item.fixer.fix}
setIsLocked={setIsLocked}
/>
)}
</div>
{item.suggestions.length > 0 && (
<div>
{item.suggestions.map((fixer, index) => (
<div
key={index}
className={clsx(styles.fixerContainer, styles.fixer)}
>
<span>&gt; {fixer.message}</span>
<FixButton
disabled={isLocked}
fix={fixer.fix}
setIsLocked={setIsLocked}
/>
</div>
))}
</div>
)}
</div>
</div>
);
Expand All@@ -78,11 +94,6 @@ function ErrorBlock({
export default function ErrorsViewer({
value,
}: ErrorsViewerProps): JSX.Element {
const model = useMemo(
() => (value ? groupErrorItems(value) : undefined),
[value],
);

const [isLocked, setIsLocked] = useState(false);

useEffect(() => {
Expand All@@ -91,11 +102,21 @@ export default function ErrorsViewer({

return (
<div className={styles.list}>
{model?.map(([group,data]) => {
{value?.map(({group,uri, items }) => {
return (
<div className="margin-top--sm" key={group}>
<h4>{group}</h4>
{data.map((item, index) => (
<h4>
{group}
{uri && (
<>
{' - '}
<a href={uri} target="_blank">
docs <IconExternalLink width={13.5} height={13.5} />
</a>
</>
)}
</h4>
{items.map((item, index) => (
<ErrorBlock
isLocked={isLocked}
setIsLocked={setIsLocked}
Expand Down
4 changes: 2 additions & 2 deletionspackages/website/src/components/Playground.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ import ASTViewerTS from './ASTViewerTS';
import type {
RuleDetails,
SelectedRange,
ErrorItem,
ErrorGroup,
TabType,
ConfigModel,
} from './types';
Expand DownExpand Up@@ -66,7 +66,7 @@ function Playground(): JSX.Element {
const [esAst, setEsAst] = useState<TSESTree.Program | null>();
const [tsAst, setTsAST] = useState<SourceFile | null>();
const [scope, setScope] = useState<Record<string, unknown> | null>();
const [markers, setMarkers] = useState<ErrorItem[]>();
const [markers, setMarkers] = useState<ErrorGroup[]>();
const [ruleNames, setRuleNames] = useState<RuleDetails[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [tsVersions, setTSVersion] = useState<readonly string[]>([]);
Expand Down
4 changes: 3 additions & 1 deletionpackages/website/src/components/editor/LoadedEditor.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,7 +129,9 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({

const messages = webLinter.lint(code);

const markers = parseLintResults(messages, codeActions);
const markers = parseLintResults(messages, codeActions, ruleId =>
sandboxInstance.monaco.Uri.parse(webLinter.rulesUrl.get(ruleId) ?? ''),
);

sandboxInstance.monaco.editor.setModelMarkers(
tabs.code,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,9 +28,10 @@ export function createProvideCodeActions(
const messages = fixes.get(createURI(marker)) ?? [];
for (const message of messages) {
actions.push({
title: message.message,
title: message.message + (message.code ? ` (${message.code})` : ''),
diagnostics: [marker],
kind: 'quickfix',
isPreferred: message.isPreferred,
edit: {
edits: [
{
Expand Down
4 changes: 2 additions & 2 deletionspackages/website/src/components/editor/types.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import type Monaco from 'monaco-editor';
import type { ConfigModel, SelectedRange,ErrorItem, TabType } from '../types';
import type { ConfigModel, SelectedRange,ErrorGroup, TabType } from '../types';
import type { TSESTree } from '@typescript-eslint/utils';
import type { SourceFile } from 'typescript';

Expand All@@ -11,6 +11,6 @@ export interface CommonEditorProps extends ConfigModel {
readonly onTsASTChange: (value: undefined | SourceFile) => void;
readonly onEsASTChange: (value: undefined | TSESTree.Program) => void;
readonly onScopeChange: (value: undefined | Record<string, unknown>) => void;
readonly onMarkersChange: (value:ErrorItem[]) => void;
readonly onMarkersChange: (value:ErrorGroup[]) => void;
readonly onSelect: (position: Monaco.Position | null) => void;
}
14 changes: 8 additions & 6 deletionspackages/website/src/components/linter/WebLinter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,8 @@ export class WebLinter {
private lintUtils: LintUtils;
private rules: TSESLint.Linter.RulesRecord = {};

public ruleNames: { name: string; description?: string }[];
public readonly ruleNames: { name: string; description?: string }[] = [];
public readonly rulesUrl = new Map<string, string | undefined>();

constructor(
system: System,
Expand All@@ -54,11 +55,12 @@ export class WebLinter {
},
});

this.ruleNames = Array.from(this.linter.getRules()).map(value => {
return {
name: value[0],
description: value[1]?.meta?.docs?.description,
};
this.linter.getRules().forEach((item, name) => {
this.ruleNames.push({
name: name,
description: item.meta?.docs?.description,
});
this.rulesUrl.set(name, item.meta?.docs?.url);
});
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp