Commit graph

5236 commits

Author SHA1 Message Date
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
Boshen
29f8497001
ci: autofix formatting relates jobs (#5383)
closes #5382

Autofixes toml, rust and unused dependencies.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-01 16:19:53 +08:00
renovate[bot]
23ae0fa335
chore(deps): update crate-ci/typos action to v1.24.3 (#5384)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [crate-ci/typos](https://togithub.com/crate-ci/typos) | action | patch
| `v1.24.1` -> `v1.24.3` |

---

### Release Notes

<details>
<summary>crate-ci/typos (crate-ci/typos)</summary>

###
[`v1.24.3`](https://togithub.com/crate-ci/typos/releases/tag/v1.24.3)

[Compare
Source](https://togithub.com/crate-ci/typos/compare/v1.24.2...v1.24.3)

#### \[1.24.3] - 2024-08-30

##### Fixes

- Updated the dictionary with the [August
2024](https://togithub.com/crate-ci/typos/issues/1069) changes

###
[`v1.24.2`](https://togithub.com/crate-ci/typos/releases/tag/v1.24.2)

[Compare
Source](https://togithub.com/crate-ci/typos/compare/v1.24.1...v1.24.2)

#### \[1.24.2] - 2024-08-30

##### Performance

- Cap unbounded parsing to avoid worst case performance (hit with test
data)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/oxc-project/oxc).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC41Ni4wIiwidXBkYXRlZEluVmVyIjoiMzguNTYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-01 07:49:57 +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
Boshen
e75e0f1465 chore: update test262 / babel / typescript submodules (#5369)
closes #5215
2024-08-31 12:28:25 +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
1d9fd1fdcc
ci: add action-semantic-pull-request
closes #5348
2024-08-31 16:02:30 +08: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
Boshen
295ad89b7e
Update FUNDING.yml 2024-08-31 13:10:59 +08: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
783a31beb6 ci(benchmark/transformer): enable all > es6 plugins (#5324)
There is a bug in the react refresh plugin, I will fix it in follow-up PR and enable the plugin in the benchmark
2024-08-30 09:30:17 +00: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
camc314
b1037372b7 feat(linter): improve no-accumulating-spread (#5302)
VSCode has a couple violations. examples:

```
  x oxc(no-accumulating-spread): Do not spread accumulators in loops
    ,-[src/vs/workbench/services/textMate/common/TMGrammarFactory.ts:65:5]
 64 |                 let injections: string[] = [];
 65 |                 for (let i = 1; i <= scopeParts.length; i++) {
    :                 ^|^
    :                  `-- For this loop
 66 |                     const subScopeName = scopeParts.slice(0, i).join('.');
 67 |                     injections = [...injections, ...(this._injections[subScopeName] || [])];
    :                                   ^^^^^^|^^^^^^
    :                                         `-- From this spread
 68 |                 }
    `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/base/common/actions.ts:205:3]
 204 |         let out: IAction[] = [];
 205 |         for (const list of actionLists) {
     :         ^|^
     :          `-- For this loop
 206 |             if (!list.length) {
 207 |                 // skip
 208 |             } else if (out.length) {
 209 |                 out = [...out, new Separator(), ...list];
     :                        ^^^|^^
     :                           `-- From this spread
 210 |             } else {
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  help: It looks like you're spreading an `Array`. Consider using the `Array.push` or `Array.concat` methods to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/workbench/contrib/extensions/browser/extensionsActions.ts:302:3]
 301 |         let actions: IAction[] = [];
 302 |         for (const visibleActions of actionsGroups) {
     :         ^|^
     :          `-- For this loop
 303 |             if (visibleActions.length) {
 304 |                 actions = [...actions, ...visibleActions, new Separator()];
     :                            ^^^^^|^^^^
     :                                 `-- From this spread
 305 |             }
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
      ,-[src/vs/workbench/contrib/extensions/browser/extensionsActions.ts:1141:3]
 1140 |         let actions: IAction[] = [];
 1141 |         for (const menuActions of menuActionGroups) {
      :         ^|^
      :          `-- For this loop
 1142 |             actions = [...actions, ...menuActions, new Separator()];
      :                        ^^^^^|^^^^
      :                             `-- From this spread
 1143 |         }
      `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/workbench/contrib/extensions/browser/extensionsViews.ts:334:4]
 333 |             let actions: IAction[] = [];
 334 |             for (const menuActions of groups) {
     :             ^|^
     :              `-- For this loop
 335 |                 actions = [...actions, ...menuActions, new Separator()];
     :                            ^^^^^|^^^^
     :                                 `-- From this spread
 336 |             }
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

```
2024-08-29 14:17:44 +00:00