Commit graph

1947 commits

Author SHA1 Message Date
dalaoshu
ee26b448cc
feat(linter): enhance get_element_type to resolve more element types (#7885)
I think it should if makes sense.

_Originally posted by @Boshen in
https://github.com/oxc-project/oxc/issues/7881#issuecomment-2543108246_
            

Since `jsx-a11y` supports these names, I have aligned them accordingly.
2024-12-14 22:45:37 +08:00
dalaoshu
32935e6875
fix(linter): false positive in jsx-a11y/label-has-associated-control (#7881)
closes #7849

This is essentially because `get_element_type` does not support
recognizing tag names like `<a.b />`. I'm unsure whether we should
support it.
2024-12-14 21:22:31 +08:00
Boshen
7fb9d47460 style(rust): cargo +nightly fmt (#7877) 2024-12-14 06:03:31 +00:00
oxc-bot
b40c410824
release(oxlint): v0.15.2 (#7876)
## [0.15.2] - 2024-12-14

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-14 13:37:03 +08:00
overlookmotel
e55ab24cc9 refactor(linter): use Expression::is_super (#7850)
Simplify code by using `Expression::is_super` which was introduced in #7831.

Also remove a lifetime bound which is unnecessary and replace use of `bool::then` (which I always find hard to read) with more explicit code.
2024-12-13 14:47:31 +00:00
oxc-bot
bb4a92c80c
release(oxlint): v0.15.1 (#7845)
## [0.15.1] - 2024-12-13

### Features

- 38b1c2e editor: Create a command to apply all auto-fixes for the
current active text editor (#7672) (Nicholas Rayburn)

### Bug Fixes

- 2b187e5 linter: Fix configuration casing for
`typescript/no_this_alias` (#7836) (Boshen)
- 06e6d38 linter: Fix unicorn/prefer-query-selector to use the correct
replacement for getElementsByClassName (#7796) (Nicholas Rayburn)
- 7a83230 semantic: Missing reference when `export default` references a
type alias binding (#7813) (Dunqing)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-13 21:23:33 +08:00
Boshen
2b187e59ba
fix(linter): fix configuration casing for typescript/no_this_alias (#7836)
closes #7835
2024-12-13 19:39:59 +08:00
Dunqing
7a832307c2 fix(semantic): missing reference when export default references a type alias binding (#7813)
Fixes: #7809

`ExportNamedDecalration` and `ExportDefaultDeclaration` can reference both type binding and value, so we need to make sure the `ReferenceFlags` is `Read | Type`
2024-12-12 14:12:30 +00:00
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