Skip to content

Commit a970a1a

Browse files
authored
docs: improve examples in rules docs (#1020)
1 parent 34bf9e7 commit a970a1a

16 files changed

+101
-75
lines changed

packages/core/docs/functions/isDeclaredInRenderPropLoose.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
> **isDeclaredInRenderPropLoose**(`node`): `boolean`
1010
1111
Unsafe check whether given node is declared inside a render prop
12-
```jsx
12+
```tsx
1313
_ = <Component renderRow={"node"} />
1414
` ^^^^^^ `
1515
_ = <Component rows={ [{ render: "node" }] } />

packages/core/docs/functions/isInsideRenderMethod.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
> **isInsideRenderMethod**(`node`): `boolean`
1010
1111
Check whether given node is declared inside class component's render block
12-
```jsx
12+
```tsx
1313
class Component extends React.Component {
1414
render() {
1515
class NestedClassComponent extends React.Component {

packages/core/docs/functions/isRenderFunctionLoose.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
> **isRenderFunctionLoose**(`context`, `node`): `boolean`
1010
1111
Unsafe check whether given node is a render function
12-
```jsx
12+
```tsx
1313
const renderRow = () => <div />
1414
` ^^^^^^^^^^^^`
1515
_ = <Component renderRow={() => <div />} />

packages/core/docs/functions/isRenderPropLoose.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
> **isRenderPropLoose**(`context`, `node`): `boolean`
1010
1111
Unsafe check whether given JSXAttribute is a render prop
12-
```jsx
12+
```tsx
1313
_ = <Component renderRow={() => <div />} />
1414
` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
1515
```

packages/core/src/component/component-lifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function isFunctionOfRenderMethod(node: AST.TSESTreeFunction) {
6666

6767
/**
6868
* Check whether given node is declared inside class component's render block
69-
* ```jsx
69+
* ```tsx
7070
* class Component extends React.Component {
7171
* render() {
7272
* class NestedClassComponent extends React.Component {

packages/core/src/component/component-render-prop.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
66

77
/**
88
* Unsafe check whether given node is a render function
9-
* ```jsx
9+
* ```tsx
1010
* const renderRow = () => <div />
1111
* ` ^^^^^^^^^^^^`
1212
* _ = <Component renderRow={() => <div />} />
@@ -39,7 +39,7 @@ export function isRenderFunctionLoose(context: RuleContext, node: AST.TSESTreeFu
3939

4040
/**
4141
* Unsafe check whether given JSXAttribute is a render prop
42-
* ```jsx
42+
* ```tsx
4343
* _ = <Component renderRow={() => <div />} />
4444
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
4545
* ```
@@ -59,7 +59,7 @@ export function isRenderPropLoose(context: RuleContext, node: TSESTree.JSXAttrib
5959

6060
/**
6161
* Unsafe check whether given node is declared directly inside a render property
62-
* ```jsx
62+
* ```tsx
6363
* const rows = { render: () => <div /> }
6464
* ` ^^^^^^^^^^^^^ `
6565
* _ = <Component rows={ [{ render: () => <div /> }] } />
@@ -80,7 +80,7 @@ export function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node) {
8080

8181
/**
8282
* Unsafe check whether given node is declared inside a render prop
83-
* ```jsx
83+
* ```tsx
8484
* _ = <Component renderRow={"node"} />
8585
* ` ^^^^^^ `
8686
* _ = <Component rows={ [{ render: "node" }] } />

packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-boolean.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,19 @@ A **safe** auto-fix is available for this rule.
2929
### Failing
3030

3131
```tsx
32-
import React from "react";
33-
34-
function MyComponent() {
35-
return <button disabled />;
36-
// ^^^^^^^^
37-
// - Avoid using shorthand syntax for 'disabled' attribute.
38-
}
32+
const Input = <input type="checkbox" checked />;
33+
// ^^^^^^^
34+
// - Expected `checked={true}` instead of `checked`
35+
const button = <button disabled />;
36+
// ^^^^^^^^
37+
// - Expected `disabled={true}` instead of `disabled`
3938
```
4039

4140
### Passing
4241

4342
```tsx
44-
import React from "react";
45-
46-
function MyComponent() {
47-
return <button disabled={true} />;
48-
}
43+
const Input = <input type="checkbox" checked={true} />;
44+
const button = <button disabled={true} />;
4945
```
5046

5147
## Implementation

packages/plugins/eslint-plugin-react-x/src/rules/avoid-shorthand-fragment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Enforces explicit `<Fragment>` components instead of the shorthand `<>` or `</>`
2525
```tsx
2626
import React from "react";
2727

28-
function MyComponent() {
28+
export function MyComponent() {
2929
return (
3030
<>
3131
<button />
@@ -40,7 +40,7 @@ function MyComponent() {
4040
```tsx
4141
import React, { Fragment } from "react";
4242

43-
function MyComponent() {
43+
export function MyComponent() {
4444
return (
4545
<Fragment>
4646
<button />

packages/plugins/eslint-plugin-react-x/src/rules/jsx-no-undef.md

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,21 @@ This rule is used to prevent the use of undefined variables in JSX. It checks fo
2222

2323
### Failing
2424

25-
```jsx
26-
const MyComponent = () => {
27-
return (
28-
<div>
29-
<Foo />
30-
</div>
31-
);
32-
};
25+
```tsx
26+
import React from "react";
27+
28+
const button = <MyButton />;
29+
// ^^^^^^^^
30+
// - 'MyButton' is not defined
3331
```
3432

3533
### Passing
3634

37-
```jsx
38-
import Foo from "./Foo";
39-
40-
const MyComponent = () => {
41-
return (
42-
<div>
43-
<Foo />
44-
</div>
45-
);
46-
};
47-
```
48-
49-
```jsx
50-
const Foo = () => <div>Foo</div>;
35+
```tsx
36+
import React from "react";
37+
import MyButton from "./MyButton";
5138

52-
const MyComponent = () => {
53-
return (
54-
<div>
55-
<Foo />
56-
</div>
57-
);
58-
};
39+
const button = <MyButton />;
5940
```
6041

6142
## Implementation

packages/plugins/eslint-plugin-react-x/src/rules/jsx-uses-vars.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ This rule only has an effect when the `no-unused-vars` rule is enabled.
3131
### Failing
3232

3333
```tsx
34-
const Hello = require("./Hello");
34+
import Hello from "./Hello";
3535
```
3636

3737
### Passing
3838

3939
```tsx
40-
const Hello = require("./Hello");
40+
import Hello from "./Hello";
4141

4242
<Hello name="John" />;
4343
```

0 commit comments

Comments
 (0)