feat: add JSX lint category
MODIFY
packages/@romejs/compiler/lint/rules/index.ts
packages/@romejs/compiler/lint/rules/index.ts
@@ -80,13 +80,13 @@ import noTargetBlank from "./jsx-a11y/noTargetBlank";
import roleHasRequiredAriaProps from "./jsx-a11y/roleHasRequiredAriaProps";
import scope from "./jsx-a11y/scope";
import tabindexNoPositive from "./jsx-a11y/tabindexNoPositive";
+import noCommentText from "./jsx/noCommentText";
+import noDuplicateProps from "./jsx/noDuplicateProps";
+import pascalCase from "./jsx/pascalCase";
+import propsNoSpreading from "./jsx/propsNoSpreading";
import buttonHasType from "./react/buttonHasType";
import jsxFragments from "./react/jsxFragments";
import jsxKey from "./react/jsxKey";
-import jsxNoCommentText from "./react/jsxNoCommentText";
-import jsxNoDuplicateProps from "./react/jsxNoDuplicateProps";
-import jsxPascalCase from "./react/jsxPascalCase";
-import jsxPropsNoSpreading from "./react/jsxPropsNoSpreading";
import noAccessStateInSetState from "./react/noAccessStateInSetState";
import noArrayIndexKey from "./react/noArrayIndexKey";
import noChildrenProp from "./react/noChildrenProp";
@@ -185,13 +185,13 @@ export const lintTransforms = [
roleHasRequiredAriaProps,
scope,
tabindexNoPositive,
+ noCommentText,
+ noDuplicateProps,
+ pascalCase,
+ propsNoSpreading,
buttonHasType,
jsxFragments,
jsxKey,
- jsxNoCommentText,
- jsxNoDuplicateProps,
- jsxPascalCase,
- jsxPropsNoSpreading,
noAccessStateInSetState,
noArrayIndexKey,
noChildrenProp,

RENAME
packages/@romejs/compiler/lint/rules/react/jsxNoCommentText.test.ts
packages/@romejs/compiler/lint/rules/jsx/noCommentText.test.ts
@@ -25,7 +25,7 @@ test(
'const a = <div className={"cls" /* comment */}></div>',
],
},
- {category: "lint/react/jsxNoCommentText"},
+ {category: "lint/jsx/noCommentText"},
);
},
);

RENAME
packages/@romejs/compiler/lint/rules/react/jsxNoCommentText.ts
packages/@romejs/compiler/lint/rules/jsx/noCommentText.ts
@@ -12,7 +12,7 @@ import {descriptions} from "@romejs/diagnostics";
const commentPattern = /(^(\/\*\*|\/\*|\/\/)|\*\/$)/gm;
export default {
- name: "reactJsxNoCommentText",
+ name: "jsxNoCommentText",
enter(path: Path): AnyNode {
const {node} = path;
@@ -26,7 +26,7 @@ export default {
value: `{/**${node.value.replace(commentPattern, "")}*/}`,
},
},
- descriptions.LINT.REACT_JSX_NO_COMMENT_TEXT,
+ descriptions.LINT.JSX_NO_COMMENT_TEXT,
);
}
}

RENAME
packages/@romejs/compiler/lint/rules/react/jsxNoDuplicateProps.test.ts
packages/@romejs/compiler/lint/rules/jsx/noDuplicateProps.test.ts
@@ -13,7 +13,7 @@ test(
],
valid: ['<Hello foo="bar" />', '<div style="{}" />'],
},
- {category: "lint/react/jsxNoDuplicateProps"},
+ {category: "lint/jsx/noDuplicateProps"},
);
},
);

RENAME
packages/@romejs/compiler/lint/rules/react/jsxNoDuplicateProps.ts
packages/@romejs/compiler/lint/rules/jsx/noDuplicateProps.ts
@@ -9,7 +9,7 @@ function getAttributeKey(node: JSXAttribute): string {
}
export default {
- name: "reactJsxNoDuplicateProps",
+ name: "jsxNoDuplicateProps",
enter(path: Path): TransformExitResult {
const {context, node} = path;
@@ -20,7 +20,7 @@ export default {
const duplicates = new DiagnosticsDuplicateHelper(
context,
- descriptions.LINT.REACT_JSX_NO_DUPLICATE_PROPS,
+ descriptions.LINT.JSX_NO_DUPLICATE_PROPS,
);
for (const attr of node.attributes) {

RENAME
packages/@romejs/compiler/lint/rules/react/jsxPascalCase.test.ts
packages/@romejs/compiler/lint/rules/jsx/pascalCase.test.ts
@@ -18,7 +18,7 @@ test(
"<FooComponent />",
],
},
- {category: "lint/react/jsxPascalCase"},
+ {category: "lint/jsx/pascalCase"},
);
},
);

RENAME
packages/@romejs/compiler/lint/rules/react/jsxPascalCase.ts
packages/@romejs/compiler/lint/rules/jsx/pascalCase.ts
@@ -3,7 +3,7 @@ import {descriptions} from "@romejs/diagnostics";
import {toCamelCase} from "@romejs/string-utils";
export default {
- name: "reactJsxPascalCase",
+ name: "jsxPascalCase",
enter(path: Path): TransformExitResult {
const {node} = path;
@@ -15,10 +15,7 @@ export default {
if (node.name.name !== pascalCaseName) {
path.context.addNodeDiagnostic(
node,
- descriptions.LINT.REACT_JSX_PASCAL_CASE(
- node.name.name,
- pascalCaseName,
- ),
+ descriptions.LINT.JSX_PASCAL_CASE(node.name.name, pascalCaseName),
);
}
}

RENAME
packages/@romejs/compiler/lint/rules/react/jsxPropsNoSpreading.test.ts
packages/@romejs/compiler/lint/rules/jsx/propsNoSpreading.test.ts
@@ -18,7 +18,7 @@ test(
"<img src={src} alt={alt} />",
],
},
- {category: "lint/react/jsxPropsNoSpreading"},
+ {category: "lint/jsx/propsNoSpreading"},
);
},
);

RENAME
packages/@romejs/compiler/lint/rules/react/jsxPropsNoSpreading.ts
packages/@romejs/compiler/lint/rules/jsx/propsNoSpreading.ts
@@ -2,14 +2,14 @@ import {Path, TransformExitResult} from "@romejs/compiler";
import {descriptions} from "@romejs/diagnostics";
export default {
- name: "reactJsxPropsNoSpreading",
+ name: "jsxPropsNoSpreading",
enter(path: Path): TransformExitResult {
const {node} = path;
if (node.type === "JSXSpreadAttribute") {
path.context.addNodeDiagnostic(
node,
- descriptions.LINT.REACT_JSX_PROPS_NO_SPREADING,
+ descriptions.LINT.JSX_PROPS_NO_SPREADING,
);
}

MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -169,13 +169,13 @@ type LintDiagnosticCategory =
| "lint/jsx-a11y/roleHasRequiredAriaProps"
| "lint/jsx-a11y/scope"
| "lint/jsx-a11y/tabindexNoPositive"
+ | "lint/jsx/noCommentText"
+ | "lint/jsx/noDuplicateProps"
+ | "lint/jsx/pascalCase"
+ | "lint/jsx/propsNoSpreading"
| "lint/react/buttonHasType"
| "lint/react/jsxFragments"
| "lint/react/jsxKey"
- | "lint/react/jsxNoCommentText"
- | "lint/react/jsxNoDuplicateProps"
- | "lint/react/jsxPascalCase"
- | "lint/react/jsxPropsNoSpreading"
| "lint/react/noAccessStateInSetState"
| "lint/react/noArrayIndexKey"
| "lint/react/noChildrenProp"

MODIFY
packages/@romejs/diagnostics/descriptions/lint.ts
packages/@romejs/diagnostics/descriptions/lint.ts
@@ -20,8 +20,8 @@ export const lint = createDiagnosticsCategory({
category: "lint/ts/preferInterfaces",
message: "Use an interface instead of an object type alias",
},
- REACT_JSX_PROPS_NO_SPREADING: {
- category: "lint/react/jsxPropsNoSpreading",
+ JSX_PROPS_NO_SPREADING: {
+ category: "lint/jsx/propsNoSpreading",
message: "Avoid using property spreading in JSX components.",
advice: [
{
@@ -89,8 +89,8 @@ export const lint = createDiagnosticsCategory({
},
],
}),
- REACT_JSX_PASCAL_CASE: (oldName: string, newName: string) => ({
- category: "lint/react/jsxPascalCase",
+ JSX_PASCAL_CASE: (oldName: string, newName: string) => ({
+ category: "lint/jsx/pascalCase",
message: `Switch <emphasis>${oldName}</emphasis> to <emphasis>${newName}</emphasis>.`,
advice: [
{
@@ -163,8 +163,8 @@ export const lint = createDiagnosticsCategory({
},
],
},
- REACT_JSX_NO_DUPLICATE_PROPS: (key: string) => ({
- category: "lint/react/jsxNoDuplicateProps",
+ JSX_NO_DUPLICATE_PROPS: (key: string) => ({
+ category: "lint/jsx/noDuplicateProps",
message: `Avoid duplicate component props. Check the <emphasis>${key}</emphasis> prop.`,
}),
REACT_NO_STRING_REFS: (details: string) => ({
@@ -453,8 +453,8 @@ export const lint = createDiagnosticsCategory({
},
],
}),
- REACT_JSX_NO_COMMENT_TEXT: {
- category: "lint/react/jsxNoCommentText",
+ JSX_NO_COMMENT_TEXT: {
+ category: "lint/jsx/noCommentText",
message: "Wrap <emphasis>comments</emphasis> inside children within <emphasis>braces</emphasis>.",
advice: [
{

MODIFY
website/src/docs/check/rules/index.md
website/src/docs/check/rules/index.md
@@ -95,6 +95,10 @@ showHero: false
| role-has-required-aria-props | |
| scope | |
| tabindex-no-positive | |
+| no-comment-text | |
+| no-duplicate-props | |
+| pascal-case | |
+| props-no-spreading | |
## React
@@ -103,10 +107,6 @@ showHero: false
| button-has-type | |
| jsx-fragments | |
| jsx-key | |
-| jsx-no-comment-text | |
-| jsx-no-duplicate-props | |
-| jsx-pascal-case | |
-| jsx-props-no-spreading | |
| no-access-state-in-set-state | |
| no-array-index-key | |
| no-children-prop | |

feat: add JSX lint category (#675)