Commit graph

6092 commits

Author SHA1 Message Date
DonIsaac
5ee1ef3d92 feat(allocator): add Vec::into_boxed_slice (#6195)
Note that this PR does not implement the inverse operation (`Box::to_vec` for `[T]`).
2024-10-12 04:29:43 +00:00
Alexander S.
7240ee23fc
refactor(linter): make advertised fix kinds consistent (#6461) 2024-10-11 19:25:32 -04:00
overlookmotel
b48c3683d6 refactor(linter): no_global_assign rule: reduce name lookups (#6460)
2 small optimizations to this lint rule:

1. Get the name for the symbol only once, rather than on each turn of the inner loop (every reference to a symbol has the same name by definition).
2. Avoid creating temporary `CompactStr`s, which causes an allocation if the string is longer than 24 bytes.
2024-10-11 20:53:35 +00:00
Boshen
7645e5c34b refactor(codegen)!: remove CommentOptions API (#6451) 2024-10-11 13:53:28 +00:00
7086cmd
3677ef81e9 feat(minifier): dce ExpressionStatements with no side effect (#6457)
Not sure about the performance. Just have a try.
2024-10-11 13:40:44 +00:00
dalaoshu
e81181261d
fix(linter): error diagnostic message based on parameter length of valid-expect (#6455) 2024-10-11 09:16:17 -04:00
overlookmotel
073b02af14 refactor(ast): type params field before params in TS function declaration types (#6391)
Our convention is that AST type fields are ordered in order they appear in source. Move `type_parameters` fields in TS function declaration types to before `this_param` and formal parameters.
2024-10-11 09:57:28 +00:00
7086cmd
06ea1216af feat(minifier): fold for statement (#6450) 2024-10-11 08:33:23 +00:00
overlookmotel
85d93ed713 fix(transformer): arrow function transform: correctly resolve this in class accessor properties (#6386)
Correctly resolve scope of `this` in class accessor properties.

The omission of this case became clear from examining Babel's `environmentVisitor`:

f343c499b0/packages/babel-traverse/src/visitors.ts (L398-L436)
2024-10-11 07:09:56 +00:00
Boshen
cb8f4210c3 refactor(prettier)!: remove source_text argument from constructor (#6448) 2024-10-11 06:27:33 +00:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen
2808973af3 feat(ast)!: add Program::comments (#6445) 2024-10-11 04:47:36 +00:00
Boshen
2b7be08af4 feat(ast)! add source_text to Program (#6444) 2024-10-11 04:13:41 +00:00
Boshen
4d8bc8c8af perf(parser): precompute is_typescript (#6443) 2024-10-11 03:39:38 +00:00
Boshen
b1bf12c336 fix(parser): do not parse as and satisfies expression in javascript (#6442)
closes #6427
2024-10-11 03:31:24 +00:00
Boshen
46a38c63ff refactor(minifier): remove allow clippy::unused_self (#6441) 2024-10-11 02:54:25 +00:00
DonIsaac
2566ce787d refactor(linter): remove OxlintOptions (#6098)
Removed in favor of LinterBuilder
2024-10-11 02:30:26 +00:00
DonIsaac
002078afe3 refactor(linter): make Runtime's members private (#6440)
Protecting `Runtime`'s API in preparation of multli-config support.
2024-10-11 02:11:28 +00:00
DonIsaac
c00f669435 perf(linter): use NonZeroUsize for pending module cache entries (#6439)
Using `NonZeroUsize` lets `rustc` detect a niche value, shrinking the size of `CacheStateEntry` from 16 bytes to 8. It has the added benefit of making `CacheStateEntry::PendingStore`'s purpose clearer.
2024-10-11 02:11:28 +00:00
DonIsaac
6a0a5337e1 refactor(linter): move module cache logic out of Runtime (#6438)
Pure refactor. Makes `Runtime` easier to reason about.
2024-10-11 02:11:27 +00:00
DonIsaac
c18c6e9db1 refactor(linter): split service code into separate modules (#6437)
Refactor in preparation of multi-config/`override` support.
2024-10-11 02:11:27 +00:00
Dunqing
702b574afb refactor(codegen): only print necessary parentheses in TSAsExpression (#6429)
Part of fixing #6385
2024-10-11 02:04:27 +00:00
Don Isaac
7458089e3c
chore: add dev container config (#6433)
This will make it easier to review PRs in github codespaces.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-11 10:04:09 +08:00
DonIsaac
80266d85c9 feat(linter)!: support plugins in oxlint config files (#6088)
> Closes #5046
This PR migrates the linter crate and oxlint app to use the new `LinterBuilder` API. This PR has the following effects:

1. `plugins` in oxlint config files are now supported
2. irons out weirdness when using CLI args and config files together. CLI args are now always applied on top of config file settings, overriding them.

# Breaking Changes
Before, config files would override rules set in CLI arguments. For example, running this command:
```sh
oxlint -A correctness -c oxlintrc.json
```
With this config file
```jsonc
// oxlintrc.json
{
  "rules": {
    "no-const-assign": "error"
  }
}
```
Would result in a single rule, `no-const-assign` being turned on at an error level with all other rules disabled (i.e. set to "allow").

Now, **CLI arguments will override config files**. That same command with the same config file will result with **all rules being disabled**.

## Details

For a more in-depth explanation, assume we are running the below command using the `oxlintrc.json` file above:
```sh
oxlint -A all -W correctness -A all -W suspicious -c oxlintrc.json
```

### Before
> Note: GitHub doesn't seem to like deeply nested lists. Apologies for the formatting.

Here was the config resolution process _before_ this PR:
<details><summary>Before Steps</summary>

1. Start with a default set of filters (["correctness", "warn"]) if no filters were passed to the CLI. Since some were, the filter list starts out empty.
2. Apply each filter taken from the CLI from left to right. When a filter allows a rule or category, it clears the configured set of rules. So applying those filters looks like this
  a. start with an empty list `[]`
  b. `("all", "allow")` -> `[]`
  c. `("correctness", "warn")` -> `[ <correctness rules> ]`
  d. `("all", "allow")` -> `[]`
  e. `("suspicious", "warn")` -> `[ <suspicious rules> ]`. This is the final rule set for this step
3. Apply overrides from `oxlintrc.json`. This is where things get a little funky, as mentioned in point 2 of what this PR does. At this point, all rules in the rules list are only from the CLI.
  a. If a rule is only set in the CLI and is not present in the config file, there's no effect
  b. If a rule is in the config file but not the CLI, it gets inserted into the list.
  c. If a rule is already in the list and in the config file
    i. If the rule is only present once (e.g. `"no-loss-of-precision": "error"`), unconditionally override whatever was in the CLI with what was set in the config file
    ii. If the rule is present twice (e.g. `"no-loss-of-precision": "off", "@typescript-eslint/no-loss-of-precision": "error"`),
      a. if all rules in the config file are set to `allow`, then turn the rule off
      b. If one of them is `warn` or `deny`, then update the currently-set rule's config object, but _leave its severity alone_.

  So, for our example, the final rule set would be `[<all suspicious rules: "warn">, no-const-assign: "error"]`

</details>

### After
Rule filters were completely re-worked in a previous PR. Now, lint filters aren't kept on hand-only the rule list is.

<details><summary>After Steps</summary>

1. Start with the default rule set, which is all correctness rules for all enabled plugins (`[<all correctness rules: "warn">]`)
2. Apply configuration from `oxlintrc.json` _first_.
  a. If the rule is warn/deny exists in the list already, update its severity and config object. If it's not in the list, add it.
  b. If the rule is set to allow, remove it from the list.

  The list is now `[<all correctness rules except no-const-assign: "warn">, no-const-assign: "error"]`.

3. Apply each filter taken from the CLI from left to right. This works the same way as before. So, after they're applied, the list is now `[<suspicous rules: "warn">]`

</details>
2024-10-10 19:21:50 +00:00
Radu Baston
454874a42d
feat(linter): Implement react/iframe-missing-sandbox (#6383)
https://github.com/oxc-project/oxc/issues/1022

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-10-10 15:17:29 -04:00
camc314
a9544ae3eb feat(minifier): partially implement minification for some known string methods (#6424)
- implements minification for `toLowerCase`, `toUpperCase` and `trim`
2024-10-10 15:23:03 +00:00
Boshen
6a194f9086 docs(span): document validity of ModuleKind::Unambiguous (#6423)
relates #6249
2024-10-10 14:59:41 +00:00
leaysgur
b5b0af98cb feat(regular_expression): Support RegExp Modifiers (#6410)
Fixes #6354
2024-10-10 14:46:17 +00:00
camc314
9dc4ee9c98 feat(minifier): implement block stmt support for StatementFusion (#6422) 2024-10-10 14:41:04 +00:00
dalaoshu
f70e93b2f5
refactor(oxc): ban index methods on std::str::Chars (#6075)
closes #6071
2024-10-10 21:35:24 +08:00
7086cmd
c5deb3235e test(minifier): port the rest of tests (#6420) 2024-10-10 12:28:00 +00:00
dalaoshu
e59da61755
test(minifier): add all test cases for collapse_variable_declarations (#6421)
closes #6227

I noticed that the implementation of `collapse-variable-declarations`
seems incomplete and appears quite simple. Therefore, I would like to
quickly add all the test cases to work on this.

Previously, I saw that `DonIsaac` had also submitted a related PR, but
he might have been too busy to respond for a long time. I want to
apologize for closing his PR.
2024-10-10 20:27:31 +08:00
7086cmd
ebbf77dfe2 feat(minifier): implement calculations for NumberValue (#6419) 2024-10-10 11:48:21 +00:00
7086cmd
73d6a4a3cf test(minifier): port all replace_known_methods tests. (#6418) 2024-10-10 10:20:55 +00:00
leaysgur
c822b48d4f fix(regular_expression): Fix CharacterClass negative codegen (#6415)
Part of #6413 , fixes these mismatch.

```
  × Regular Expression content mismatch for `/[^]a/m`: `[]a` == `[]a`
  × Regular Expression content mismatch for `/a[^]/`: `a[]` == `a[]`
  × Regular Expression content mismatch for `/[^]/`: `[]` == `[]`
  × Regular Expression content mismatch for `/[^]/`: `[]` == `[]`
```
2024-10-10 05:00:45 +00:00
camchenry
a1a2721b1e perf(linter): Replace ToString::to_string with CompactStr in remaining rules (#6407) 2024-10-10 02:45:24 +00:00
camchenry
c5c69d6359 perf(linter): use CompactStr in valid-title (#6406) 2024-10-10 02:45:24 +00:00
camchenry
d66e826136 perf(linter): use CompactStr in prefer-lowercase-title (#6405) 2024-10-10 02:45:23 +00:00
camchenry
889400c77d perf(linter): use CompactStr for get_node_name in Jest rules (#6403) 2024-10-10 02:45:22 +00:00
Boshen
95892ecc86 feat(coverage): add ContentEq test for regular_expression (#6411)
closes #6409

Marking as good first issue if anyone wants to pick this up and fix the failing test.
2024-10-10 02:21:21 +00:00
dalaoshu
2d3ae63b01
chore(editors/vscode): remove the usage of prettier (#6412)
Because we use `dprint`, there are some conflicts between them.
2024-10-10 09:57:38 +08:00
camchenry
9906849b33 perf(linter): use CompactStr in no-large-snapshots (#6402) 2024-10-10 01:15:22 +00:00
camchenry
c382ec4f32 perf(linter): use CompactStr in no-hooks (#6401) 2024-10-10 01:15:22 +00:00
camchenry
24a5d9b98f perf(linter): use CompactStr in expect-expect (#6400) 2024-10-10 01:15:21 +00:00
camchenry
71dbdad1e3 perf(linter): use CompactStr in no-console (#6399) 2024-10-10 01:15:21 +00:00
ottomated
384d5be40b
fix(regular_expression): Flatten Spans on regex AST nodes (#6396)
cc @overlookmotel
2024-10-10 09:13:18 +08:00
camchenry
f5f00a1b0e perf(linter): use CompactStr in no-bitwise (#6398) 2024-10-10 00:34:48 +00:00
DonIsaac
84aa2a237c test(linter/no-useless-constructor): add cases for initializers in subclass constructors (#6390) 2024-10-09 22:05:54 +00:00
DonIsaac
5ea9ef7af7 refactor(linter): improve labels and help message for eslint/no-useless-constructor (#6389)
I noticed this rule's error message for redundant cases was pretty unclear when I ran oxlint on one of my codebases. I think this is an improvement.
2024-10-09 19:53:12 +00:00
DonIsaac
ba53bc9942 fix(linter/no-unused-vars): false positives in TS type assertions (#6397)
Fixes several false positive cases for referenced variables and declarations
that are inside type casts, `as` expressions, `satisfies` expressions, non-null
assertions, and the like.

```js
function foo(el) { return el + 1 }
const arr = [1, 2, 3]
const mapped = arr.map(foo as unknown as SomePredicateType)
```
2024-10-09 19:43:59 +00:00