Commit graph

1822 commits

Author SHA1 Message Date
Dmitry Zakharov
428770edee
feat(linter): add import/no-namespace rule (#7229) 2024-11-14 19:23:56 +08:00
camc314
ff2a1d4937 fix(linter): move exhaustive-deps to react (#7251)
@Boshen lemme know if this is incorrect, but i noticed that `rules-of-hooks` lives inside `react` not `react-hooks`

1f2a6c666f/crates/oxc_linter/src/config/rules.rs (L291-L292)

1f2a6c666f/crates/oxc_linter/src/options/filter.rs (L254)
2024-11-14 08:02:26 +00:00
Orenbek
9c91151603
feat(linter): implement typescript/no-empty-object-type (#6977) 2024-11-13 09:31:16 +00:00
DonIsaac
2268a0ef90 feat(linter): support overrides config field (#6974)
Part of #5653
2024-11-13 05:40:59 +00:00
camchenry
c6a48684c3 refactor(linter): temporarily remove unknown rules checking (#7260)
I had intended to leave this in until we could rework some of the rule/plugin name resolution code, however this is causing issues with merging https://github.com/oxc-project/oxc/pull/6974. The mutability of `self` is difficult to resolve in that PR without more drastic changes. Since this isn't currently helping us out, I am simply removing the code for now until we can revisit this.
2024-11-13 03:41:03 +00:00
Cameron A McHenry
df5c535dd0
fix(linter): revert unmatched rule error (#7257)
- related to https://github.com/oxc-project/oxc/issues/6988

This is causing a lot of errors currently such as
https://github.com/oxc-project/oxc/issues/7233. I think we need to
handle rule names more robustly first:

- https://github.com/oxc-project/oxc/issues/7240
- https://github.com/oxc-project/oxc/issues/7082
- https://github.com/oxc-project/oxc/discussions/7242

then, I think we can revisit this and maybe implement it as an actual
lint plugin too? https://github.com/oxc-project/oxc/discussions/7086
2024-11-13 09:06:20 +08:00
camc314
c4ed230f8a fix(linter): fix false positive in eslint/no-cond-assign (#7241)
fixes #7238
2024-11-12 14:45:38 +00:00
dalaoshu
ef847dab9c
fix(linter): false positive in jsx-a11y/iframe-has-title (#7253)
closes #7243
2024-11-12 13:14:50 +00:00
overlookmotel
44375a5662 refactor(ast)!: rename TSEnumMemberName enum variants (#7250)
Variants of `TSEnumMemberName` were previously only prefixed with `Static` to avoid naming conflicts with the variants inherited from `Expression` for non-static member names. #7219 removed the variants inherited from `Expression`, so all variants are now static. So we can shorten the names again (back to what they were before `inherit_variants!` was introduced).
2024-11-12 12:22:21 +00:00
camc314
62b6327879 fix(linter): react/exhaustive-deps update span for unknown deps diagnostic (#7249)
Relates to #7246
2024-11-12 11:55:50 +00:00
camc314
3dcac1ae0b feat(linter): react/exhaustive-deps (#7151)
Firstly, a massive thanks to @alisnic for starting this (incredibly complicated) lint rule in https://github.com/oxc-project/oxc/pull/2637 !

still a draft. current state:

3x false positives (all todo with refs)

3x false negatives (TS will catch these
13x false negatvies todo with refs
1x false negative TODO

closes  #2637
relates to #2174
2024-11-12 11:42:47 +00:00
oxc-bot
68dc899887
release(oxlint): v0.11.1 (#7224)
## [0.11.1] - 2024-11-09

### Features

- 4dd9b60 editor/vscode: Replace existing output channel and trace
output channel with a single LogOutputChannel (#7196) (Nicholas Rayburn)
- 1fcd709 linter: Add jsx support for only-used-in-recursion (#7120)
(no-yan)
- 4d577cf linter: Add `import/first` rule (#7180) (Dmitry Zakharov)
- 9b8973f linter: Add `import/unambiguous` rule (#7187) (Dmitry
Zakharov)
- 5ab1ff6 linter: Implement @typescript-eslint/no-unsafe-function-type
(#6989) (Orenbek)

### Bug Fixes

- eea8879 editor/vscode: Update language client id to fix the resolution
of the oxc.trace.server setting (#7181) (Nicholas Rayburn)
- b73cfd9 linter: Fix `is_method_call` with parentheses and chain
expression (#7095) (tbashiyy)

### Refactor

- 8c0a362 linter: Use `ctx.source_range(comment.content_span())` API
(#7155) (Boshen)
- c5485ae semantic: Add `ancestor_kinds` iterator function (#7217)
(camchenry)
- abf1602 semantic: Rename `iter_parents` to `ancestors` (#7216)
(camchenry)
- 42171eb semantic: Rename `ancestors` to `ancestor_ids` (#7215)
(camchenry)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-11-09 19:57:08 +08:00
no-yan
1fcd70932d
feat(linter): add jsx support for only-used-in-recursion (#7120)
close #5530

This PR adds support for handling recursive JSX components, allowing
detect functions like the one below:

```javascript
function ListItem({ depth }) {
    return <ListItem depth={depth} />
}
```

Some logic is duplicated with the non-JSX case. But the refactor will be
complicated and affects over-all, so we can make it in another PR.

cc: @DonIsaac @camc314

---------

Co-authored-by: Cam McHenry <camchenry@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-09 17:11:27 +08:00
Dmitry Zakharov
4d577cf69f
feat(linter): add import/first rule (#7180) 2024-11-09 17:10:59 +08:00
Boshen
0e4adc15dd feat(ast)!: remove invalid expressions from TSEnumMemberName (#7219) 2024-11-09 08:48:14 +00:00
camchenry
c5485ae7ee refactor(semantic): add ancestor_kinds iterator function (#7217)
for convenience, I've added a new function called `ancestor_kinds` which loops overall `ancestors` and gets their `AstKind`. this is a common pattern in a couple of places. I also did some somewhat related refactoring to remove places where we were manually calling `AstNode::kind` instead of using `ancestor_kinds` or calling `parent_kind`.
2024-11-09 08:04:38 +00:00
camchenry
abf1602f33 refactor(semantic): rename iter_parents to ancestors (#7216)
for consistency with the `ancestor_ids` function, this changes it to use the same terminology but make it clear it actually returns the node, not just the ID.

this is pure refactor, no functional changes here.
2024-11-09 07:07:26 +00:00
camchenry
42171eba94 refactor(semantic): rename ancestors to ancestor_ids (#7215)
pure refactor, renaming this method to make it more clear that it returns only IDs, not nodes. in preparation for the next PR.
2024-11-09 07:00:15 +00:00
Dmitry Zakharov
9b8973f425
feat(linter): add import/unambiguous rule (#7187) 2024-11-08 08:54:37 +08:00
Orenbek
5ab1ff6f06
feat(linter): implement @typescript-eslint/no-unsafe-function-type (#6989)
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-07 17:14:19 +00:00
Dmitry Zakharov
500effe5bb
chore(linter): correct links to docs in rules (#7183) 2024-11-07 15:20:47 +08:00
Boshen
8c0a362b8b refactor(linter): use ctx.source_range(comment.content_span()) API (#7155) 2024-11-06 06:25:05 +00:00
Boshen
d1d187417b feat(ast)!: change comment.span to real position that contain // and /* (#7154)
closes #7150
2024-11-06 05:10:33 +00:00
overlookmotel
843bce4d92 refactor(ast)!: IdentifierReference::reference_id return ReferenceId (#7126)
Alter `IdentifierReference::reference_id` to return `ReferenceId`, instead of `Option<ReferenceId>`.

This method is only useful on a post-semantic AST, where it will never return `None`. Returning `ReferenceId` discourages the anti-pattern of treating the result as if it could be either `Some` or `None`, and shortens code.
2024-11-05 02:25:27 +00:00
tbashiyy
b73cfd992e
fix(linter): fix is_method_call with parentheses and chain expression (#7095)
I fixed `is_method_call` behavior in specific case below.

For example, when we use `is_method_call(call_expr, None,
Some(&["apply"]), Some(1), Some(1))` for
[`(a?.b.apply)(args)`](https://playground.oxc.rs/#eNpFjkEKg0AMRe+SVQviAdx057alN4gaZWBMJJmxFfHunVG0q+Qnn//fCi1UcMNH2ZQ4TX6531AHu0MBAtUKGjkPWzjgF6qgkQrwjsO5WysTXWIZG/GnCopsvegIVY/eaCtgQjXSnIjey+dNISo/YzDXUR25DU5S3+5OZqVknumFSmxHasrI7XtG2q+K89BKRwNl5iRGx653/xcHFV+n3gwwkzZiCf1g27YfdH1fTA==),
we cannot check correctly.

This is because we don't consider `call_expr` has parentheses and chain
expression.
2024-11-04 11:12:37 +08:00
oxc-bot
2d40b073cb
release(oxlint): v0.11.0 (#7094)
## [0.11.0] - 2024-11-03

- 9fd9f4f linter: [**BREAKING**] Sync sindresorhus/globals; removed
Object.prototype properties from builtin and es* globals (#6991)
(Boshen)

### Features

- 6b619da editor: Listen to config file changes and trigger a
didChangeConfiguration update (#6964) (Nicholas Rayburn)
- 7872927 editor/vscode: Support window/showMessage event (#7085)
(Nicholas Rayburn)
- 2184588 linter: Do not bail for unmatched rules yet (#7093) (Boshen)
- a6fcd81 linter: Add `import/no-commonjs` rule (#6978) (Dmitry
Zakharov)
- 1691cab linter: Support user-configurable secrets for
`oxc-security/api-keys` (#5938) (DonIsaac)
- 610621c linter: Implement `react/style-prop-object` (#6342) (Albert
Kaaman)
- 1e2f012 linter: Add `oxc/no-map-spread` (#6751) (DonIsaac)
- 1c66473 linter: Implement `eslint/prefer-object-has-own` (#6905)
(tomoya yanagibashi)

### Bug Fixes

- ebf3753 editor: Fix onConfigChange to send the correct config for
didChangeConfiguration notification (#6962) (Nicholas Rayburn)
- 79bf74a linter: Check is_reference_to_global_variable in
`no-array-constructor` (#7067) (Naoya Yoshizawa)
- 38d1f78 linter: Remove confusing help text for now (#7081) (Cam
McHenry)
- 147e2e4 linter: Allow replacing rule when none are enabled yet (#7014)
(camchenry)
- 7aa496a linter: Remove unsafe fixer of `no-useless-spread` (#6655)
(dalaoshu)
- f5a7134 linter/no-unused-vars: False positive for discarded reads
within sequences (#6907) (DonIsaac)

### Documentation

- 4551baa linter: Document `rules` (#6983) (Boshen)

### Refactor

- a8dc75d linter: Remove unused CLI result types (#7088) (camchenry)
- 8f1460e linter: Move `LintPlugins` from `LintOptions` to `LintConfig`
(#6932) (DonIsaac)

### Testing

- c35d3f2 linter: Improve test failure output (#6975) (camchenry)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-03 11:27:30 +08:00
Boshen
218458811b
feat(linter): do not bail for unmatched rules yet (#7093)
I intend to make a release today, let's hold onto this behaviour.
2024-11-03 11:18:36 +08:00
Naoya Yoshizawa
79bf74a1a1
fix(linter): check is_reference_to_global_variable in no-array-constructor (#7067)
Hello,

I am currently reading through the code as I work on contributing by
creating some ESLint rules.
Along the way, I noticed an incompatibility in certain cases within the
`no-array-constructor` rule.

In this PR, I added test cases and modified the code to include a check
for is_reference_to_global_variable.

The relevant ESLint behavior can be verified in the following
playground.


https://eslint.org/play/#eyJ0ZXh0IjoiLyplc2xpbnQgbm8tYXJyYXktY29uc3RydWN0b3I6IFwiZXJyb3JcIiovXG5cbi8vIGlmIGNvbW1lbnQgb3V0IGJlbG93LCBuZXh0IGxpbmUgYXMgZXJyb3JcbnZhciBBcnJheTsgbmV3IEFycmF5KCk7XG5cbm5ldyBBcnJheSgpOyIsIm9wdGlvbnMiOnsicnVsZXMiOnt9LCJsYW5ndWFnZU9wdGlvbnMiOnsic291cmNlVHlwZSI6Im1vZHVsZSIsInBhcnNlck9wdGlvbnMiOnsiZWNtYUZlYXR1cmVzIjp7fX19fX0=
2024-11-02 18:17:48 +00:00
renovate[bot]
4012e6ba0c
chore(deps): update crate-ci/typos action to v1.27.0 (#7061) 2024-11-01 23:46:54 +08:00
camchenry
1f2a6c666f feat(linter)!: report unmatched rules with error exit code (#7027)
- closes https://github.com/oxc-project/oxc/issues/6988

we now return an error exit code when there are unmatched rules. previously, we would print an error to stderr and continue running. however, this masked errors in some tests that actually had unmatched rules in them. these test cases now trigger a panic (in tests only, not at runtime), and help ensure that we are reporting an error message to the user for unknown rules, which we did not have any tests cases for before.

- fixes https://github.com/oxc-project/oxc/issues/7025

this also fixes https://github.com/oxc-project/oxc/issues/7025, where we were reporting rules as unmatched simply because they had been disabled prior to being configured. similar to https://github.com/oxc-project/oxc/issues/7009.
2024-11-01 03:27:25 +00:00
camchenry
147e2e4858 fix(linter): allow replacing rule when none are enabled yet (#7014)
fixes https://github.com/oxc-project/oxc/issues/7009

allows rules to be replaced properly when the `rules_for_override` array is empty (e.g., if you initially disable all rules, then configure them) by checking the `all_rules` array if the first `find` call fails
2024-10-30 03:39:03 +00:00
Dmitry Zakharov
a6fcd812b3
feat(linter): add import/no-commonjs rule (#6978) 2024-10-29 22:15:30 -04:00
Boshen
9fd9f4f5b9 feat(linter)!: sync sindresorhus/globals; removed Object.prototype properties from builtin and es* globals (#6991) 2024-10-29 04:13:20 +00:00
DonIsaac
8f1460eba3 refactor(linter): move LintPlugins from LintOptions to LintConfig (#6932)
Pure refactor. Moves plugin settings from linter options (which control the linter's behavior on a global level) and linter config ("which may or may not get adjusted on each file).
2024-10-29 01:28:21 +00:00
DonIsaac
1691cab507 feat(linter): support user-configurable secrets for oxc-security/api-keys (#5938) 2024-10-28 18:55:19 +00:00
Boshen
4551baaf4a docs(linter): document rules (#6983)
closes #6370
2024-10-28 14:49:16 +00:00
camchenry
c35d3f2ea2 test(linter): improve test failure output (#6975)
Improves the test output when a test fails, based on the type of expectation. The output now includes the config that was passed, as well as the source code that failed. Additional formatting makes it a little bit easier to parse.

Before:

<img width="818" alt="Screenshot 2024-10-27 at 11 54 02 PM" src="https://github.com/user-attachments/assets/bac4079c-566a-403b-adde-acdc709baceb">

&nbsp;

<img width="792" alt="Screenshot 2024-10-27 at 11 54 56 PM" src="https://github.com/user-attachments/assets/16074216-00ad-4cdc-9f47-09142242111d">

---

After:

<img width="784" alt="Screenshot 2024-10-27 at 11 49 36 PM" src="https://github.com/user-attachments/assets/5d687562-55f4-4e4f-aa3a-c90b90b714e8">

&nbsp;

<img width="820" alt="Screenshot 2024-10-27 at 11 58 56 PM" src="https://github.com/user-attachments/assets/0725d362-7aed-4fd0-9fab-93a7687aca6d">
2024-10-28 12:55:24 +00:00
dalaoshu
7aa496ab33
fix(linter): remove unsafe fixer of no-useless-spread (#6655)
closes #6618

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-10-28 17:32:02 +08:00
Albert Kaaman
610621cadf
feat(linter): implement react/style-prop-object (#6342)
Implements not recommended rule `react/style-prop-object`
(https://github.com/oxc-project/oxc/issues/1022)

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-10-27 22:51:09 -04:00
DonIsaac
f5a7134834 fix(linter/no-unused-vars): false positive for discarded reads within sequences (#6907)
Fixes a case where no-unused-vars incorectly reports a read as unused in edge
cases where a logical/binary expression is used as a conditional shorthand to
write a variable within sequence expressions.

Some code examples will make this more clear.
```js
function foo(a) {
  let x = somePropertyIWantToCheck();
  (x in a && x.hasPropA = true, console.log(a))
}
```
Since the logical expression is not in the last position within the sequence
expression list, it's getting discarded as unused. However, the right expression
(`x.hasPropA = true`) has side effects, so it _is_ being used.
2024-10-27 17:06:58 +00:00
Boshen
9a6a2f99c6 refactor(semantic)!: remove SymbolTable::get_symbol_id_from_span API (#6955)
closes #6867
2024-10-27 14:31:36 +00:00
DonIsaac
1e2f012d3c feat(linter): add oxc/no-map-spread (#6751)
Adds a new performance rule that disallows using object and array spreads in `map` and `flatMap` to modify/merge arrays and objects.
I've currently added it to `nursery` so we can battle-harden it before making it generally available as a `perf` rule.

```ts
// needless O(n) spread on `x`, making this an O(n^2) operation
const x = arr.map(x => {
  return { ...x, foo: getFoo(x.id) }
})

// Object.assign is better here
const x = arr.map(x => {
  return Object.assign(x, { foo: getFoo(x.id) })
})
```
2024-10-26 17:41:21 +00:00
tomoya yanagibashi
1c66473a8f
feat(linter): Implement eslint/prefer-object-has-own (#6905) 2024-10-26 10:45:38 -04:00
oxc-bot
1ea0be1b6a
release(oxlint): v0.10.3 (#6911)
## [0.10.3] - 2024-10-26

- 90c786c regular_expression: [**BREAKING**] Support ES2025 Duplicated
named capture groups (#6847) (leaysgur)

- 8032813 regular_expression: [**BREAKING**] Migrate to new regexp
parser API (#6741) (leaysgur)

### Features

- a73c5af linter: Add fixer for `jsx-a11y/no-access-key` rule (#6781)
(Tapan Prakash)
- 2aa763c linter: Warn unmatched rule names (#6782) (Tapan Prakash)
- 0acca58 linter: Support `--print-config all` to print config file for
project (#6579) (mysteryven)

### Bug Fixes

- f49b3e2 linter: `react/iframe-missing-sandbox` ignores vanilla JS APIs
(#6872) (DonIsaac)
- 54a5032 linter: Correct false positive in `no-duplicates` (#6748)
(dalaoshu)
- a47c70e minifier: Fix remaining runtime bugs (#6855) (Boshen)

### Documentation

- 3923e63 linter: Add schema to config examples (#6838) (Dmitry
Zakharov)

### Refactor

- a148023 linter: Dereference IDs as soon as possible (#6821)
(overlookmotel)
- 423d54c rust: Remove the annoying `clippy::wildcard_imports` (#6860)
(Boshen)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-26 17:13:06 +08:00
Boshen
cb5cb6287e fix(linter): eprintln unmatched rules warning (#6916)
We can make this a hard error and bail early once stable.
2024-10-26 08:59:12 +00:00
Tapan Prakash
a73c5af0f5
feat(linter): Add fixer for jsx-a11y/no-access-key rule (#6781) 2024-10-25 02:48:12 -04:00
leaysgur
90c786c420 feat(regular_expression)!: Support ES2025 Duplicated named capture groups (#6847)
Closes #6358

@preyneyv I know you've been working on this problem.

This is an implementation that has been dormant on my local for a while.

- All tests are passing
- However, the approach is simple but not general, so there might be some edge cases that were missed
- There's also room for improvement in terms of performance

For these reasons, it was marked as WIP for me.

I believe the test cases and other parts are usable, so feel free to fork and replace them with your implementation if you'd like.
2024-10-25 02:13:57 +00:00
DonIsaac
f49b3e2088 fix(linter): react/iframe-missing-sandbox ignores vanilla JS APIs (#6872)
> Closes #6750

Fixes a false positive in `react/iframe-missing-sandbox` on `document.createElement`, which is not react and has no way of passing a sandbox prop/attribute on creation.
2024-10-25 01:43:55 +00:00
Boshen
423d54cb74 refactor(rust): remove the annoying clippy::wildcard_imports (#6860) 2024-10-24 13:57:19 +00:00
Boshen
a47c70e425 fix(minifier): fix remaining runtime bugs (#6855) 2024-10-24 12:22:18 +00:00