Commit graph

1939 commits

Author SHA1 Message Date
camc314
38ba2f640c chore(linter): remove some unused commented code (#7800) 2024-12-11 08:55:21 +00:00
Nicholas Rayburn
06e6d387fa
fix(linter): Fix unicorn/prefer-query-selector to use the correct replacement for getElementsByClassName (#7796)
Note: This uses a regex to replace multiple instances of whitespace with
` .`. May not be the most performant, so if there's a simple alternative
I can change to that instead.

cc @camc314, I know this was assigned to you but I just wanted to throw
something quick together while I had a minute. Feel free to use this, or
decline it and write your own.

Fixes #7794.

---------

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-12-11 16:49:40 +08:00
oxc-bot
bde753b4ee
release(oxlint): v0.15.0 (#7782)
## [0.15.0] - 2024-12-10

- 39b9c5d linter: [**BREAKING**] Remove unmaintained security plugin
(#7773) (Boshen)

### Features

- 065f7dc linter: Support `expectTypeOf`, `assert` and `assertType` in
`vitest/expect-expect` (#7742) (Yuichiro Yamashita)
- 3d5f0a1 linter/no_restricted_imports: Add the no_restricted_imports
rules (#7629) (Guillaume Piedigrossi)

### Bug Fixes

- ad27b20 linter: Only resolve esm files for import plugin (#7720)
(Boshen)
- 5e6053f linter: False positive in `eslint/yoda` (#7719) (dalaoshu)

### Refactor

- c6a19aa linter: Remove unused `serde` features (#7738) (Boshen)
- b9a2b35 linter: Remove `aho-corasick` (#7718) (Boshen)

### Testing

- 62f0a22 linter: Port `react-jsx-uses-vars` rules to no_unused_vars
(#7731) (Tyler Earls)
- 02f9903 linter: Add regression tests for `import/namespace` (#7723)
(dalaoshu)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-11 00:58:03 +08:00
Boshen
39b9c5d01b feat(linter)!: remove unmaintained security plugin (#7773) 2024-12-10 14:29:22 +00:00
Guillaume Piedigrossi
3d5f0a1a0c
feat(linter/no_restricted_imports): add the no_restricted_imports rules (#7629)
add first test cases related to the 'paths' config

Note that the test cases and configuration format is not the same as the
original ESLint rule.
What is the oxc team strategy to develop such a rule? Is it ok to adapt
the config format ?

---

I started a discussion here :
https://github.com/oxc-project/oxc/discussions/7534#discussion-7574282
I copy/paste the content here. Maybe it is more relevant?

I am working to implement [this no-restricted-imports
rule](https://eslint.org/docs/latest/rules/no-restricted-imports).
I have several problems:

How to handle multiple format configuration in rust?
The eslint config can be: "fs", ["fs"], or {paths: [{name: "fs"}]}. But
Rust needs only one type. I don't know how to do this in rust.

Is it ok to cover only the {paths: [{name: "fs"}]} case ?

How to parse this config with the from_configuration method?
Here is what I have done:

```
   fn from_configuration(value: serde_json::Value) -> Self {
        let mut paths = Vec::new();
        let mut patterns = Vec::new();

        if let Some(obj) = value.as_object() {
            // Handle paths array
            if let Some(paths_value) = obj.get("paths") {
                if let Some(paths_array) = paths_value.as_array() {
                    for path_value in paths_array {
                        if let Ok(path) = serde_json::from_value(path_value.clone()) {
                            paths.push(path);
                        }
                    }
                }
            }

            // Handle patterns array
            if let Some(patterns_value) = obj.get("patterns") {
                if let Some(patterns_array) = patterns_value.as_array() {
                    for pattern_value in patterns_array {
                        if let Ok(pattern) = serde_json::from_value(pattern_value.clone()) {
                            patterns.push(pattern);
                        }
                    }
                }
            }
        }

        Self { paths, patterns }
    }
````
But here is my result:
```
[RestrictedPath { name: "foo", import_names: None, message: None }]

-------- rule config --------
{
  "paths": [
    {
      "name": "foo",
      "importNames": [
        "AllowedObject"
      ]
    }
  ]
}
```
Note the "None" values
2024-12-10 17:00:15 +08:00
Yuichiro Yamashita
065f7dcb9d
feat(linter): support expectTypeOf, assert and assertType in vitest/expect-expect (#7742)
[Vitest](https://vitest.dev/api/expect.html) has 4 assertions.
[expect](https://vitest.dev/api/expect),
[expectTypeOf](https://vitest.dev/api/expect-typeof),
[assert](https://vitest.dev/api/assert) and
[assertType](https://vitest.dev/api/assert-type).

But now only `expect`. Therefore this PR supports there rest of
assertions.
And jest doesn't have such assertions, so I added branching based on the
test framework.
2024-12-09 22:07:25 +08:00
Boshen
1a67cde0de
build(linter): fix feature unification (#7740) 2024-12-09 19:21:22 +08:00
Boshen
c6a19aa478 refactor(linter): remove unused serde features (#7738) 2024-12-09 09:16:32 +00:00
Tyler Earls
62f0a22b89
test(linter): port react-jsx-uses-vars rules to no_unused_vars (#7731)
I added the test cases from
[eslint-plugin-react/jsx-uses-vars](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/tests/lib/rules/jsx-uses-vars.js)
to a `react.rs` file in the `no_unused_vars` tests module.

After adding the new tests, they immediately passed without any source
code changes required. It would seem that the linter already supported
this rule, but now there will be tests to support it.

---------

Co-authored-by: Cameron <cameron.clark@hey.com>
2024-12-08 22:18:23 +00:00
dalaoshu
02f9903211
test(linter): add regression tests for import/namespace (#7723)
Related to #7696
2024-12-08 15:35:14 +08:00
Boshen
ad27b20dc3 fix(linter): only resolve esm files for import plugin (#7720)
closes #7696

cjs files do not work at all.
2024-12-07 17:30:45 +00:00
dalaoshu
5e6053f35a
fix(linter): false positive in eslint/yoda (#7719) 2024-12-07 15:12:30 +00:00
Boshen
b9a2b35e5a refactor(linter): remove aho-corasick (#7718) 2024-12-07 12:34:41 +00:00
oxc-bot
5f4f6d140b
release(oxlint): v0.14.1 (#7692) 2024-12-06 13:06:54 +08:00
Boshen
fd0935cfcd feat(linter): change react/rules-of-hooks category to pedantic (#7691)
Although this rule is recommended by the React team,
it does not report incorrect or wrong code for the `correctness` category.

When turned on by default, I find false positive warnings confusing,
I cannot tell whether my code is wrong or the rule implementation is
wrong - see examples in the affine repo.

```
  x eslint-plugin-react-hooks(rules-of-hooks): React Hook "use" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.
    ,-[packages/backend/server/src/config/affine.self.ts:80:1]
 79 |     /* Captcha Plugin Default Config */
 80 | ,-> AFFiNE.use('captcha', {
 81 | |     turnstile: {},
 82 | |     challenge: {
 83 | |       bits: 20,
 84 | |     },
 85 | `-> });
 86 |
    `----
```
2024-12-06 03:49:32 +00:00
camc314
7cee065249 fix(linter): panic in yoda (#7679)
fixes #7674
2024-12-06 03:33:38 +00:00
camc314
f029090d65 docs(linter): update rule documentation (#7684) 2024-12-05 16:17:46 +00:00
camc314
be9863a415 test(linter): add more tests fo rules-of-hooks (#7683)
closes #6651
2024-12-05 15:18:14 +00:00
camc314
4e489bdf0a docs(linter): update rule documentation (#7681)
part of #6050
2024-12-05 14:09:30 +00:00
Cameron
56fe5f8bb9
docs(linter): update rule documentation (#7680)
part of #6050
2024-12-05 20:14:42 +08:00
Boshen
e64fd9556d feat(linter): map .js to .ts when resolving with tsconfig.json (#7675)
fixes #6913
closes #6906
2024-12-05 09:07:23 +00:00
Boshen
b8dc333ed4 feat(syntax): add ExportEntry::is_type (#7676) 2024-12-05 09:02:18 +00:00
Boshen
6ae178e0b9 fix(linter): ignore type references in no-undef (#7670)
fixes #7007
fixes #7008
2024-12-05 05:36:54 +00:00
overlookmotel
a0973dcb5a refactor(linter): use BigIntLiteral::raw field (#7660)
No need to slice source text to get raw value of `BigIntLiteral`. It already has a `raw` field.
2024-12-05 04:23:14 +00:00
camc314
3711a8e342 refactor(linter): rename is_same_reference to is_same_expression (#7654) 2024-12-05 04:15:15 +00:00
Song Gao
ebc80f6749
refactor(ast)!: change 'raw' from &str to Option<Atom> (#7547)
Fix #7254 

Changed all "raw" properties of literal types (if they have this property) to `Option<Atom>`.

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-12-05 00:34:45 +00:00
tbashiyy
bd9d38a9a0
feat(linter): Implement eslint:yoda (#7559)
In this PR, implement
[eslint:yoda](https://eslint.org/docs/latest/rules/yoda)

ref: https://github.com/oxc-project/oxc/issues/479
2024-12-04 15:58:21 +00:00
camc314
a14e76aade feat(linter): report identical logical expressions in const-comparisons (#7630) 2024-12-04 03:10:17 +00:00
camc314
afe1e9b929 feat(linter): enhance const-comparisons for more cases (#7628) 2024-12-04 02:59:56 +00:00
camc314
b445654fbd refactor(linter): use get_inner_expression in const-comparisons (#7627) 2024-12-04 02:59:55 +00:00
camc314
fcc2546f9f fix(linter): move no-unused-expressions from TS to eslint (#7624) 2024-12-04 02:26:47 +00:00
Alexander S.
29db060c78
fix(linter): detect typescript eslint alias rules (#7622)
closes #7233
2024-12-04 10:16:00 +08:00
camc314
e824501a21 fix(linter): false positive in exhaustive-deps (#7626) 2024-12-04 01:58:25 +00:00
camc314
8a68ef4c3b fix(linter): update reporting spans for exhaustive-deps (#7625) 2024-12-04 01:58:23 +00:00
camc314
543df6e3a8 fix(linter): fix false positives in exhaustive-deps (#7615)
part of https://github.com/oxc-project/oxc/issues/7246
2024-12-03 23:54:22 +00:00
Boshen
4eb87eadbf feat(linter): RulesOfHooks from nursery to correctness (#7607) 2024-12-03 14:15:43 +00:00
camc314
6dd71c6d05 test(linter): port eslint tests to no-unused-expressions (#7611) 2024-12-03 13:15:49 +00:00
camc314
e80214c74f fix(linter): fix false positives in rules-of-hooks (#7606)
closes https://github.com/oxc-project/oxc/issues/7572

should remove all false positives from this rule
2024-12-03 12:19:00 +00:00
Cameron
3dc46a80c9
fix(linter): no-unused-expressions false positive with arrow fn expressions (#7585)
fixes https://github.com/oxc-project/oxc/issues/7584
2024-12-03 09:48:50 +08:00
Alexander S.
810671a4a0
fix(linter): detect vitest jest alias rules (#7567)
closes #7240
2024-12-03 09:46:05 +08:00
Boshen
f0e7acc68b refactor(syntax): change ModuleRecord::not_esm to has_module_syntax (#7579) 2024-12-02 09:32:57 +00:00
Boshen
18519dea33 refactor(syntax): remove ModuleRecord::export_default (#7578)
This value can be derived.
2024-12-02 09:17:57 +00:00
Boshen
d476660b0b refactor(syntax): remove ModuleRecord::exported_bindings_duplicated because it is a syntax error (#7577) 2024-12-02 08:48:01 +00:00
Boshen
17663f55d3 refactor(syntax): remove ModuleRecord::export_default_duplicated because it is a syntax error (#7576) 2024-12-02 08:19:59 +00:00
camc314
275d6256bb feat(linter): output rules to json array (#7574)
closes #7517

cc @Sysix
2024-12-02 03:17:57 +00:00
camc314
4e3044e225 fix(linter): rules-of-hooks fix false positive with default export (#7570)
closes #7555
2024-12-02 03:09:30 +00:00
camc314
cb1f8e6e03 chore(linter): update rules_of_hooks test cases (#7569)
updates test cases based on what's currently in react's repo
2024-12-02 03:09:30 +00:00
Boshen
79014ffb1d refactor(syntax): clean up ModuleRecord (#7568) 2024-12-01 14:49:04 +00:00
oxc-bot
c61a383e8c
release(oxlint): v0.14.0 (#7563)
## [0.14.0] - 2024-12-01

### Features

- 32f860d linter: Add support for ignorePatterns property within config
file (#7092) (Nicholas Rayburn)
- 053bc08 linter: Implement typescript/no-unused-expressions (#7498)
(camc314)
- 60b28fc linter: Implement typescript/consistent-generic-constructors
(#7497) (camc314)
- bd0693b linter: Allow lint rules with the same name (#7496) (camc314)
- 2ac9f96 linter: Typescript/no-inferrable-types (#7438) (camc314)
- 8d89fdc linter: Add eslint/prefer-spread (#7112) (tbashiyy)

### Bug Fixes

- 123b5b7 linter: False positive in
`typescript/consistent-type-definitions` (#7560) (dalaoshu)
- cc078d6 linter: Add missing error message prefix to
`eslint/no-const-assign` (Boshen)
- 17c0dd8 linter: Fix `jsx_no_script_url` doc failed to build (Boshen)

### Performance

- 6cc7a48 linter: Use `OsString` for module cache hash (#7558) (Boshen)
- 6655345 linter: Use `FxDashMap` for module cache (#7522)
(overlookmotel)

### Documentation

- a6b0100 linter: Fix config example headings (#7562) (Boshen)

### Refactor

- 0f3f67a linter: Add capability of adding semantic data to module
record (#7561) (Boshen)
- 8392177 linter: Clean up the runtime after the module record change
(#7557) (Boshen)
- 823353a linter: Clean up APIs for `ModuleRecord` (#7556) (Boshen)
- f847d0f linter: Call `str::ends_with` with array not slice (#7526)
(overlookmotel)
- 2077ff9 linter: Remove `once_cell` (#7510) (Boshen)
- 169b8bf linter, syntax: Introduce type alias `FxDashMap` (#7520)
(overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-01 16:47:21 +08:00
Boshen
a6b0100501
docs(linter): fix config example headings (#7562)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-01 16:31:22 +08:00