diff --git a/packages/core/docs/functions/isDeclaredInRenderPropLoose.md b/packages/core/docs/functions/isDeclaredInRenderPropLoose.md
index 7671b11f13..4f2469393c 100644
--- a/packages/core/docs/functions/isDeclaredInRenderPropLoose.md
+++ b/packages/core/docs/functions/isDeclaredInRenderPropLoose.md
@@ -9,7 +9,7 @@
> **isDeclaredInRenderPropLoose**(`node`): `boolean`
Unsafe check whether given node is declared inside a render prop
-```jsx
+```tsx
_ =
` ^^^^^^ `
_ =
diff --git a/packages/core/docs/functions/isInsideRenderMethod.md b/packages/core/docs/functions/isInsideRenderMethod.md
index 9aabcda53a..34f2fd8d9d 100644
--- a/packages/core/docs/functions/isInsideRenderMethod.md
+++ b/packages/core/docs/functions/isInsideRenderMethod.md
@@ -9,7 +9,7 @@
> **isInsideRenderMethod**(`node`): `boolean`
Check whether given node is declared inside class component's render block
-```jsx
+```tsx
class Component extends React.Component {
render() {
class NestedClassComponent extends React.Component {
diff --git a/packages/core/docs/functions/isRenderFunctionLoose.md b/packages/core/docs/functions/isRenderFunctionLoose.md
index bbf3821ebf..e565993812 100644
--- a/packages/core/docs/functions/isRenderFunctionLoose.md
+++ b/packages/core/docs/functions/isRenderFunctionLoose.md
@@ -9,7 +9,7 @@
> **isRenderFunctionLoose**(`context`, `node`): `boolean`
Unsafe check whether given node is a render function
-```jsx
+```tsx
const renderRow = () =>
` ^^^^^^^^^^^^`
_ = } />
diff --git a/packages/core/docs/functions/isRenderPropLoose.md b/packages/core/docs/functions/isRenderPropLoose.md
index 78a75b11db..93732276ba 100644
--- a/packages/core/docs/functions/isRenderPropLoose.md
+++ b/packages/core/docs/functions/isRenderPropLoose.md
@@ -9,7 +9,7 @@
> **isRenderPropLoose**(`context`, `node`): `boolean`
Unsafe check whether given JSXAttribute is a render prop
-```jsx
+```tsx
_ = } />
` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
```
diff --git a/packages/core/src/component/component-lifecycle.ts b/packages/core/src/component/component-lifecycle.ts
index ab4be33051..1e495e8a11 100644
--- a/packages/core/src/component/component-lifecycle.ts
+++ b/packages/core/src/component/component-lifecycle.ts
@@ -66,7 +66,7 @@ export function isFunctionOfRenderMethod(node: AST.TSESTreeFunction) {
/**
* Check whether given node is declared inside class component's render block
- * ```jsx
+ * ```tsx
* class Component extends React.Component {
* render() {
* class NestedClassComponent extends React.Component {
diff --git a/packages/core/src/component/component-render-prop.ts b/packages/core/src/component/component-render-prop.ts
index 9869cac22f..2c92c0bc37 100644
--- a/packages/core/src/component/component-render-prop.ts
+++ b/packages/core/src/component/component-render-prop.ts
@@ -6,7 +6,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
/**
* Unsafe check whether given node is a render function
- * ```jsx
+ * ```tsx
* const renderRow = () =>
* ` ^^^^^^^^^^^^`
* _ = } />
@@ -39,7 +39,7 @@ export function isRenderFunctionLoose(context: RuleContext, node: AST.TSESTreeFu
/**
* Unsafe check whether given JSXAttribute is a render prop
- * ```jsx
+ * ```tsx
* _ = } />
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
* ```
@@ -59,7 +59,7 @@ export function isRenderPropLoose(context: RuleContext, node: TSESTree.JSXAttrib
/**
* Unsafe check whether given node is declared directly inside a render property
- * ```jsx
+ * ```tsx
* const rows = { render: () => }
* ` ^^^^^^^^^^^^^ `
* _ = }] } />
@@ -80,7 +80,7 @@ export function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node) {
/**
* Unsafe check whether given node is declared inside a render prop
- * ```jsx
+ * ```tsx
* _ =
* ` ^^^^^^ `
* _ =
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-boolean.md b/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-boolean.md
index d0d71587e7..55cd9bc00b 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-boolean.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-boolean.md
@@ -29,23 +29,19 @@ A **safe** auto-fix is available for this rule.
### Failing
```tsx
-import React from "react";
-
-function MyComponent() {
- return ;
- // ^^^^^^^^
- // - Avoid using shorthand syntax for 'disabled' attribute.
-}
+const Input = ;
+// ^^^^^^^
+// - Expected `checked={true}` instead of `checked`
+const button = ;
+// ^^^^^^^^
+// - Expected `disabled={true}` instead of `disabled`
```
### Passing
```tsx
-import React from "react";
-
-function MyComponent() {
- return ;
-}
+const Input = ;
+const button = ;
```
## Implementation
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-fragment.md b/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-fragment.md
index 9524c0f4c4..75da945cf0 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-fragment.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-fragment.md
@@ -25,7 +25,7 @@ Enforces explicit `` components instead of the shorthand `<>` or `>`
```tsx
import React from "react";
-function MyComponent() {
+export function MyComponent() {
return (
<>
@@ -40,7 +40,7 @@ function MyComponent() {
```tsx
import React, { Fragment } from "react";
-function MyComponent() {
+export function MyComponent() {
return (
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/jsx-no-undef.md b/packages/plugins/eslint-plugin-react-x/src/rules/jsx-no-undef.md
index 60829c8e66..bdf7688f78 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/jsx-no-undef.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/jsx-no-undef.md
@@ -22,40 +22,21 @@ This rule is used to prevent the use of undefined variables in JSX. It checks fo
### Failing
-```jsx
-const MyComponent = () => {
- return (
-
-
-
- );
-};
+```tsx
+import React from "react";
+
+const button = ;
+// ^^^^^^^^
+// - 'MyButton' is not defined
```
### Passing
-```jsx
-import Foo from "./Foo";
-
-const MyComponent = () => {
- return (
-
-
-
- );
-};
-```
-
-```jsx
-const Foo = () =>
Foo
;
+```tsx
+import React from "react";
+import MyButton from "./MyButton";
-const MyComponent = () => {
- return (
-
-
-
- );
-};
+const button = ;
```
## Implementation
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/jsx-uses-vars.md b/packages/plugins/eslint-plugin-react-x/src/rules/jsx-uses-vars.md
index 89d5308267..5dfb5d59e1 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/jsx-uses-vars.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/jsx-uses-vars.md
@@ -31,13 +31,13 @@ This rule only has an effect when the `no-unused-vars` rule is enabled.
### Failing
```tsx
-const Hello = require("./Hello");
+import Hello from "./Hello";
```
### Passing
```tsx
-const Hello = require("./Hello");
+import Hello from "./Hello";
;
```
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-class-component.md b/packages/plugins/eslint-plugin-react-x/src/rules/no-class-component.md
index 7e084bdd4a..e3c4eb6005 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/no-class-component.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-class-component.md
@@ -63,6 +63,31 @@ function MyComponent({ name }: MyComponentProps) {
}
```
+```tsx
+import React, { Component } from "react";
+
+interface ErrorBoundaryProps {
+ children: React.ReactNode;
+}
+
+// This is an exception to the rule, as ErrorBoundary is a special case.
+class ErrorBoundary extends Component {
+ state = { hasError: false };
+
+ static getDerivedStateFromError(error: Error) {
+ return { hasError: true };
+ }
+
+ render() {
+ if (this.state.hasError) {
+ return
Something went wrong.
;
+ }
+
+ return this.props.children;
+ }
+}
+```
+
## Implementation
- [Rule source](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x/src/rules/no-class-component.ts)
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-comment-textnodes.md b/packages/plugins/eslint-plugin-react-x/src/rules/no-comment-textnodes.md
index a90e064e21..81cccbf071 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/no-comment-textnodes.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-comment-textnodes.md
@@ -34,7 +34,7 @@ This could be a mistake during code editing or it could be a misunderstanding of
```tsx
import React from "react";
-function MyComponent() {
+function MyComponent1() {
return
// empty div
;
// ^^^^^^^^^^^^
// - Possible misused comment in text node. Comments inside children section of tag should be placed inside braces.
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.md b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.md
index 1182751c56..0afd2cb232 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.md
@@ -40,7 +40,8 @@ A **safe** codemod is available for this rule.
### Failing
```tsx
-const ThemeContext = createContext("");
+import React from "react";
+import ThemeContext from "./ThemeContext";
function App({ children }) {
return (
@@ -54,7 +55,8 @@ function App({ children }) {
### Passing
```tsx
-const ThemeContext = createContext("");
+import React from "react";
+import ThemeContext from "./ThemeContext";
function App({ children }) {
return (
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.md b/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.md
index 5e31e1164e..01daf5777a 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.md
@@ -40,11 +40,13 @@ An **unsafe** codemod is available for this rule.
### Failing
```tsx
-import { forwardRef } from "react";
+import React, { forwardRef } from "react";
-const MyInput = forwardRef(function MyInput(props, ref) {
- return ;
-});
+const MyInput = forwardRef(
+ function MyInput(props, ref) {
+ return ;
+ },
+);
```
```tsx
@@ -55,12 +57,17 @@ interface MyInputProps {
onChange: (value: string) => void;
}
-const MyInput = React.forwardRef(function MyInput(
- { value, onChange },
- ref,
-) {
- return onChange(e.target.value)} />;
-});
+const MyInput = React.forwardRef(
+ function MyInput({ value, onChange }, ref) {
+ return (
+ onChange(e.target.value)}
+ />
+ );
+ },
+);
```
### Passing
@@ -79,8 +86,18 @@ interface MyInputProps {
onChange: (value: string) => void;
}
-function MyInput({ ref, value, onChange }: MyInputProps & { ref: React.RefObject }) {
- return onChange(e.target.value)} />;
+function MyInput({
+ ref,
+ value,
+ onChange,
+}: MyInputProps & { ref: React.RefObject }) {
+ return (
+ onChange(e.target.value)}
+ />
+ );
}
```
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-key.md b/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-key.md
index 8337b73b3c..4fa604300c 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-key.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-missing-key.md
@@ -42,9 +42,9 @@ function MyComponent({ items }: MyComponentProps) {
return (
{items.map((todo) => (
-
- {/* ^^^^^^^^^^^^^^^ */}
- {/* - Missing 'key' for element when rendering list. */}
+
))}
);
}
diff --git a/packages/plugins/eslint-plugin-react-x/src/rules/no-unstable-default-props.md b/packages/plugins/eslint-plugin-react-x/src/rules/no-unstable-default-props.md
index 56acd64d00..ab4ce6972c 100644
--- a/packages/plugins/eslint-plugin-react-x/src/rules/no-unstable-default-props.md
+++ b/packages/plugins/eslint-plugin-react-x/src/rules/no-unstable-default-props.md
@@ -162,8 +162,8 @@ interface MyComponentProps {
}
function MyComponent({ num = 3, str = "foo", bool = true }: MyComponentProps) {
- // -------------------------------------
- // - Primitives are all compared by value, so are safe to be inlined as default props.
+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ // - Primitives are all compared by value, so are safe to be inlined as default props.
return null;
}
```