Commit graph

6080 commits

Author SHA1 Message Date
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
DonIsaac
d3e59c6a6d fix(linter/no-unused-vars): false positive in some default export cases (#6395)
Fixes a false positive in `eslint/no-unused-vars` when a function expression is
default exported within an array.

```js
export default [ function foo() {} ]
```
2024-10-09 19:43:57 +00:00
DonIsaac
e08f956c00 fix(linter/no-unused-vars): false positive for functions and classes in arrays (#6394)
Fixes a false positive when a function or class expression is an array element.
Found while linting Jest tests in an internal repo.

```js
import { stringify } from './custom-stringify';

test.each(['a', 1, function foo() {}])('When stringifying %p, matches the snapshot', input => {
    expect(stringify(input)).toMatchSnapshot();
})
```
2024-10-09 19:43:56 +00:00
7086cmd
994b60b420 refactor(minifier): use builtin get_number_value. (#6335) 2024-10-09 12:55:34 +00:00
7086cmd
97ac179320 feat(minifier): arithmetic operations for infinity. (#6332)
I do not anticipate that this will be utilized in production 😂 .
2024-10-09 12:55:33 +00:00
dalaoshu
b9c94bbc44
fix(editors/vscode): temporarily solve oxc_language_server issue on windows (#6384)
closes #6382 

It seems we cannot support `oxc_language_server` by directly reusing
code from `coc-oxc`, at least not on Windows, because it requires an
`.exe` executable.

I will take some time to study the implementation of `Biome` to enhance
our vscode plugin.
2024-10-09 20:52:54 +08:00
Boshen
eacde0553e chore(coverage): proposal-json-modules to stage 4 (#6380) 2024-10-09 03:09:35 +00:00
DonIsaac
a504f96b06 refactor(isolated-declarations): mark return struct as non exhaustive (#6374)
This will let us add fields to `IsolatedDeclarationsReturn` in the future without breaking consuming code.
2024-10-08 22:02:14 -04:00
Boshen
f1bf0e8425
chore: Update README.md 2024-10-09 09:51:02 +08:00
DonIsaac
15dfc1db95 feat(isolated-declarations): impl Default for options (#6372)
Makes using ID options more ergonomic.
2024-10-09 01:43:06 +00:00
DonIsaac
834ee2aa6c fix(semantic): TSConditionalType scope enter/exit locations (#6351)
Fixes the same problem as #6270, but uses `#[scope(enter_before)]` and `#[scope(exit_after)]` to correct scope entry/exit locations.
2024-10-09 01:34:46 +00:00
DonIsaac
d9718adc8d feat(ast_tools): support #[scope(exit_before)] (#6350)
Closes #6311.

Adds support for `#[scope(exit_before)]`, which is the opposite of `#[scope(enter_before)]`
2024-10-09 01:34:44 +00:00
camchenry
c8174e2ab4 feat(linter): add suggestions for no-plusplus (#6376)
Implements naive suggestions for the `no-plusplus` rule. This is not implemented as a fix, because there isn't an exact 1:1 equivalence between `++` and `+= 1`. But most cases should be autofixable by this, but I've marked it as dangerous suggestion due to the semantics change
2024-10-09 01:20:07 +00:00