Skip to content

Commit

Permalink
feat: show error message in rsdoctor page
Browse files Browse the repository at this point in the history
  • Loading branch information
nyqykk committed Dec 2, 2024
1 parent 32d6972 commit 4346e15
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
6 changes: 6 additions & 0 deletions examples/rsbuild-minimal/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export default defineConfig({
limit: 1,
},
],
'ecma-version-check': [
'Warn',
{
ecmaVersion: 3,
},
],
},
},
port: 9988,
Expand Down
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dist/"
],
"devDependencies": {
"@rsbuild/plugin-check-syntax": "1.2.0-beta.1",
"@ant-design/icons": "5.5.1",
"@monaco-editor/react": "4.6.0",
"@rsdoctor/graph": "workspace:*",
Expand Down
19 changes: 16 additions & 3 deletions packages/components/src/components/Alert/link.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
import React from 'react';
import { Alert, Button, Space, Typography } from 'antd';
import { InfoCircleOutlined } from '@ant-design/icons';

import { useRuleIndexNavigate } from '../../utils';

import { LinkAlertProps } from './types';

export const LinkRuleAlert: React.FC<LinkAlertProps> = ({ data }) => {
const { title, description = '', level, code } = data;
const { title, error, description, level, code } = data;
const navigate = useRuleIndexNavigate(code, data.link);

return (
<Alert
showIcon
message={
<Space>
<Typography.Text code strong onClick={navigate} style={{ cursor: 'pointer' }}>
<Typography.Text
code
strong
onClick={navigate}
style={{ cursor: 'pointer' }}
>
<a>{code}</a>
</Typography.Text>
<Typography.Text strong>{title}</Typography.Text>
</Space>
}
description={<div dangerouslySetInnerHTML={{ __html: description }} />}
description={
<div>
{error?.source?.path ? <div>Source: {error.source.path}</div> : null}
{error?.output?.path ? <div>Output: {error.output.path}</div> : null}
<div>Message: {description}</div>
</div>
}
type={level === 'warn' ? 'info' : level}
action={
<Button type="link" onClick={navigate} size="small">
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/components/Alert/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Rule } from '@rsdoctor/types';
import React from 'react';

import type { CheckSyntax } from '@rsbuild/plugin-check-syntax';

export interface AlertProps extends Omit<PackageRelationAlertProps, 'data'> {
data: Rule.RuleStoreDataItem;
cwd: string;
Expand Down Expand Up @@ -29,8 +31,12 @@ export interface CodeViewAlertProps {
cwd: string;
}

type CheckSyntaxError =
CheckSyntax['errors'] extends Array<infer T> ? T : false;
export interface LinkAlertProps {
data: Rule.LinkRuleStoreData;
data: Rule.LinkRuleStoreData & {
error?: CheckSyntaxError;
};
}

export interface EMOAlertProps {
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/rules/rules/ecma-version-check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { defineRule } from '../../rule';
import { Config } from './types';

import { Linter } from '@rsdoctor/types';

export type { Config } from './types';

const title = 'ecma-version-check';
Expand Down Expand Up @@ -49,9 +48,9 @@ export const rule = defineRule<typeof title, Config>(() => {
await checkSyntax.check(asset.path, asset.content);
checkSyntax.errors.forEach((err) => {
report({
message: err.message,
message: `Find some syntax that does not match "ecmaVersion <= ${checkSyntax.ecmaVersion}"`,
detail: {
err,
error: err,
type: 'link',
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/rules/rules/ecma-version-check/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { PluginCheckSyntaxOptions } from '@rsbuild/plugin-check-syntax';

export type Config = PluginCheckSyntaxOptions;
export interface Config extends PluginCheckSyntaxOptions {}
6 changes: 4 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4346e15

Please sign in to comment.