Commit graph

7114 commits

Author SHA1 Message Date
Boshen
15552ac499 feat(napi/transform): display semantic error (#6160) 2024-09-29 04:17:26 +00:00
Boshen
f27d59f748 fix(napi/transform): remove confusing jsx option (#6159) 2024-09-29 04:09:53 +00:00
DonIsaac
ea908f742d refactor(linter): consolidate file loading logic (#6130)
# Human Description
Low on time, so this one is short.
- consolidate source file and partial loader logic into `loader` module. I have more plans for this.
- ~LSP no longer uses `VALID_EXTENSIONS`, so now `.d.ts` files (and the like) will be linted as well~ LSP does not respect `.gitignore` files, so this change was reverted.

# AI Description
## Refactor Loader and Partial Loader

This PR refactors the loader and partial loader functionality in the oxc_linter crate:

* Introduce a new `Loader` struct with methods for checking if a file can be loaded and loading file contents
* Move `partial_loader` module to `loader/partial_loader`
* Rename `JavaScriptSource` to `source.rs` and move it to the `loader` module
* Update `JavaScriptSource` to use `u32` for `start` offset instead of `usize`
* Refactor `IsolatedLintHandler` to use the new `Loader`
* Update imports and module references throughout the codebase

This change improves the organization of the loader-related code and provides a more unified interface for loading different file types.
2024-09-29 02:48:01 +00:00
dalaoshu
183739ff47
feat(linter): implement prefer-await-to-callbacks (#6153) 2024-09-28 22:30:30 -04:00
Boshen
f50fdcd0f9 feat(napi/transform): make react refresh option take a boolean (#6146) 2024-09-28 14:52:46 +00:00
Dunqing
bfd19882b0 fix(transformer/react): should not collect use-hooks if it's a nested member expression (#6143)
close: #6139

I still remember this logic and I call `get_first_object` for it intentionally 🥲
2024-09-28 14:38:14 +00:00
DonIsaac
ab187d1e22 refactor(codegen): restrict visibility of internal methods (#6145)
add `pub(crate)` to `Codegen` methods that should only be used within `oxc_codegen`
2024-09-28 14:33:42 +00:00
camchenry
be0030cdb8 fix(linter): allow whitespace control characters in no-control-regex (#6140)
- fixes https://github.com/oxc-project/oxc/issues/6136

The original eslint rule checks if chars start with `\u` or `\x`, but our character spans are currently busted and only report 1 char for chars like `\u{0a}`. I've made whitespace an exception to the rule, so we don't report `\x0a` currently, which is fine for now I think
2024-09-28 12:45:27 +00:00
dalaoshu
14ba263506
docs(linter): improve docs for eslint-plugin-import rules (#6131)
Related to #6050
2024-09-28 20:45:02 +08:00
overlookmotel
375bebea06 refactor(transformer): improve parsing React pragmas (#6138)
If comment starts with `@jsxRuntime`, it can't also start with `@jsxImportSource` etc. So bail out earlier.
2024-09-28 10:29:12 +00:00
overlookmotel
0836f6b57b refactor(transformer): move parsing pragmas into TS transform (#6137)
It's more natural for this code to live in TS transform.
2024-09-28 10:29:11 +00:00
overlookmotel
30424fab58 refactor(transformer): TS transforms only store options they need (#6135)
All TS transforms only need a subset of the options in `TypeScriptOptions` - mostly just a single `bool`. Store these specific options in the transforms, not the whole `TypeScriptOptions` object.

This makes the transformer types smaller, and also checking the option is cheaper as it doesn't involve going through a double-reference.

e.g. Accessing `only_remove_type_imports` option with Rust's deref sugar made explicit:

Before: `*(&*self.options).only_remove_type_imports`
After: `*self.only_remove_type_imports`
2024-09-28 09:40:09 +00:00
oxc-bot
73098a43ff
release(crates): v0.30.4 (#6134)
## [0.30.4] - 2024-09-28

### Bug Fixes

- 8582ae3 codegen: Missing parentheses if there is a pure comment before
a NewExpression as a ComputedMemberExpression's callee (#6105) (Dunqing)
- fd6798f parser: Remove unintended `pub Kind` (#6109) (Boshen)
- 6f98aad sourcemap: Align sourcemap type with Rollup (#6133) (Boshen)
- 64d4756 transformer: Fix debug assertion in `Stack` (#6106)
(overlookmotel)

### Performance

- 05852a0 codegen: Do not check whether there are annotation comments or
not if we don't preserve annotation comments (#6107) (Dunqing)

### Documentation

- 26a273a oxc-transform: Update README (Boshen)
- e2c5baf transformer: Fix formatting of README (#6111) (overlookmotel)

### Refactor

- 2090fce semantic: Fix lint warning in nightly (#6110) (overlookmotel)
- 7bc3988 transformer: Remove dead code (#6124) (overlookmotel)
- 07fe45b transformer: Exponentiation operator: convert to match (#6123)
(overlookmotel)
- 4387845 transformer: Share `TypeScriptOptions` with ref not `Rc`
(#6121) (overlookmotel)
- 09e41c2 transformer: Share `TransformCtx` with ref not `Rc` (#6118)
(overlookmotel)
- 58fd6eb transformer: Pre-allocate more stack space (#6095)
(overlookmotel)
- 9ac80bd transformer: Add wrapper around `NonNull` (#6115)
(overlookmotel)
- c50500e transformer: Move common stack functionality into
`StackCommon` trait (#6114) (overlookmotel)
- 9839059 transformer: Simplify `StackCapacity` trait (#6113)
(overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-28 13:08:44 +08:00
Boshen
a5037719ab
chore(napi/minify): no publish 2024-09-28 12:52:46 +08:00
Boshen
6f98aadc7f fix(sourcemap): align sourcemap type with Rollup (#6133)
closes #5578
2024-09-28 04:24:05 +00:00
camchenry
db751f0f8f refactor(linter): use regexp AST visitor in no-control-regex (#6129)
- closes https://github.com/oxc-project/oxc/issues/5416

Rewrites the `no-control-regex` rule to use a regular expression AST visitor instead of the `regex` crate and parsing by hand. This change simplifies the code and makes it easier to maintain.

One notable change in the snapshots is the printing of the control characters. Previously, we always printed from the source text. Now, we print a representation of the control character itself based on its numeric value. This resulted in the nonprintable chars being printed, which are invisible. The other reason for this change is that the spans output by the regex parser for unicode escapes do not match 1:1 when raw strings and escapes are involved. This resulted in goofy looking spans in the output:

```
  ⚠ eslint(no-control-regex): Unexpected control character: '*\\x'
   ╭─[no_control_regex.tsx:1:22]
 1 │ new RegExp('\\u{1111}*\\x1F', 'u')
   ·                      ────
   ╰────
```

Not sure where the bug lies there yet.
2024-09-28 04:18:09 +00:00
camchenry
3aa7e42826 refactor(linter): use RegExp AST visitor for no-hex-escape (#6117)
Updates the `no-hex-escape` to use the new standard `Visit` trait for visiting the RegExp AST, replacing the handwritten implementation in this rule. This makes it much simpler to maintain.
2024-09-27 23:24:59 +00:00
DonIsaac
e7e8eada69 fix(linter): false positive in no-return-assign (#6128) 2024-09-27 21:16:50 +00:00
Radu Baston
ae539af675
feat(linter): implement no-return-assign (#6108)
This PR implements the not-recomennded eslint rule `no-return-assign`
https://github.com/oxc-project/oxc/issues/479

---------

Co-authored-by: Cameron <cameron.clark@hey.com>
2024-09-27 16:52:18 -04:00
overlookmotel
7bc39884ca refactor(transformer): remove dead code (#6124)
This line calls a method which is a no-op. Remove it.
2024-09-27 19:21:56 +00:00
overlookmotel
07fe45b416 refactor(transformer): exponentiation operator: convert to match (#6123)
In exponentiation operator transform, the first branch handling `**` was "falling through" to also run the 2nd branch which handles `**=`. The first branch replaces `**` with `Math.pow`, so it can never match on the 2nd branch.

Convert it to a `match` instead, so it only executes one branch or the other.
2024-09-27 19:21:55 +00:00
overlookmotel
43878451da refactor(transformer): share TypeScriptOptions with ref not Rc (#6121)
Similar to #6118.

Share `TypeScriptOptions` between transforms as a plain `&` reference, rather than an `Rc`, to reduce setup/teardown time.

The code to parse pragmas from comments is moved into `Transformer::new`. This isn't the ideal place for it, but it means `TypeScriptOptions` can be shared with the existing `'ctx` lifetime, rather than having to have a 3rd lifetime `TypeScript<'a, 'ctx, 'options>`.
2024-09-27 18:32:33 +00:00
overlookmotel
09e41c2c26 refactor(transformer): share TransformCtx with ref not Rc (#6118)
Many transforms share `TransformCtx`. Currently it's shared with `Rc`, which has a cost as the `Rc` has to be cloned many times, and it also makes dropping `Transformer` more expensive.

The PR changes that to share it as a normal reference `&TransformCtx` instead.

This requires adding an inner `TransformerImpl`. `Transformer` is now just a facade which creates the `TransformCtx` and stores options. `Transformer::build_with_symbols_and_scopes` constructs `TransformerImpl` and runs the visitor on it.

Unlikely to have any perf impact on larger files, but for small files where setup/teardown is a larger % of the overall workload, it may help a little.
2024-09-27 18:07:54 +00:00
overlookmotel
58fd6eb905 refactor(transformer): pre-allocate more stack space (#6095)
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
2024-09-27 16:48:38 +00:00
overlookmotel
9ac80bd2d2 refactor(transformer): add wrapper around NonNull (#6115)
Introduce a wrapper around `NonNull` which enables methods which exist on `std::ptr::NonNull` but are not yet stable in our MSRV. These methods remove a lot of boilerplate code from `Stack` and `NonEmptyStack` and make them easier to understand - which is important, since they contain so much unsafe code.
2024-09-27 16:48:37 +00:00
overlookmotel
c50500ec42 refactor(transformer): move common stack functionality into StackCommon trait (#6114)
`Stack` and `NonEmptyStack` contained a lot of the same logic. Move shared logic into a `StackCommon` trait that they both implement.

Also split out core allocation logic into non-generic free functions for faster compile time.
2024-09-27 16:48:36 +00:00
overlookmotel
98390594d2 refactor(transformer): simplify StackCapacity trait (#6113)
Pure refactor. Make it simpler.
2024-09-27 16:48:35 +00:00
Boshen
c519182359
feat(napi): add napi minifier (#6053) 2024-09-28 00:46:52 +08:00
Boshen
2da9a4d298
chore(regular_expression): rename visitor example to regex_visitor
closes #6116

To avoid name collision with parser/visitor.rs.
2024-09-28 00:33:11 +08:00
overlookmotel
509460b923
ci(transformer): run transformer tests under Miri (#6112)
Transformer tests include tests for unsafe code in `Stack` and
`NonEmptyStack`. Run these tests under Miri.
2024-09-27 17:27:28 +01:00
camchenry
9d5b44ad4c refactor(linter): use regex visitor in no-regex-spaces (#6063)
Similar to previous PRs, this refactors the `no-regex-spaces` rule to use the RegExp AST visitor, rather than the handwritten implementation in this rule. This makes the rule much simpler and easier to maintain in the future.
2024-09-27 15:58:54 +00:00
camchenry
0d44cf730a refactor(linter): use regex visitor in no-useless-escape (#6062)
This PR updates this rule to use the new RegExp AST visitor trait, instead of a custom implementation, which makes this rule much simpler and easier to maintain. The core logic is the same though, and the output should be identical.
2024-09-27 15:58:53 +00:00
camchenry
eeb8873982 refactor(linter): use regex visitor in no-empty-character-class (#6058)
Replaces rule-specific regex AST visitor method with the standard `oxc_regular_expression` one. This simplifies the code and also enables more capabilities (visiting more than just terms, but also character class contents, etc.)
2024-09-27 15:58:53 +00:00
overlookmotel
2090fce4bc refactor(semantic): fix lint warning in nightly (#6110)
Fix a lint warning which you only get on nightly (so appears when running Miri).
2024-09-27 13:45:16 +00:00
overlookmotel
e2c5baf868
docs(transformer): fix formatting of README (#6111) 2024-09-27 14:27:21 +01:00
Boshen
26a273a462
docs(oxc-transform): update README 2024-09-27 21:11:17 +08:00
Boshen
fd6798ffbc fix(parser): remove unintended pub Kind (#6109) 2024-09-27 12:44:40 +00:00
overlookmotel
64d4756af9 fix(transformer): fix debug assertion in Stack (#6106)
Fix incorrect debug assertion in `Stack`. The code itself was fine, but debug assertion was testing the wrong thing.

This error was spotted by @Boshen: https://github.com/oxc-project/oxc/pull/6095#pullrequestreview-2332830541

Also add more debug asserts and change test so it fails before the fix in this PR.
2024-09-27 11:24:09 +00:00
Dunqing
05852a04ed perf(codegen): do not check whether there are annotation comments or not if we don't preserve annotation comments (#6107) 2024-09-27 11:18:42 +00:00
Dunqing
8582ae3e91 fix(codegen): missing parentheses if there is a pure comment before a NewExpression as a ComputedMemberExpression's callee (#6105)
refer to 332727499e/internal/js_printer/js_printer.go (L2544)
2024-09-27 07:12:31 +00:00
oxc-bot
3ef248afbd
release(oxlint): v0.9.9 (#6101)
## [0.9.9] - 2024-09-27

### Bug Fixes

- bd8f786 linter: Rule and generic filters do not re-configure existing
rules (#6087) (DonIsaac)
- c5cdb4c linter: Disable all rules in a plugin when that plugin gets
turned off (#6086) (DonIsaac)
- 6c855af linter: Only write fix results if source code has changed
(#6096) (DonIsaac)
- 8759528 linter: Category filters not re-configuring already-enabled
rules (#6085) (DonIsaac)
- c2616f7 linter: Fix panic in fixer for `oxc/only-used-in-recursion`
(#6070) (camc314)
- 3da3845 linter: Malformed snippets in `eslint/for-direction` docs
(#6060) (DonIsaac)
- c047d42 linter: `no-useless-escape`: do not crash on backslash
character (#6048) (camchenry)
- 6f76ebe linter: Ignore invalid or partial disable directives (#6045)
(camchenry)
- 09a24cd linter: Fix false positives for generics in
`no-unexpected-multiline` (#6039) (camchenry)
- d05fd20 linter: Newline in type parameters causing false positive in
`no-unexpected-multiline` (#6031) (DonIsaac)
- 01b9c4b npm/oxlint: Make bin/oxc_language_server an executable (#6066)
(Boshen)

### Performance

- f8464a3 linter: `no-magic-numbers` remove redudant checks in
`is_array_index` (#6033) (Alexander S.)
- c16ae60 linter: `jest/prefer-hooks-in-order`: rewrite rule to allocate
less and iterate fewer times (#6030) (camchenry)

### Documentation

- a4fdf1b linter: Improve docs for promise rules (#6051) (dalaoshu)
- 21cdb78 linter: Fix incorrect "bad" example in
`only-used-in-recursion` (#6029) (Boshen)

### Refactor

- 1f92d61 linter: `jest/prefer-hooks-in-order`: improve diagnostic
messages (#6036) (camchenry)

### Testing

- 55949eb linter: Add `OxlintRules::override_rules` tests (#6081)
(DonIsaac)
- 1a6923a linter: Add filter parsing test cases (#6080) (DonIsaac)
- 58d333a linter: Add more test cases for disable directives (#6047)
(camchenry)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-27 14:41:55 +08:00
dalaoshu
d4bed9a800
docs(linter): improve docs for node/security/tree_shaking rules (#6097)
Related to #6050 

As of this PR, all documents of that contain a few rules have been
corrected.
2024-09-27 14:29:06 +08:00
oxc-bot
d56264ee9a
release(crates): v0.30.3 (#6104)
## [0.30.3] - 2024-09-27

### Bug Fixes

- a8338dd isolated-declarations: Accidentally collected references of
original ast (#6102) (Dunqing)
- 933a743 semantic: Add interfaces and functions to
`SymbolFlags::ClassExcludes` (#6057) (DonIsaac)

### Documentation

- 6167f29 oxc-transform: Modify the example code in the `Readme` file
(#6103) (loong.woo)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-27 14:23:48 +08:00
loong.woo
6167f29022
docs(oxc-transform): Modify the example code in the Readme file (#6103) 2024-09-27 14:12:30 +08:00
DonIsaac
933a7431b1 fix(semantic): add interfaces and functions to SymbolFlags::ClassExcludes (#6057)
This brings ClassExcludes into alignment with TypeScript.
2024-09-27 05:57:03 +00:00
Dunqing
93d509db2b chore(codegen): test function reports duplicate error information (#6067)
<img width="649" alt="image" src="https://github.com/user-attachments/assets/7789a7b4-56fb-40a2-a76d-52a55fe2bfad">
2024-09-27 05:51:31 +00:00
Don Isaac
b2760ec91c
chore(github): add linter bug report template (#6082)
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-09-27 13:50:35 +08:00
Dunqing
a8338ddfe3 fix(isolated-declarations): accidentally collected references of original ast (#6102) 2024-09-27 05:43:02 +00:00
oxc-bot
60d02a61f9
release(crates): v0.30.2 (#6100)
## [0.30.2] - 2024-09-27

### Features

- 60c52ba ast: Allow passing span to `void_0` method (#6065) (Dunqing)
- cca433f codegen: Print `vite` / `webpack` special comments (#6021)
(Dunqing)
- 8d026e1 regular_expression: Implement `GetSpan` for RegExp AST nodes
(#6056) (camchenry)
- 7764793 regular_expression: Implement visitor pattern trait for regex
AST (#6055) (camchenry)
- f866781 semantic: Check for type annotations on left side of `for..in`
and `for..of` iterators (#6043) (DonIsaac)
- 8b2e9aa semantic: Check for JSDoc types in TS type annotations (#6042)
(DonIsaac)
- 28da771 transformer: Do not transform `**` with bigint literals
(#6023) (Boshen)

### Bug Fixes

- a88504c diagnostics: Check for terminal when displaying links (#6018)
(Boshen)
- 418ae25 isolated-declarations: Report uninferrable types in arrays
(#6084) (michaelm)
- e0a8959 minifier: Compute `void number` as `undefined` (#6028)
(Boshen)
- 0658576 paresr: Do not report missing initializer error in ambient
context (#6020) (Boshen)
- b1af73d semantic: Do not create a `global` symbol for `declare global
{}` (#6040) (DonIsaac)
- c8682e9 semantic,codegen,transformer: Handle definite `!` operator in
variable declarator (#6019) (Boshen)

### Performance

- 6b7d3ed isolated-declarations: Should clone transformed AST rather
than original AST (#6078) (Dunqing)
- 85aff19 transformer: Introduce `Stack` (#6093) (overlookmotel)
- ad4ef31 transformer: Introduce `NonEmptyStack` (#6092) (overlookmotel)

### Documentation

- 3099709 allocator: Document `oxc_allocator` crate (#6037) (DonIsaac)
- d60ceb4 oxc: Add README.md and crate-level docs (#6035) (DonIsaac)
- efabfc8 semantic: Improve doc comments on `Reference` methods (#6076)
(overlookmotel)

### Refactor

- 1fc80d1 ast: Move all ts ast related impl methods to `ast_impl`
(#6015) (Dunqing)
- fe696f0 codegen: Simplify printing annotation comments (#6027)
(Dunqing)
- e60ce50 transformer: Add `SparseStack::with_capacity` method (#6094)
(overlookmotel)
- 1399d2c transformer: Move `SparseStack` definition into folder (#6091)
(overlookmotel)
- 6bd29dd transformer: Add more debug assertions (#6090) (overlookmotel)
- c90b9bf transformer: Rename `SparseStack` methods (#6089)
(overlookmotel)
- 2b380c8 transformer: Remove unsued `self.ctx` (#6022) (Boshen)

### Testing

- 93575cd semantic: Add comprehensive regression test suite (#5976)
(DonIsaac)
- a4cec75 transformer: Enable tests (#6032) (overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-27 13:28:12 +08:00
overlookmotel
e60ce506ea refactor(transformer): add SparseStack::with_capacity method (#6094)
Add `SparseStack::with_capacity` method.
2024-09-27 04:28:55 +00:00