Commit graph

3917 commits

Author SHA1 Message Date
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
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
overlookmotel
da8aa1873a improve(traverse)!: TraverseCtx::ancestors iterator do not yield Ancestor::None (#5295)
`TraverseCtx::ancestors` iterator would previously yield `Some(Ancestor::None)` before finally yielding `None`. Skip `Ancestor::None` as it's pointless.
2024-08-29 09:22:13 +00:00
overlookmotel
23e84564e7 fix(traverse)!: TraverseCtx::ancestor with level 0 = equivalent to parent (#5294)
Change meaning of `level` passed to `TraverseCtx` from "levels above current" to "levels above parent". `ctx.parent()`'s equivalent was `ctx.ancestor(1)`, now it's `ctx.ancestor(0)`.

This prevents out of bounds read on `ctx.ancestor(0)` (UB), which was made possible by #5286.
2024-08-29 08:52:04 +00:00
overlookmotel
6e969f9fa4 feat(semantic): add ScopeTree::delete_root_unresolved_reference (#5305)
Add an API to `ScopeTree` to delete an unresolved reference.
2024-08-29 08:39:09 +00:00
Dunqing
d2666fe039 refactor(transformer/object-rest-spread): move plugin-relates files to object_rest_spread mod (#5320)
Both `object_spread` and `object_rest` belong to `object_rest_object`, so moving them to the plugin mod makes the file structure clearer
2024-08-29 07:35:09 +00:00
Dunqing
164511549f refactor(transformer/object-reset-spread): make plugin initialization unconditional (#5319)
Align with other plugins
2024-08-29 07:35:08 +00:00
DonIsaac
9c22ce9c99 feat(linter): add hyperlinks to diagnostic messages (#5318)
Adds hyperlinks to diagnostic codes.

Diagnostics without codes will not have links. In practice, this means linter diagnostics have links, while semantic and parser diagnostics do not.

![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/OVwvhVoSj4tgQWTUipoY/11790a3a-7dfa-4c6d-be43-550d8b6370a9.png)

> notice the underline under the error code
2024-08-29 05:50:04 +00:00
DonIsaac
cd63336c7e refactor(diagnostic): change how diagnostic codes are rendered (#5317)
Preparation for upstack PRs. Graphical reporter diagnostics look exactly the same. This does, however, change `to_string()` to only show diagnostic messages, and not error codes + messages.
2024-08-29 05:50:03 +00:00
oxc-bot
53ff3493ef
Release oxlint v0.9.1 (#5316)
## [0.9.1] - 2024-08-29

### Features

- 6633972 linter: Add fixer for `no-empty` (#5276) (camc314)
- a58e448 linter/eslint: Add fixer to `no-var` (#5144) (camc314)
- a6e9769 linter/jsx-a11y: Add `label-has-associated-control` (#5163)
(Billy Levin)
- c8e8532 linter/unicorn: Add fixer to `throw-new-error` (#5275)
(camc314)
- 7ccde4b linter/unicorn: Add fixer to `prefer-date-now` (#5147)
(camc314)

### Bug Fixes

- 76e86f8 linter: Eslint-plugin-unicorn prefer-spread wrong linter
suggestion on variables of type string (#5265) (Arian94)
- b39544e linter/jest: Fixer for `prefer-jest-mocked` creates invalid
LHS expressions (#5243) (camc314)
- 9953fa5 linter/no-null: Incorrect fixer for `NullLiteral` within
`ReturnStatement` (#5247) (Dunqing)
- 318479e linter/no-unused-vars: Mark the class/function in the new
expression as used (#5306) (magic-akari)

### Refactor

- fa1d460 linter: Clean up Fixer and Message (#5308) (DonIsaac)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-29 13:04:52 +08:00
cinchen
fdef8aec72
fix(linter): jest/vitest rule compat (#4797)
This pr is for jest/vitest compat and add another jest rule condition

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
Co-authored-by: Wang Wenzhe <mysteryven@gmail.com>
2024-08-29 11:04:00 +08:00
camc314
bb995f6361 feat(jsx-a11y/linter) add fixer for scope (#5310) 2024-08-29 00:51:00 +00:00
camc314
e5ead86d43 feat(linter) catch more cases for misrefactored-assign-op (#5309)
changes from using `without_parenthesis` to using `get_inner_expression` to ignore type casts, non null assertions ect.

this helps catch more error cases
2024-08-29 00:47:38 +00:00
Dunqing
3acb3f6461 fix(transformer/react): mismatch output caused by incorrect transformation ordering (#5255)
close: #4767
2024-08-29 00:38:02 +00:00
DonIsaac
fa1d460852 refactor(linter): clean up Fixer and Message (#5308)
- refactor(linter): clean up Fixer and Message
- perf(linter): replace sort_by_key with sort_unstable_by_key in fixer
2024-08-28 23:19:46 +00:00
magic-akari
318479ec4d
fix(linter/no-unused-vars): mark the class/function in the new expression as used (#5306)
Fix: #5274
2024-08-28 13:38:16 -04:00
magic-akari
08dc0adeab feat(transformer): add object-spread plugin (#3133) 2024-08-28 15:57:20 +00:00
Boshen
5c4c00123d fix(codegen): print export @decorator declare abstract class Foo correctly (#5303) 2024-08-28 15:30:39 +00:00
camc314
6633972663 feat(linter): add fixer for no-empty (#5276)
adds a suggestion for `no-empty` eslint lint rule
2024-08-28 15:06:29 +00:00
Boshen
7fa2fa386c
refactor(wasm): clean up code and add transform (#5299)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-28 22:14:35 +08:00
Boshen
8d6b05ca01 fix(transformer): class property with typescript value should not be removed (#5298) 2024-08-28 13:53:41 +00:00
Boshen
70091771b6
test(parser): fix incorrect flow error test 2024-08-28 20:53:32 +08:00
Boshen
fb75d2576b
Revert "fix(parser): Revert "check for @flow with recoverable errors as well" (#5297)"
This reverts commit d4c06ef093.
2024-08-28 20:53:13 +08:00
overlookmotel
d4c06ef093 fix(parser): Revert "check for @flow with recoverable errors as well" (#5297)
e1d8b92080 caused CI to fail. Revert it.
2024-08-28 12:48:37 +00:00
Boshen
e1d8b92080
fix(parser): check for @flow with recoverable errors as well 2024-08-28 19:39:07 +08:00
Boshen
5e27798dc3
chore(parser): parse regular expression in example 2024-08-28 19:32:44 +08:00
overlookmotel
b43a3948a1 refactor(traverse): correct code comments (#5293)
#5286 changed `TraverseCtx::ancestor` to always return an `Ancestor`. Update doc comments to reflect that.
2024-08-28 10:10:04 +00:00