Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit 7d37278

Browse files
committed
fix: document link for eslint core rule
1 parent 37435f5 commit 7d37278

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/components/LintMessages.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,26 @@ import { Alert } from "react-bootstrap";
44
import type { FC } from "react";
55
import type { Linter } from "eslint";
66

7-
const DOCS_PATH =
7+
const TS_ESLINT_DOCS_PATH =
88
"https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/";
99

10+
const ESLINT_DOCS_PATH = "https://eslint.org/docs/rules/";
11+
12+
function isTSESLintRule (ruleId: string) {
13+
return ruleId.startsWith('@typescript-eslint');
14+
}
15+
16+
function getDocLink (ruleId: string | null) {
17+
if (ruleId) {
18+
if (isTSESLintRule(ruleId)) {
19+
return `${TS_ESLINT_DOCS_PATH}${ruleId.replace(`${TS_ESLINT_SCOPE}/`, '')}.md`;
20+
} else {
21+
return `${ESLINT_DOCS_PATH}${ruleId}`;
22+
}
23+
}
24+
return '';
25+
}
26+
1027
interface Props {
1128
messages?: Linter.LintMessage[];
1229
}
@@ -22,10 +39,7 @@ export const LintMessages: FC<Props> = (props) => {
2239
({ line = 0, column = 0, message: lintMsg, ruleId, fatal }, index) => {
2340
const variant = fatal ? "danger" : "primary";
2441
const key = `lint-msg-${index}`;
25-
const docUrl = `${DOCS_PATH}${ruleId?.replace(
26-
`${TS_ESLINT_SCOPE}/`,
27-
""
28-
)}.md`;
42+
const docUrl = getDocLink(ruleId);
2943
return (
3044
<Alert variant={variant} key={key}>
3145
{`${line}:${column} - ${lintMsg}`}(

0 commit comments

Comments
 (0)