Commit graph

3943 commits

Author SHA1 Message Date
camc314
b8464325e7 feat(linter/oxc): add fixer for erasing-op (#5377)
adds a fixer for `erasing-op` (replace the binary expression with `0`)
2024-09-03 00:46:55 +00:00
overlookmotel
2ccbd9361b refactor(linter): react/jsx_no_undef rule get_member_ident do not return Option (#5411)
Small tidy-up after #5358. `get_member_ident` now always returns a value, never `None`, so no need for it to return an `Option`.
2024-09-02 18:42:02 +00:00
Dunqing
1aa49af010 feat(ast)!: remove JSXMemberExpressionObject::Identifier variant (#5358)
close: #5353

`JSXMemberExpressionObject::Identifier` is dead code.
2024-09-02 18:35:39 +00:00
Dunqing
a72cc96482 chore(ast)!: remove get_object_identifier and get_object_identifier_mut (#5357)
These two methods are no longer needed
2024-09-02 18:26:05 +00:00
Dunqing
94ff94cd34 fix(transformer/arrow-functions): reaches unreachable when <this.foo> is inside an arrow function (#5356)
Fixes: https://github.com/oxc-project/oxc/issues/5353#issuecomment-2321792915
2024-09-02 18:06:08 +00:00
Boshen
01cc2ceac0 feat(semantic)!: add ScopeTree:get_child_ids API behind a runtime flag (#5403)
The runtime API for enabling `get_child_ids` is `SemanticBuilder::with_scope_tree_child_ids`.

I've tested this PR in Rolldown to ensure correctness.
2024-09-02 16:22:26 +00:00
oxc-bot
953344dd42
Release oxlint v0.9.2 (#5401)
## [0.9.2] - 2024-09-02

### Features

- f81e8a1 linter: Add `oxc/no-async-endpoint-handlers` (#5364)
(DonIsaac)
- b103737 linter: Improve no-accumulating-spread (#5302) (camc314)
- 9c22ce9 linter: Add hyperlinks to diagnostic messages (#5318)
(DonIsaac)
- 1967c67 linter/eslint: Implement no-new-func (#5360) (dalaoshu)
- b867e5f linter/eslint-plugin-promise: Implement catch-or-return
(#5121) (Jelle van der Waa)
- 8d781e7 linter/oxc: Differentiate between array/object in
`no-accumulating-spread` loop diagnostic (#5375) (camc314)
- db55444 linter/oxc: Add fixer for `double-comparisons` (#5378)
(camc314)
- e5c755a linter/promise: Add `spec-only` rule (#5124) (Jelle van der
Waa)
- 4c0861f linter/unicorn: Add fixer for `prefer-type-error` (#5311)
(camc314)
- 084c2d1 linter/vitest: Implement prefer-to-be-object (#5321)
(dalaoshu)

### Bug Fixes

- 11b93af linter/unicorn: Consistent-function-scoping false positive on
assignment expression (#5312) (Arian94)

### Performance

- f052a6d linter: `react/jsx_no_undef` faster check for unbound
references (#5349) (overlookmotel)
- 05636b7 linter: Avoid unnecessary work in `jsx_a11y/anchor_is_valid`
rule (#5341) (overlookmotel)

### Refactor

- afb038e linter: `react/jsx_no_undef` use loop instead of recursion
(#5347) (overlookmotel)
- fe62687 linter: Simplify skipping JSX elements in
`unicorn/consistent_function_scoping` (#5351) (overlookmotel)
- 381d9fe linter: Shorten code in `react/jsx_no_useless_fragment`
(#5350) (overlookmotel)
- 83b9a82 linter: Fix indentation in
`nextjs/no_script_component_in_head` rule (#5338) (overlookmotel)
- 89f0188 linter: Improve docs for `react/jsx_no_target_blank` rule
(#5342) (overlookmotel)
- 57050ab linter: Shorten code in
`jsx_a11y/aria_activedescendant_has_tabindex` rule (#5340)
(overlookmotel)
- ed31d67 linter/jest: Fix indentation in code comment (#5372) (camc314)
- 2499cb9 linter/oxc: Update rule docs for `erasing-op` (#5376)
(camc314)
- 69493d2 linter/oxc: Improve diagnostic for `no-accumulating-spread` in
loops (#5374) (camc314)
- 024b585 linter/oxc: Improve code comment for `no-accumulating-spread`
(#5373) (camc314)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-09-02 20:30:22 +08:00
dalaoshu
084c2d166c
feat(linter/vitest): implement prefer-to-be-object (#5321)
Related to #4656
2024-09-01 19:09:36 +08:00
Boshen
1b20ceb70c feat(span): add CompactStr::to_compact_string method (#5385)
For cases where we want to get the inner string and mutate it.
2024-09-01 10:49:39 +00:00
_lmmmmmm
3864eb42ce
chore: typo fix (#5380)
fixed #5379
Fix typos so `just ready` works
2024-09-01 15:10:40 +08:00
camc314
2499cb9785 refactor(linter/oxc): update rule docs for erasing-op (#5376)
updates the rule docs to align with the template:

a266b45167/tasks/rulegen/template.txt (L13)
2024-09-01 06:23:25 +00:00
camc314
8d781e7dff feat(linter/oxc): differentiate between array/object in no-accumulating-spread loop diagnostic (#5375)
when reporting diagnotics for code such as

```ts
let foo = {};
for (let i = 0; i < 10; i++) {
    foo = { ...foo, [i]: i };
}
```

we do not currently differentiate the diagnostic message between object/array.
this PR changes this to help the user fix ths issue
2024-08-31 20:52:05 +00:00
camc314
69493d2987 refactor(linter/oxc): improve diagnostic for no-accumulating-spread in loops (#5374)
when reporting diagnotics for code such as

```ts
let foo = {};
for (let i = 0; i < 10; i++) {
    foo = { ...foo, [i]: i };
}
```

we do not currently report **where** the accumulator is defined.
since this is constant for `Array.prototype.reduce`, it is not necessary.
however for loops, it makes sense to add this span to clearly show the user where the accumator is defined.
2024-08-31 20:52:05 +00:00
camc314
024b58506e refactor(linter/oxc): improve code comment for no-accumulating-spread (#5373)
mentioned here: https://github.com/oxc-project/oxc/pull/5302#discussion_r1735759462
it's not exactly clear why we check that it's a `let` declaration kind.
2024-08-31 20:52:04 +00:00
camc314
db554447aa feat(linter/oxc): add fixer for double-comparisons (#5378) 2024-08-31 20:48:59 +00:00
camc314
ed31d67b51 refactor(linter/jest): fix indentation in code comment (#5372)
previously, `test('...` was indented, making it look like it was inside a block statement/callback.

this PR corrects this by fixing the indentation
2024-08-31 18:56:25 +00:00
Arian94
11b93af0d1
fix(linter/unicorn): consistent-function-scoping false positive on assignment expression (#5312)
fixes #5159 and any other named function assigned to a property like:
```js
const foo = {};
foo.bar = function fooBar() {}
```

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-08-31 19:41:25 +01:00
DonIsaac
f81e8a126e feat(linter): add oxc/no-async-endpoint-handlers (#5364)
Adds `no-async-endpoint-handlers` rules, which bans async functions used as endpoint handlers in Express applications. These do not get caught by Express' error handler, causing the server to crash with an unhandled process rejection error.

```js
app.use(async (req, res) => {
  const foo = await api.getFoo(req.query) // server panics if this function rejects
  return res.json(foo)
})
```

I could not find this rule implemented in any ESLint plugin, but this is a problem I see quite often and I'm tired of dealing with it. I've added it to `oxc` for now, but we should consider adding an `express` or `api` plugin in the future.
2024-08-31 16:59:52 +00:00
Boshen
add146557c
feat(wasm): turn on all transform options 2024-09-01 00:24:10 +08:00
Jelle van der Waa
b867e5f16b
feat(linter/eslint-plugin-promise): implement catch-or-return (#5121)
Rule detail:

[link](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/catch-or-return.md)

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-31 17:04:06 +01:00
Jelle van der Waa
e5c755a7a6
feat(linter/promise): add spec-only rule (#5124)
Rule Detail:


[link](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/spec-only.md)

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-31 11:38:47 -04:00
dalaoshu
1967c6730b
feat(linter/eslint): implement no-new-func (#5360)
Related to #479

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-31 11:37:03 -04:00
Dunqing
35f03db464 fix(transformer): ArrowfunctionExpression's expression is true but has more than one body statement (#5366)
close: #5363

We insert the new statement here, but it's broken if it a `() => x;`, we need to transform it to `function () { return x }`

8d565d5b23/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs (L59-L76)

I don't where we should put the fallback logic, It's useful for all plugins. We had already done the same thing in the react refresh plugin.

8d565d5b23/crates/oxc_transformer/src/react/refresh.rs (L578-L605)
2024-08-31 14:49:58 +00:00
overlookmotel
c2d8c9e743 refactor(ast): reduce allocations in AstBuilder::move_assignment_target (#5367)
`AstBuilder::move_assignment_target` pass a static `Atom` instead of empty string to `AstBuilder::simple_assignment_target_identifier_reference`. This avoids a call to `alloc` to allocate an empty string in arena.
2024-08-31 08:34:26 +00:00
Boshen
8d565d5b23
chore(transformer): update examples to use the targets API 2024-08-31 14:08:37 +08:00
camc314
4c0861f694 feat(linter/unicorn): add fixer for prefer-type-error (#5311) 2024-08-31 05:17:47 +00:00
DonIsaac
180b1a17fb feat(ast): add Function::name() (#5361) 2024-08-31 03:45:45 +00:00
overlookmotel
afb038e93e refactor(linter): react/jsx_no_undef use loop instead of recursion (#5347) 2024-08-30 17:48:05 +00:00
Dunqing
be7b8c6845 test(semantic): add JSXIdentifierReference-related tests (#5224)
These tests demonstrate what kind of JSX will have references.
2024-08-30 17:43:34 +00:00
Dunqing
7e2a7afaa4 refactor(transformer/react): remove CalculateSignatureKey implementation from refresh (#5289)
follow-up: https://github.com/oxc-project/oxc/pull/4587#issue-2440174935

The `CalculateSignatureKey`is used to collect signature keys, but since it requires a double visit, it doesn't perform very well. Now I use ScopeId to store the signature key that is generated in `CallExpression`. This way we can then determine which ArrowFunction/Function the `CallExpression` belongs to.
2024-08-30 17:37:04 +00:00
overlookmotel
fe62687bf1 refactor(linter): simplify skipping JSX elements in unicorn/consistent_function_scoping (#5351)
Follow-on after #5223. We're trying to ignore JSX identifiers, so there's no point walking downwards from `JSXElementName`, as all we'll find is JSX identifiers that we want to ignore.
2024-08-30 15:11:50 +00:00
overlookmotel
381d9fe624 refactor(linter): shorten code in react/jsx_no_useless_fragment (#5350)
Shorten code. Also do the enum match first, as its cheaper than a string comparison.
2024-08-30 15:06:46 +00:00
overlookmotel
f052a6d666 perf(linter): react/jsx_no_undef faster check for unbound references (#5349)
Follow-on after #5223.

Now that we are getting an `IdentifierReference` with a `reference_id`, we can use that ID for a faster lookup of whether the reference is bound or not.
2024-08-30 14:56:55 +00:00
overlookmotel
d236554512 refactor(parser): move JSXIdentifier conversion code into parser (#5345)
Outside of the parser, a `JSXIdentifier` in a `JSXElementName::Identifier` will never be a identifier reference. So move the code for deciding if a `JSXElementName` is `JSXElementName::Identifier` or `JSXElementName::IdentifierReference`, and the code for converting from one to the other, into the parser - which is only place it should be used.
2024-08-30 14:47:09 +00:00
overlookmotel
292f217da8 perf(ast): optimize JSXIdentifier::is_reference (#5344) 2024-08-30 14:47:08 +00:00
overlookmotel
8a178075b7 fix(parser): treat JSX element tags starting with _ or $ as IdentifierReferences (#5343)
#5223 added a new variant `JSXElementName::IdentifierReference` for JSX identifiers which are treated as references (e.g. `<Foo>`) as opposed to `JSXElementName::Identifier` which is for lowercase (e.g. `<div>`).

But we were incorrectly categorizing identifiers beginning with `_` or `$` - these should also be treated as references.

(as discussed in https://github.com/oxc-project/oxc/pull/5339#issuecomment-2321037779)
2024-08-30 14:47:06 +00:00
overlookmotel
83b9a8240e
refactor(linter): fix indentation in nextjs/no_script_component_in_head rule (#5338) 2024-08-30 09:01:14 -04:00
overlookmotel
89f018889d
refactor(linter): improve docs for react/jsx_no_target_blank rule (#5342) 2024-08-30 09:00:43 -04:00
overlookmotel
05636b7725 perf(linter): avoid unnecessary work in jsx_a11y/anchor_is_valid rule (#5341)
Follow-on after #5223.

#5223 introduced the line `let span = jsx_el.opening_element.name.span();`. But the span is only needed when creating a diagnostic when the rule fails (cold path). Avoid the work of getting the span for the common case where the rule passes.
2024-08-30 12:52:39 +00:00
overlookmotel
57050ab16a refactor(linter): shorten code in jsx_a11y/aria_activedescendant_has_tabindex rule (#5340)
Shorten code which was introduced in #5223.
2024-08-30 12:17:09 +00:00
overlookmotel
0de844d23c refactor(transformer): remove unnecessary code from JSX transform (#5339)
Follow-on after #5223.

JSX identifiers which start with a capital letter are now `JSXElementName::IdentifierReference`s, so no need to check for capitalized `JSXElementName::Identifier`s.
2024-08-30 12:17:08 +00:00
Boshen
cbd9a60194
fix(wasm): do not run symbols and scopes for .d.ts files 2024-08-30 19:57:09 +08:00
Dunqing
32f730085c feat(ast)!: add JSXElementName::IdentifierReference and JSXMemberExpressionObject::IdentifierReference (#5223)
close: #3528

part of #4746
2024-08-30 11:11:04 +00:00
Boshen
8ab270b720
feat(wasm): add mangler 2024-08-30 18:45:56 +08:00
Dunqing
d04857bd35 feat(transformer): support Targets::from_query method (#5336) 2024-08-30 09:30:16 +00:00
Dunqing
3d4a64c811 feat(transformer): make Targets public (#5335) 2024-08-30 09:30:15 +00:00
Dunqing
8334bd4fa2 docs(transformer): add documentation for Targets::get_targets (#5337)
`Targets` will be public in follow-up PRs.
2024-08-30 09:30:14 +00:00
Boshen
3ae94b8801
refactor(semantic): change build_module_record to accept &Path instead of PathBuf 2024-08-30 12:24:49 +08:00
overlookmotel
946c867b27 refactor(ast): box TSThisParameter (#5325)
Box `TSThisParameter` in `Function`, `TSMethodSignature` and `TSFunctionType`. I assume `function(this: Whatever) {}` is a fairly rare syntax in TS code, and obviously never occurs in JS code, so it takes up a lot of space in `Function` for this uncommon case.

This change reduces `Function` from 136 bytes to 104.
2024-08-29 18:00:58 +00:00
Dunqing
0eb7602e18 feat(transformer): support TransformOptions::from_preset_env API (#5323) 2024-08-29 15:20:50 +00:00