Commit graph

3784 commits

Author SHA1 Message Date
Don Isaac
7b86ed61d1
fix(linter/unicorn): handle type casts and parens in no-null (#5175) 2024-08-24 18:18:52 -04:00
DonIsaac
7ab615220d refactor(linter/unicorn): clean up no-null (#5174) 2024-08-24 21:48:35 +00:00
DonIsaac
7886618e00 test(linter/unicorn): add fixer tests for no-null (#5173) 2024-08-24 21:48:34 +00:00
DonIsaac
b629e160db fix(linter/unicorn): improve diagnostic message for no-null (#5172)
This stack was made because of shortcomings I noticed while running `oxlint-eccosystem-ci` tests locally
2024-08-24 21:40:00 +00:00
camc314
dc9e1e233a fix(unicorn/linter) fix multiple false positives in no-useless-promise-resolve-reject (#5178)
more closely follows the implementation from unicorn's repo.

early returns if the parent is not a `return`, `yield`, or an arroy function

Closes #5125
Closes #5126
2024-08-24 21:03:31 +00:00
DonIsaac
d29042e7fc fix(linter/no-unused-vars): function expression in implicit arrow function return (#5155)
Fixes cases such as:
```ts
export const foo = () => function bar() {}
```
2024-08-24 15:49:56 +00:00
Cameron
147b37176b
fix(linter) fix bug in fixer for func names when function is async (#5167) 2024-08-24 11:30:56 -04:00
dalaoshu
1f5b6b6c82
fix(linter): bug in fixer for prefer-to-have-length (#5164) 2024-08-24 11:29:45 -04:00
Boshen
01c0c3e4b2 feat(transformer): add remaining options to transformer options (#5169)
closes #5168
2024-08-24 14:52:03 +00:00
Earl Chase
ba62a71975
fix(linter/react): Fixed false positive with missing key inside React.Children.toArray() for fragments (#5133)
Related: #4421 and #4945
2024-08-24 16:01:50 +08:00
Boshen
7b1546bb66
fix(codegen): do not print comments when --minify 2024-08-24 13:49:34 +08:00
Boshen
0410314278
chore(codegen): improve examples 2024-08-24 13:38:19 +08:00
DonIsaac
36e4a2875c fix(linter/no-unused-vars): panic in variable declarator usage checks (#5160)
Part of #5129
2024-08-24 04:49:30 +00:00
Dunqing
e3561127fe
chore(semantic): remove accidentally left comment (#5162) 2024-08-24 00:41:01 -04:00
Boshen
d5a494023e refactor(semantic): rewrite handling of label statement errors (#5138)
This reverts the previous changes to handling labels so that all tests can pass.

This passes all false postivies found in `monitor-oxc` (node_modules/flow-parser/flow_parser.js)

As it turns out this requires less code and produces better diagnostics.
2024-08-24 02:37:49 +00:00
overlookmotel
960e1d5c60 refactor(ast): rename IdentifierReference::new_with_reference_id (#5157)
The old name `new_read` no longer makes sense as it doesn't set a read-only flag any more, since `flags` field was removed from `IdentifierReference`.
2024-08-24 02:34:18 +00:00
Cameron
22d57f9e5e
feat(linter/unicorn): add fixer to prefer-string-slice (#5150) 2024-08-23 21:37:35 -04:00
camc314
34bfaf6792 feat(linter/react): add fixer to jsx-props-no-spread-multi (#5145) 2024-08-23 23:43:53 +00:00
overlookmotel
5136f011d9 refactor(transformer): remove unnecessary type annotation (#5131)
Remove unnecessary type annotation introduced in #4925.
2024-08-23 23:10:38 +00:00
overlookmotel
f63b568c48 refactor(ast): remove #[non_exhaustive] attr from AstBuilder (#5130)
Partially revert #4925. That PR's description gave no explanation of why this attribute is desirable.
2024-08-23 23:04:28 +00:00
Cameron
2fe44153ac
feat(linter/unicorn): add fixer to no-redundant-roles (#5146) 2024-08-23 17:38:24 -04:00
Cameron
d35c6f5dfc
feat(linter/unicorn): add fixer to prefer-regexp-test (#5151) 2024-08-23 17:34:06 -04:00
Cameron
27db769b8a
feat(linter/unicorn): add fixer to text-encoding-identifier-case (#5154) 2024-08-23 17:29:19 -04:00
Cameron
7eb052e0d4
fix(linter): no-hex-escape fixer removing regex flags (#5137)
closes #5127
2024-08-23 20:32:34 +01:00
DonIsaac
1ce9630c72 feat(linter/config): implement FromIterator for LintPluginOptions (#5102)
Part of #5046
2024-08-23 18:55:58 +00:00
DonIsaac
33599b0064 refactor(linter): split options into multiple files (#5101) 2024-08-23 18:55:57 +00:00
camc314
56a68f542d fix(linter) fix bug in fixer for func-name (#5136)
closes #5128
2024-08-23 18:46:04 +00:00
Boshen
7cc2bbd293
chore(semantic): print errors from examples/simple.rs 2024-08-23 22:57:26 +08:00
DonIsaac
b894d3b33e feat(linter)!: make no-unused-vars correctness (#5081)
closes #5080
2024-08-23 13:12:59 +00:00
Dunqing
47e69a8c94 fix(transformer-optional-catch-binding): the unused binding is not in the correct scope (#5066)
Blocked by #5008

In the SemanticBuilder, we insert all CatchClause parameters in the BlockStatement scope, a child-scope of CatchClause

858f510d59/crates/oxc_semantic/src/builder.rs (L709-L718)

So we should do the same thing in this plugin, but because CatchClause has no parameters, SemanticBuilder doesn't create scope for `CatchClause`. This cause we cannot find the `BlockStatement` scope_id.

This PR has changed to the correct logic. Just to wait #5008 solved
2024-08-23 13:02:53 +00:00
overlookmotel
eba5033a58 refactor(traverse): codegen ChildScopeCollector (#5119)
Codegen `ChildScopeCollector`, so that if more types have scopes added, we don't forget to add them (like the problem #5118 fixed).

The methods are in different order in the generated version, but otherwise identical to before this PR.

`visit_finally_clause` has to be added manually, as `oxc_traverse` codegen does not read or understand `#[visit(as)]` attrs.
2024-08-23 12:49:33 +00:00
overlookmotel
25d6e20bba fix(traverse): add missing visitors to ChildScopeCollector (#5118)
`ChildScopeCollector` was missing visitors for a few nodes which have recently had scopes added to them.
2024-08-23 12:49:33 +00:00
overlookmotel
f771d7c402 refactor(traverse): remove unnecessary imports (#5116)
`Atom`, `SourceType` and `Span` from `oxc_span`, and operators from `oxc_syntax` are now re-exported from `oxc_ast` crate. Remove unnecessary `use` statements by importing them all from `oxc_ast`.
2024-08-23 12:49:32 +00:00
overlookmotel
c6590aeee3 refactor(traverse): move generated files into separate folder (#5115)
Move generated files in `oxc_traverse` crate into separate folder, to match `ast_tools`.

Also amend the header on generated files to match files generated by `ast_tools`.
2024-08-23 12:49:31 +00:00
camc314
525d664aa9 fix(linter) false positive in jest/no-untyped-mock-factory (#5123)
part of https://github.com/oxc-project/oxc/issues/5103
2024-08-23 12:45:23 +00:00
camc314
b7ba9c01a1 fix(linter) fix bug in fixer for prefer-function-type when interface is exported (#5122)
part of https://github.com/oxc-project/oxc/issues/5103
2024-08-23 12:45:22 +00:00
Jelle van der Waa
f7958c4cc2
feat(linter/unicorn): add prefer-structured-clone (#5095) 2024-08-23 12:34:52 +01:00
Boshen
ff7fa987db fix(diagnostics): improve "file is too long to fit on the screen" (#5120)
closes #4322

Setting the threshold to 1200 because graphical output may contain ansi escape codes and other decorations.
2024-08-23 11:17:12 +00:00
Boshen
76c66b4326 fix(linter/max-lines): point span to end of file for disable directive to work (#5117)
closes #4101
2024-08-23 10:20:17 +00:00
overlookmotel
fc2e9adeff refactor(traverse): remove support for #[scope(if(...))] attr (#5114)
Closes #5008.

There are no longer any nodes with conditional scopes. Remove support for `#[scope(if(...))]` attr from `oxc_traverse` codegen - it's no longer needed.
2024-08-23 09:28:18 +00:00
overlookmotel
1ba11a34ab refactor(traverse): refactor ChildScopeCollector (#5112)
Refactor `ChildScopeCollector`. Now that all scopes are unconditional, can move shared logic into a common method.
2024-08-23 09:28:15 +00:00
overlookmotel
40e2f6e25c refactor(traverse): remove unnecessary branch in ChildScopeCollector (#5111)
Fix a mistake in `ChildScopeCollector`. `Class` always has a scope. No need to check whether it does.
2024-08-23 09:28:14 +00:00
overlookmotel
c100826b42 refactor(semantic)!: always create a scope for for statements (#5110)
Part of #5008. Make scopes for `ForStatement`, `ForInStatement` and `ForOfStatement` unconditional. i.e. always create a scope, even if there is no lexical binding (e.g. `for (i of a) {}`).
2024-08-23 09:28:13 +00:00
overlookmotel
d304d6f973 refactor(semantic)!: always create a scope for CatchClause (#5109)
Part of #5008. Make scope for `CatchClause` unconditional. i.e. always create a scope, even if there is no catch parameter.
2024-08-23 08:30:27 +00:00
Boshen
dd3ad4d68e
chore(regular_expression): remove circular dependency
Error: Circular dependency detected: oxc_parser -> oxc_regular_expression
2024-08-23 16:16:10 +08:00
Boshen
fc4eba5096
chore: publish oxc_regular_expression 2024-08-23 16:16:10 +08:00
overlookmotel
91343913ca fix(semantic): transform checker check unresolved references (#5096)
Transform checker check root unresolved references.

The transform checker is now checking pretty much everything it can.

Only fields of `ScopeTree` and `SymbolTable` that it's *not* checking are those which contain `AstNodeId`s, because transformer does not create node IDs at present:

* `ScopeTree::node_ids`
* `SymbolTable::declarations`
* `Reference::node_id`

Checking also only proceeds in "from AST" direction.

i.e. for each `SymbolId` which appears in the AST, we check everything about that symbol. But we *don't* go through all the "rows" in `SymbolTable` and check if there are any extra symbols in the table which aren't in the AST.

Presumably transformer will leave a lot of old symbols lying around in `SymbolTable` (ditto scopes and references). We'd need to add `ScopeFlags::Deleted`, `SymbolFlags::Deleted` and `ReferenceFlags::Deleted` for the transformer to be able to "delete" existing symbols.
2024-08-23 07:52:30 +00:00
overlookmotel
13c961c492 refactor(semantic): clean up transform checker (#5094)
Remove some defunct code and clean up a few bits in transform checker.
2024-08-23 08:37:48 +01:00
overlookmotel
c57e078c71 fix(semantic): transform checker check unbound references (#5093) 2024-08-23 08:37:48 +01:00
oxc-bot
0b900110a2
Release crates v0.25.0 (#5107)
## [0.25.0] - 2024-08-23

- 78f135d ast: [**BREAKING**] Remove `ReferenceFlag` from
`IdentifierReference` (#5077) (Boshen)

- f2b8d82 semantic: [**BREAKING**] `ScopeTree::get_child_ids` +
`get_child_ids_mut` return value not `Option` (#5058) (overlookmotel)

- 5f4c9ab semantic: [**BREAKING**] Rename `SymbolTable::get_flag` to
`get_flags` (#5030) (overlookmotel)

- 58bf215 semantic: [**BREAKING**] Rename `Reference::flag` and
`flag_mut` methods to plural (#5025) (overlookmotel)

- c4c08a7 ast: [**BREAKING**] Rename
`IdentifierReference::reference_flags` field (#5024) (overlookmotel)

- d262a58 syntax: [**BREAKING**] Rename `ReferenceFlag` to
`ReferenceFlags` (#5023) (overlookmotel)

- c30e2e9 semantic: [**BREAKING**] `Reference::flag` method return
`ReferenceFlag` (#5019) (overlookmotel)

- ce4d469 codegen: [**BREAKING**] Remove const generic `MINIFY` (#5001)
(Boshen)

- b2ff2df parser: [**BREAKING**] Remove builder pattern from `Parser`
struct (#5000) (Boshen)

- f88970b ast: [**BREAKING**] Change order of fields in CallExpression
(#4859) (Burlin)

### Features

- 714373d ast: `inherit_variants!` macro add `into_*` methods (#5005)
(overlookmotel)
- 6800e69 oxc: Add `Compiler` and `CompilerInterface` (#4954) (Boshen)
- 2b21be3 oxc_minifier: Define plugin with postfix wildcard (#4979)
(IWANABETHATGUY)
- afe728a parser: Parse regular expression with regex parser (#4998)
(Boshen)
- 4b49cf8 transformer: Always pass in symbols and scopes (#5087)
(Boshen)
- f51d3f9 transformer/nullish-coalescing-operator: Handles nullish
coalescing expression in the FormalParamter (#4975) (Dunqing)
- f794870 transformer/nullish-coalescing-operator: Generate the correct
binding name (#4974) (Dunqing)
- 72ff2c6 transformer/nullish-coalescing-operator: Add comments in top
of file (#4972) (Dunqing)
- 6b885fe traverse: Expose `generate_uid_based_on_node` and
`generate_uid_in_current_scope_based_on_node` from `TraverseCtx` (#4965)
(Dunqing)

### Bug Fixes

- 7f3129e ast: Correct code comment (#5004) (overlookmotel)
- 1bd9365 coverage: Correctly check semantic data after transform
(#5035) (Boshen)
- 185eb20 isolated_declarations: Namespaces that are default exported
should be considered for expando functions (#4935) (michaelm)
- 2a5e15d npm: `libc` field should not be `null` (Boshen)
- efbdced parser: Only show flow error if it's a flow file (#5069)
(Boshen)
- ad2be97 semantic: Incorrect semantic check for label has same name
(#5041) (heygsc)
- d5de97d semantic: Transform checker check reference flags (#5092)
(overlookmotel)
- 90c74ee semantic: Transform checker check reference symbol IDs (#5090)
(overlookmotel)
- a8005b9 semantic: Transform checker check symbol redeclarations
(#5089) (overlookmotel)
- 205bff7 semantic: Transform checker check symbol references (#5088)
(overlookmotel)
- 4a57086 semantic: Transform checker check symbol IDs (#5078)
(overlookmotel)
- ea7d216 semantic: Transform checker check symbol spans (#5076)
(overlookmotel)
- 1b6b27a semantic: Transform checker check symbol flags (#5074)
(overlookmotel)
- 6d87b0f semantic: Fix error message for duplicated label (#5071)
(Boshen)
- 05fff16 semantic: Transform checker compare binding symbol IDs (#5057)
(overlookmotel)
- f187b71 semantic: Transform checker compare scope children (#5056)
(overlookmotel)
- b52c6a4 semantic: Transform checker compare scope parents (#5055)
(overlookmotel)
- da64014 semantic: Transform checker catch more scope flags mismatches
(#5054) (overlookmotel)
- 67d1a96 semantic: Transform checker compare scope flags (#5052)
(overlookmotel)
- 863b9cb semantic: Transform checker handle conditional scopes (#5040)
(overlookmotel)
- 47029c4 semantic: Transform checker output symbol names in errors
(#5038) (overlookmotel)
- 6ffbd78 transformer: Remove an `AstBuilder::copy` call from TS
namespace transform (#4987) (overlookmotel)
- a8dfdda transformer: Remove an `AstBuilder::copy` call from TS module
transform (#4986) (overlookmotel)
- 1467eb3 transformer: Remove an `AstBuilder::copy` call from TS enum
transform (#4985) (overlookmotel)
- 1365feb transformer: Remove an `AstBuilder::copy` call for TS
`AssignmentTarget` transform (#4984) (overlookmotel)
- edacf93 transformer: Remove an `AstBuilder::copy` call (#4983)
(overlookmotel)
- 3b35332 transformer/logical-assignment-operators: Fix semantic errors
(#5047) (Dunqing)- b7db235 Comments gen regression (#5003)
(IWANABETHATGUY)

### Documentation

- 178d1bd transformer: Add documentation for exponentiation-operator
plugin (#5084) (Dunqing)
- d50eb72 transformer: Add documentation for `optional-catch-binding`
plugin (#5064) (Dunqing)
- 4425b17 transformer: Add documentation for
`logical-assignment-operators` plugin (#5012) (Dunqing)
- 1bd5853 transformer: Updated README re: order of methods (#4993)
(overlookmotel)

### Refactor

- a4247e9 allocator: Move `Box` and `Vec` into separate files (#5034)
(overlookmotel)
- cca7440 ast: Replace `AstBuilder::move_statement_vec` with `move_vec`
(#4988) (overlookmotel)
- 4012260 ast: `AstBuilder::move_identifier_reference` do not allocate
empty string (#4977) (overlookmotel)
- 96422b6 ast: Make AstBuilder non-exhaustive (#4925) (DonIsaac)
- ca70cc7 linter, mangler, parser, semantic, transformer, traverse,
wasm: Rename various `flag` vars to `flags` (#5028) (overlookmotel)
- 0f64d10 minifier: Remove duplicated helper `move_out_expression`
(#5007) (IWANABETHATGUY)
- cd9cf5e oxc: Remove `remove_whitespace` (Boshen)
- b4407c4 oxc,mangler: `oxc` crate add mangler; mangler use options API
(Boshen)
- 9da6a21 semantic: Rename transform checker output for reference symbol
mismatches (#5091) (overlookmotel)
- fb46eaf semantic: Add remap functions to transform checker (#5082)
(overlookmotel)
- a00bf18 semantic: Add `IdMapping` to transform checker (#5079)
(overlookmotel)
- b14a302 semantic: Transform checker: change symbol name mismatch error
(#5075) (overlookmotel)
- b8c6ce5 semantic: Rename vars in transform checker (#5072)
(overlookmotel)
- 7156fd2 semantic: Transform checker `Pair` structure (#5053)
(overlookmotel)
- 0ba6f50 semantic: Simplify raising errors in transform checker (#5051)
(overlookmotel)
- ee7ac8b semantic: Store all data in `PostTransformChecker` in
transform checker (#5050) (overlookmotel)
- 4e1f4ab semantic: Add `SemanticIds` to transformer checker (#5048)
(overlookmotel)
- c1da574 semantic: Add comments to transformer checker (#5045)
(overlookmotel)
- 8cded08 semantic: Rename error labels in transformer checker snapshots
(#5044) (overlookmotel)
- 602244f semantic: Rename vars in transformer checker (#5043)
(overlookmotel)
- ae94b9a semantic: Remove unused function params in transformer checker
(#5042) (overlookmotel)
- 586e15c semantic: Reformat transform checker errors (#5039)
(overlookmotel)
- d69e34e semantic: Fix indentation (#5037) (overlookmotel)
- 4336a32 semantic: Rename fields in snapshots from `flag` to `flags`
(#5032) (overlookmotel)
- 83dfb14 semantic: Rename vars from `flag` to `flags` (#5031)
(overlookmotel)
- 3b7de18 semantic: Rename `SemanticBuilder::current_reference_flags`
field (#5027) (overlookmotel)
- 0bacdd8 semantic: Rename `Reference::flag` field to `flags` (#5026)
(overlookmotel)
- 896b92f semantic: Correct typo in doc comment (#5009) (overlookmotel)
- d677b8e semantic: Do not reserve space in `resolved_references`
(#4962) (overlookmotel)
- a7ef30d semantic: `UnresolvedReferencesStack` contain only
`ReferenceId` (#4960) (overlookmotel)
- 59d15c7 semantic: `root_unresolved_references` contain only
`ReferenceId` (#4959) (overlookmotel)
- 7706523 span: Clarify `Atom` conversion methods lifetimes (#4978)
(overlookmotel)
- 4fdf26d transform_conformance: Add driver (#4969) (Boshen)
- 8d15e65 transformer: Use `into_member_expression` (#5006)
(overlookmotel)
- 4796ece transformer: TS annotations transform use `move_expression`
(#4982) (overlookmotel)
- a9fcf29 transformer/es2016: Move all entry points to implementation of
Traverse trait (#5085) (Dunqing)
- deda6ac transformer/es2019: Move all entry points to implementation of
Traverse trait (#5065) (Dunqing)
- 9df2f80 transformer/es2020: Move all entry points to implementation of
Traverse trait (#4973) (Dunqing)
- 3f9433c transformer/es2021: Move all entry points to implementation of
Traverse trait (#5013) (Dunqing)
- c60a50d transformer/exponentiation-operator: Use built-in
`ctx.clone_identifier_reference` (#5086) (Dunqing)
- bcc8da9 transformer/logical-assignment-operator: Use
`ctx.clone_identifier_reference` (#5014) (Dunqing)
- 38d4434 transformer/nullish-coalescing-operator: Move internal methods
to bottom of the file (#4996) (Dunqing)

### Testing

- 0df1a94 semantic: Add more symbol and reference checks to
`PostTransformChecker` (Boshen)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-23 15:37:36 +08:00