Skip to content

Commit

Permalink
Merge branch 'main' into fix/typo-no-double-equals
Browse files Browse the repository at this point in the history
  • Loading branch information
togami2864 committed Mar 9, 2024
2 parents b145d29 + 71e10ed commit bb8df1e
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ impl Rule for UseShorthandFunctionType {
node,
)?),
)
.build();
.build()
.with_type_parameters(interface_decl.type_parameters());

mutation.replace_node(
AnyJsDeclarationClause::from(interface_decl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ fn handle_iterators(
let body = callback.body().ok()?;
match body {
AnyJsFunctionBody::AnyJsExpression(expr) => {
handle_potential_react_component(&expr, model, is_inside_jsx)
// unwrap parenthesized expression
let mut inner_expr = expr;
while let AnyJsExpression::JsParenthesizedExpression(parenthesized_expr) =
inner_expr
{
inner_expr = parenthesized_expr.expression().ok()?;
}
handle_potential_react_component(&inner_expr, model, is_inside_jsx)
.map(|state| vec![state])
}
AnyJsFunctionBody::JsFunctionBody(body) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ React.Children.map(c => React.cloneElement(c));
(<h1>{data.map(c => <h1></h1>)}</h1>)

(<h1>{data.map(c => xyz)}</h1>)

(<h1>{data.map(c => (<h1></h1>))}</h1>)
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ React.Children.map(c => React.cloneElement(c));

(<h1>{data.map(c => xyz)}</h1>)

(<h1>{data.map(c => (<h1></h1>))}</h1>)
```

# Diagnostics
Expand Down Expand Up @@ -586,10 +587,28 @@ invalid.jsx:37:21 lint/nursery/useJsxKeyInIterable ━━━━━━━━━
> 37 │ (<h1>{data.map(c => xyz)}</h1>)
│ ^^^
38 │
39 │ (<h1>{data.map(c => (<h1></h1>))}</h1>)
i Either return a JSX expression, or suppress this instance if you determine it is safe.
i Check the React documentation for why a key prop is required.
```

```
invalid.jsx:39:22 lint/nursery/useJsxKeyInIterable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Missing key property for this element in iterable.
37 │ (<h1>{data.map(c => xyz)}</h1>)
38 │
> 39 │ (<h1>{data.map(c => (<h1></h1>))}</h1>)
│ ^^^^
i The order of the items may change, and having a key can help React identify which item was moved.
i Check the React documentation.
```
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ React.Children.map(c => React.cloneElement(c, {key: c}));
(<h1>{[<h1 key={1}></h1>, <h1 key={2}></h1>, <h1 key={3}></h1>]}</h1>)

(<h1>{data.map(c => <h1 key={c}></h1>)}</h1>)

(<h1>{data.map(c => (<h1 key={c}></h1>))}</h1>)
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ React.Children.map(c => React.cloneElement(c, {key: c}));

(<h1>{data.map(c => <h1 key={c}></h1>)}</h1>)

(<h1>{data.map(c => (<h1 key={c}></h1>))}</h1>)
```
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ type GenericCallSignature<T> = { (arg: T): T };

// Object type with optional call signature
let optionalCall: { (): number | undefined };

// Generic interface with a call signature
interface GenericInterface<T> {
(value: T): boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type GenericCallSignature<T> = { (arg: T): T };
// Object type with optional call signature
let optionalCall: { (): number | undefined };

// Generic interface with a call signature
interface GenericInterface<T> {
(value: T): boolean;
}

```

# Diagnostics
Expand Down Expand Up @@ -229,6 +234,7 @@ invalid.ts:33:21 lint/style/useShorthandFunctionType FIXABLE ━━━━━
> 33 │ let optionalCall: { (): number | undefined };
│ ^^^^^^^^^^^^^^^^^^^^^^
34 │
35 │ // Generic interface with a call signature
i Types containing only a call signature can be shortened to a function type.
Expand All @@ -239,8 +245,34 @@ invalid.ts:33:21 lint/style/useShorthandFunctionType FIXABLE ━━━━━
33 │ - let·optionalCall:·{·():·number·|·undefined·};
33 │ + let·optionalCall:·()·=>·number·|·undefined;
34 34 │
35 35 │ // Generic interface with a call signature
```

```
invalid.ts:37:2 lint/style/useShorthandFunctionType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Use a function type instead of a call signature.
35 │ // Generic interface with a call signature
36 │ interface GenericInterface<T> {
> 37 │ (value: T): boolean;
│ ^^^^^^^^^^^^^^^^^^^^
38 │ }
39 │
i Types containing only a call signature can be shortened to a function type.
i Safe fix: Alias a function type instead of using an interface with a call signature.
34 34 │
35 35 │ // Generic interface with a call signature
36 │ - interface·GenericInterface<T>·{
37 │ - → (value:·T):·boolean;
38 │ - }
36 │ + type·GenericInterface<T>·=·(value:·T)·=>·boolean
39 37 │
```
Binary file modified website/src/assets/vscode-extension.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bb8df1e

Please sign in to comment.