Commit Graph

102 Commits

Author SHA1 Message Date
connorshea 464ddd1806 docs(linter): support a shared short description for jest/vitest rules (#26186)
AI Disclosure: Generated with Claude Code, Fable 5. Reviewed by me. This sets up the short_description to be added to the various rules shared between jest and vitest.

`declare_oxc_lint!` now accepts a path to a shared constant for `short_description`, mirroring how `docs = SHARED_DOCUMENTATION` works. Like `documentation`, the handling is gated behind the `ruledocs` feature.

A shared short description is added to `expect-expect`, `no-disabled-tests`, and `valid-expect`.

Rules where the wording legitimately differs per framework (e.g. `no-alias-methods`) can keep per-plugin string literals, which remain supported. Or we can opt to add the raw strings on every one of these rules and drop the shared short desc idea, I don't have a strong preference either way.

Once we decide and merge this, we can add the short descriptions for all the other remaining shared rules. We'll also need to split up the two remaining rules that are problematic (https://github.com/oxc-project/oxc/issues/23186), then we can expose the `short_description` field in the JSON rules formatter for use on the website's rules list view.
2026-08-30 20:40:00 +00:00
Boshen 8c4552dfa6 feat(linter)!: split react/react-compiler into per-category rules (#25500)
Splits the experimental `react/react-compiler` rule into 24 category-specific rules matching `eslint-plugin-react-hooks` v7.

- Runs React Compiler once per file and routes structured diagnostics to each enabled rule.
- Removes `react/react-compiler` and `reportAllBailouts`, with rules categorized by user-facing lint intent.
- Adds per-rule documentation and deduplicates shared React lint URLs.
- Preserves standardized compiler diagnostics while reporting each finding under its Oxlint rule name.

Breaking change: configurations using `react/react-compiler` must migrate to the category-specific rules.

Written with Claude Code and Codex.
2026-08-15 14:56:58 +00:00
Connor Shea d09ccc9a7b chore(linter): Add info and short_description fields to declare_oxc_lint! macro. (#22511)
Simplified redo of #22295. Calling this a chore because I don't think it
warrants mention in the changelog for now as this is just basic
scaffolding changes, but we can mark it as a feature if preferred.

AI Disclosure: generated with Claude Code, reviewed by me.

The `short_description` field will be a one-sentence summary of the rule
that can be used in documentation, and especially the rules list on the
website. The idea would be to enable the rules list to include the short
description as a subtitle under each rule, similar to this:

<img width="1120" height="618" alt="image"
src="https://github.com/user-attachments/assets/ff9e4d63-b61f-474e-9455-d3567c96d51c"
/>

The rule macros will now look like this:

```rs
declare_oxc_lint!(
    /// Longer rule description here.
    MyRule,
    eslint,
    nursery,
    pending,
    config = MyRule,
    version = "next",
    info {
        short_description = "FIXME: One-sentence description of the rule.",
    },
);
```

We could do `info = {` here instead of `info {`, up to the reviewers.

I'll move `version` into the `info` field in a subsequent PR. I didn't
do it here because I wanted to keep this simple and avoid problems of
merge conflicts with the release tomorrow. The `info` field was
suggested by camchenry to avoid continuing to bloat the size of the rule
meta struct / rules enum file.

In a subsequent PR I'll add the short_description to most rules using
the same script as I used in #22295. Again, just keeping this simple /
avoiding merge conflicts.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2026-06-10 14:20:12 +01:00
camchenry 5c1fe49a27 refactor(linter): allow config in declare_oxc_lint to be a path to a config struct (#21751)
In order to support shared config structs like in https://github.com/oxc-project/oxc/pull/18467, we need to allow defining `config` as a path to a struct in a different module, like `config = shared::SomeConfig`
2026-04-25 16:03:48 +00:00
Sysix 83b91f5403 chore(linter): declare_oxc_lint! accept docs from a const (#18603)
> Updates the `declare_oxc_lint!` proc-macro parser/codegen to support sourcing rule documentation from a shared constant (via a `docs = path::TO_CONST` option) in addition to inline doc comments.
2026-04-24 20:21:16 +00:00
Old Autumn cffdc2ee91 feat(linter): backfill rule version metadata (#21391)
## Summary

This PR covers the first two follow-up tasks from #19890:

- backfill missing `version` metadata for the remaining rules
- add a test to prevent future regressions
- expose rule version metadata through `RuleEnum` so the new test can
validate it programmatically

The following rules now declare `version = "1.60.0"`:

- `jest/valid-expect-in-promise`
- `jest/prefer-importing-jest-globals`
- `unicorn/consistent-template-literal-escape`

## Why

Part of #19890 tracks adding per-rule introduction versions for oxlint
rules. This PR focuses on finishing the metadata backfill and adding a
guardrail so future rules cannot regress by omitting `version = ...`.

## Testing

```bash
cargo test -p oxc_linter --test rule_version_metadata_test --features ruledocs
cargo test -p oxc_linter --test rule_configuration_documentation_test --features ruledocs
cargo test -p oxc_linter --features ruledocs
cargo fmt
```

## Notes

This PR intentionally does not include:

- release automation for rewriting `version = "next"`
- website/docs rendering changes

Those are better handled in follow-up PRs.

## AI Usage Disclosure

I used AI assistance to help analyze the issue, inspect the relevant
code paths, and draft the implementation plan and PR text. I manually
reviewed the proposed changes and remain responsible for the final code
and submission.
2026-04-14 16:30:32 +01:00
camchenry b9e93da282 feat(linter): allow tagging rules with release version (#21362)
Allows `version = "foo"` setting in `declare_oxc_lint`.
2026-04-13 07:53:42 +00:00
Boshen b293ea8d4e chore(rust): bump cargo-shear to 1.11.2 (#20403)
## Summary
- Bump `cargo-shear` from 1.10.0 to 1.11.2 in justfile and CI workflows
- Apply `cargo shear --fix`: set `doctest = false` on 6 crates with no
doc tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 23:10:12 +08:00
Boshen 3e54818821 chore(rust): use cargo-shear to toggle Cargo.toml [lib] test = bool (#20195)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-03-10 22:59:09 +08:00
Boshen 569aa6138d docs(rust): add missing rustdocs and remove missing_docs lint attrs (#19306)
## Summary
- add rustdoc comments for remaining public APIs in:
  - `oxc_transformer`
  - `oxc_isolated_declarations`
  - `oxc_semantic`
- remove all `#![warn(missing_docs)]` crate attributes
- remove all `#![expect(missing_docs)]` and `#[expect(missing_docs)]` attributes
- update AST kind generator template and regenerate so generated code no longer reintroduces missing-doc lint expectations

## Validation
- `just fmt`
- `just ast`
- `cargo rustc -p oxc_ast --lib -- -Dmissing-docs`
- `cargo rustc -p oxc_codegen --lib -- -Dmissing-docs`
- `cargo rustc -p oxc_transformer --lib -- -Dmissing-docs`
- `cargo rustc -p oxc_isolated_declarations --lib -- -Dmissing-docs`
- `cargo rustc -p oxc_semantic --lib -- -Dmissing-docs`
- `cargo rustc -p oxc_span --lib -- -Dmissing-docs`
- `cargo check -p oxc_transformer -p oxc_isolated_declarations -p oxc_semantic`
- `cargo check -p oxc_ast -p oxc_syntax -p oxc_str -p oxc_parser -p oxc_codegen -p oxc_span -p oxc_allocator -p oxc_data_structures -p oxc_macros`

## AI usage disclosure
This PR was prepared with AI assistance (Codex / GPT-5). I reviewed and validated the generated changes and take responsibility for the final content.
2026-02-12 08:41:48 +00:00
connorshea 41f92d15b6 fix(linter): Error when given config options for a lint rule that has no config options defined. (#18809)
Enforce that rules with no config struct/enum raise an error when provided with config options.

For example, the `no-debugger` rule does not take any configuration options. It would silently allow them, but that was an invalid behavior.

```json
{
  "rules": {
    "eslint/no-debugger": ["error", { "some": "option" }]
  }
}
```

With this PR, we get this error:

```
Failed to parse oxlint configuration file.

  x Invalid configuration for rule `no-debugger`:
  |   This rule does not accept configuration options.
```

This prevents misconfiguration from causing problems / confusing behaviors if you try to define a config option on a rule which supports no config options. This is another part of the work for #17854.

There were still a handful of rules not yet migrated over to the `config` defined inside the lint macro. I've worked around that problem by giving them dummy configs for now, and added a test accordingly.

AI Disclosure: Built with help from Raptor Mini + Copilot / Claude Code + Opus. Reviewed and verified by me.
2026-02-01 17:47:47 +00:00
Boshen f424ac675a refactor(linter): replace declare_all_lint_rules! macro with codegen (#18076)
## Summary

- Replace the `declare_all_lint_rules\!` proc-macro with checked-in codegen
- The generated `rules_enum.rs` file (~16K lines) provides better IDE support since the code is visible to rust-analyzer
- Run `cargo run -p oxc_linter_codegen` to regenerate
- Uses `quote\!` macro for clean, maintainable code generation

### Changes

- **New**: `tasks/linter_codegen/src/rules_enum.rs` - generates `RuleEnum` using `quote\!` macro
- **Modified**: `tasks/linter_codegen/src/main.rs` - added `generate_rules_enum_file()`
- **Modified**: `tasks/linter_codegen/src/rules.rs` - updated parser to scan module declarations
- **Modified**: `tasks/linter_codegen/Cargo.toml` - added `quote` and `proc-macro2` dependencies
- **Modified**: `crates/oxc_linter/src/rules.rs` - replaced macro invocation with re-exports, updated module docs
- **Modified**: `crates/oxc_linter/src/lib.rs` - added `pub mod rules_enum` to generated module, added clippy expects
- **Deleted**: `crates/oxc_macros/src/declare_all_lint_rules.rs` - removed proc-macro

### Adding new rules

1. Add the rule module to `crates/oxc_linter/src/rules.rs`
2. Run `cargo run -p oxc_linter_codegen` to regenerate `RuleEnum`

### Build time comparison

| Mode | main | this PR | Change |
|------|------|---------|--------|
| Dev | 26.80s | 31.39s | +17% |
| Release | 3m 32s | 3m 37s | +2% |

The slight increase is expected since rustc now parses the 1.1MB generated file instead of expanding a proc-macro. The tradeoff is better IDE support.

## Test plan

- [x] All 916 linter tests pass
- [x] `just lint` passes
- [x] `just ready` passes
- [x] Verified codegen works: `cargo run -p oxc_linter_codegen`

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-01-21 02:48:30 +00:00
connorshea 2b11d4d8e7 docs(linter): Raise error if rule docs contain unclosed markdown codeblocks. (#17889)
AI Disclosure: Used GitHub Copilot + Raptor mini for help with this, have code reviewed and confirmed the behavior is correct after adding an invalid codeblock. The implementation is a bit naive (markdown technically allows 4 backticks in some situations, for example, and this doesn't technically catch whether that is closed properly), but I think it should be fine if it works fine with all 650 rules we already have.

This will prevent a somewhat-common mistake in the rule documentation where we unintentionally have invalid markdown. Now, the rule will fail if the docs are invalid in this way. e.g. see #17888.

We should maybe consider updating the macro to also error on certain missing headers, but that's a future concern.
2026-01-11 20:54:43 +00:00
Connor Shea 901eef6b5d refactor(linter): update Rule::from_configuration to return a Result (#17479)
Built on top of #17478. 

Based on the changes I experimented with in #17199, and the suggestion
given by camc in that PR.

AI Disclosure: This was done almost entirely via find+replace and manual
updates to fix individual rules. I did use AI for the change in
0abc9814d3b9e44c59dcd042ef65f446a556d1a3 since I had trouble figuring
out a solution for that.

It may be easier to review this by going through it commit-by-commit.

Ran ecosystem CI on this branch and it looks like it works fine, no new
regressions
https://github.com/oxc-project/oxc-ecosystem-ci/actions/runs/20590908980

---------

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2025-12-30 18:29:22 +00:00
overlookmotel f1660c2219 refactor(linter): rename RuleEnum::read_json to from_configuration (#16340)
Pure refactor. `RuleEnum::read_json` delegates to the rule's `from_configuration` method. So it makes more sense IMO for this method to be called `from_configuration` too. This follows the same pattern as the rest of `RuleEnum`'s methods.
2025-12-01 15:51:51 +00:00
camchenry 7598b3ed00 feat(linter): allow configuring tsgolint rules (#15286)
This depends on the next version of `tsgolint` (after 0.6.0) to be released in order to work, otherwise not all `options` will not be accepted.

This implements rule configuration for rules that run in tsgolint. This is achieved by serializing the rule configuration as JSON and sending it as part of the payload, which is now supported by tsgolint. This is implemented by adding a new `to_configuration` method, which does the opposite of `from_configuration`. This is only implemented and used for tsgolint rules, so that there's no additional performance cost unless you are using type-aware linting.

Unfortunately, this does mean that we sort of have to maintain config parsing in two separate codebases, but I think we can improve this in the future with more tooling.

---

Generated rule documentation:

````

## Configuration

This rule accepts a configuration object with the following properties:

### allowForKnownSafeCalls

type: `array`

default: `[]`

Allows specific calls to be ignored, specified as type or value specifiers.

#### allowForKnownSafeCalls[n]

Type or value specifier for matching specific declarations

Supports four types of specifiers:

1. **String specifier** (deprecated): Universal match by name
```json
"Promise"
```

2. **File specifier**: Match types/values declared in local files
```json
{ "from": "file", "name": "MyType" }
{ "from": "file", "name": ["Type1", "Type2"] }
{ "from": "file", "name": "MyType", "path": "./types.ts" }
```

3. **Lib specifier**: Match TypeScript built-in lib types
```json
{ "from": "lib", "name": "Promise" }
{ "from": "lib", "name": ["Promise", "PromiseLike"] }
```

4. **Package specifier**: Match types/values from npm packages
```json
{ "from": "package", "name": "Observable", "package": "rxjs" }
{ "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" }
```

### allowForKnownSafePromises

type: `array`

default: `[]`

Allows specific Promise types to be ignored, specified as type or value specifiers.

#### allowForKnownSafePromises[n]

Type or value specifier for matching specific declarations

Supports four types of specifiers:

1. **String specifier** (deprecated): Universal match by name
```json
"Promise"
```

2. **File specifier**: Match types/values declared in local files
```json
{ "from": "file", "name": "MyType" }
{ "from": "file", "name": ["Type1", "Type2"] }
{ "from": "file", "name": "MyType", "path": "./types.ts" }
```

3. **Lib specifier**: Match TypeScript built-in lib types
```json
{ "from": "lib", "name": "Promise" }
{ "from": "lib", "name": ["Promise", "PromiseLike"] }
```

4. **Package specifier**: Match types/values from npm packages
```json
{ "from": "package", "name": "Observable", "package": "rxjs" }
{ "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" }
```

### checkThenables

type: `boolean`

default: `false`

Check for thenable objects that are not necessarily Promises.

### ignoreIIFE

type: `boolean`

default: `false`

Ignore immediately invoked function expressions (IIFEs).

### ignoreVoid

type: `boolean`

default: `true`

Ignore Promises that are void expressions.

````
2025-11-14 22:22:47 +00:00
renovate 4d71f45eec chore(deps): update rust crates (#15523)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [convert_case](https://redirect.github.com/rutrum/convert-case) | workspace.dependencies | minor | `0.8.0` -> `0.9.0` |
| [quote](https://redirect.github.com/dtolnay/quote) | workspace.dependencies | patch | `1.0.41` -> `1.0.42` |
| [ureq](https://redirect.github.com/algesten/ureq) | workspace.dependencies | patch | `3.1.2` -> `3.1.4` |

---

### Release Notes

<details>
<summary>dtolnay/quote (quote)</summary>

### [`v1.0.42`](https://redirect.github.com/dtolnay/quote/releases/tag/1.0.42)

[Compare Source](https://redirect.github.com/dtolnay/quote/compare/1.0.41...1.0.42)

- Tweaks to improve build speed ([#&#8203;305](https://redirect.github.com/dtolnay/quote/issues/305), [#&#8203;306](https://redirect.github.com/dtolnay/quote/issues/306), [#&#8203;307](https://redirect.github.com/dtolnay/quote/issues/307), [#&#8203;308](https://redirect.github.com/dtolnay/quote/issues/308), thanks [@&#8203;dishmaker](https://redirect.github.com/dishmaker))

</details>

<details>
<summary>algesten/ureq (ureq)</summary>

### [`v3.1.4`](https://redirect.github.com/algesten/ureq/blob/HEAD/CHANGELOG.md#314)

[Compare Source](https://redirect.github.com/algesten/ureq/compare/3.1.3...3.1.4)

- Set content-type with new Multipart form [#&#8203;1133](https://redirect.github.com/algesten/ureq/issues/1133)

### [`v3.1.3`](https://redirect.github.com/algesten/ureq/blob/HEAD/CHANGELOG.md#313)

[Compare Source](https://redirect.github.com/algesten/ureq/compare/3.1.2...3.1.3)

- Fix short read with multi-byte charset [#&#8203;1131](https://redirect.github.com/algesten/ureq/issues/1131)
  - Replace rustls-pemfile usage with rustls-pki-types [#&#8203;1122](https://redirect.github.com/algesten/ureq/issues/1122)
  - Support for env NO\_PROXY and proxy config [#&#8203;1118](https://redirect.github.com/algesten/ureq/issues/1118)
  - Experimental multi-part form support [#&#8203;1102](https://redirect.github.com/algesten/ureq/issues/1102)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 9am on monday" in timezone Asia/Shanghai, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNTkuNCIsInVwZGF0ZWRJblZlciI6IjQxLjE1OS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
2025-11-10 13:52:24 +00:00
Connor Shea 5c2df4c02a docs(linter): Add docs for config attribute in declare_oxc_lint! macro. (#15233)
Noticed this was missing in the macro docs.

---------

Signed-off-by: Connor Shea <connor.james.shea@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-02 23:11:22 +00:00
howen 801e1d174c fix(linter): Error on unexpected tokens when declaring lint rule (#14881)
Related to
[this](https://github.com/oxc-project/oxc/pull/14807#issuecomment-3422865650)
issue where missing commas in `declare_oxc_lint!` would cause
documentation to be generated wrongly without erroring.

In the image below, there is no warning about the missing comma after
`dangerou_suggestion`, this causes `config` to not be generated in the
documentation.

<img width="436" height="196" alt="image"
src="https://github.com/user-attachments/assets/0d40bc12-15e2-48a7-813b-62b61aafc718"
/>

With the fix, users will be notified about the missing comma.

<img width="436" height="196" alt="image"
src="https://github.com/user-attachments/assets/ca75fb69-ce08-4de0-9cc0-7332a11a5e55"
/>
2025-10-22 09:33:45 +01:00
camchenry 90f5f89bdf refactor(linter): remove run_on_symbol (#14610)
- closes https://github.com/oxc-project/backlog/issues/191

Previous PRs removed most usage of this run function, and this migrates the rest to use `run_once`. The motivation for this is not performance (this is likely a slight regression, actually), but should be a slight benefit to binary size and general maintenance. We now only have 3 ways of running lint rules, which makes the linter runtime code simpler.
2025-10-15 09:16:32 +00:00
camchenry 75a529c611 feat(linter): add run info about what functions rules implement (#13839)
Adds linter codegen to specify run information about what functions a given rule implements. Looks for the `impl` block for the given rule and looks at all of the rules and checks what functions are implemented. multiple `impl` blocks cannot be specified for the same struct, so we are guaranteed to be able to know this just from the one block.

On its own, this information doesn't do much for us, but it will allow us to improve the linter runtime performance by optimizing how rules are run based on which functions are implemented and which are no-ops.
2025-10-12 10:22:32 +00:00
Boshen c778cba9d5 chore(rust): MSRV 1.88.0 (#13977)
This broke the linter ast nodes detector
2025-09-22 14:04:26 +00:00
camchenry 476729bc2d refactor(linter): simplify RuleRunner trait definition (#13637)
Suggestion from @overlookmotel. Simplifies the `RuleRunner` trait down to a single `Option` constant. `None` indicates we should run the lint rule on any node type, and `Some(AstTypesBitset)` means we should use the specific node types given for filtering lint rules.
2025-09-10 04:25:48 +00:00
camchenry a744aff1d7 perf(linter): skip rules that do not have any relevant node types (#13138)
- part of https://github.com/oxc-project/oxc/issues/12223
- supersedes stack: https://github.com/oxc-project/oxc/pull/12228

This PR adds the ability to add node type information to indicate what node types a lint rule acts on. The lint rule runner can use this information to optimize running lint rules by skipping nodes, files, or rules that don't apply.

This is a simple version that is focused on creating the framework for automatically generating the rule runner code. This is not the end of optimizations. Currently only 102 rules have node type information, while 471 rules have no node type information and will not be skipped. Adding node type information for more rules will improve performance. We may also be able to skip more nodes and files by being clever about how we use this information. For example, filtering out any rules which do not run on any node type, if the file contains no relevant node types for the rule.

- Adds a new `RuleRunner` trait which includes information needed for indicating whether a rule has node type info or not
- Adds a `oxc_linter_codegen` task which is used to generate the implementation of `RuleRunner` trait for all lint rules. This is mostly written by AI, so worth a bit of skepticism, but I've tried to manually verify the results and it looks good (just lacking more complex detection).
  - Currently, only rules that contain a single top-level `if` statement (or chain of `else if`), or a single `match` statement will have their node type info generated. This should give us a high level of confidence, since these patterns are relatively easy to verify and identify, but it's only a subset of all rules. Next steps will be to add support for `let...else`
- Adjusts the main linting loop to use the node type information to skip rules for node types that don't apply
- Updates CI to include a check for any uncommitted linter codegen changes

---

## Benchmarks

In the latest version of this PR, CodSpeed shows an up to +13% increase in linter performance across large and small files. In the real-world, I've seen a ~5-15% improvement in performance, but in some cases close to zero for very small files. In either case, there appears to be little downside and a lot of potential upside here.

<img width="769" height="242" alt="Screenshot 2025-08-24 at 9 29 30 PM" src="https://github.com/user-attachments/assets/d2c430c4-17a9-4606-85d5-c66c734975d9" />
<img width="757" height="308" alt="Screenshot 2025-08-24 at 9 30 24 PM" src="https://github.com/user-attachments/assets/5508464f-de55-4f4e-9ddd-58f215c4ce85" />
<img width="976" height="368" alt="Screenshot 2025-08-24 at 9 34 52 PM" src="https://github.com/user-attachments/assets/203f83c7-46f3-49f1-a1a8-e18f7ec8483b" />
2025-09-08 03:22:26 +00:00
Cam McHenry 9e3963fce9 refactor(linter): allow marking rule as a tsgolint rule (#12890)
Making it easier to add new `tsgolint` rules, which will make this more
favorable for implementing new rules with AI to speed up importing all
the type-aware rules. Adds the ability to add a `(tsgolint)` marker in
the `declare_oxc_lint!` macro which generates the necessary code.
2025-08-08 13:46:23 +08:00
Copilot 3f37ed1aff refactor(linter): Replace lazy_static with std::sync::LazyLock (#12822) 2025-08-05 14:48:07 +08:00
Copilot de1de35c07 docs(rust): Add comprehensive README.md documentation for all Rust crates (#12706) 2025-08-01 18:13:46 +08:00
Don Isaac 14f0159721 feat(linter/exhaustive-deps): add auto-fixer (#12354)
## What This PR Does
Adds auto-fixing capabilities for some scenarios in
`react-hooks/exhaustive-deps`.

This is a poor man's stacked PR. #12337 must be merged first.
2025-07-17 15:12:34 +01:00
DonIsaac 12b0917e54 feat(linter): auto-generate docs for rule configs (#10629) 2025-05-16 10:18:20 +00:00
DonIsaac fb070c43b0 feat(linter/no-extra-boolean-cast): implement auto-fixer (#10682) 2025-05-01 14:18:29 +00:00
renovate a788a64649 chore(deps): update dependency rust to v1.86.0 (#10196)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [rust](https://redirect.github.com/rust-lang/rust) | minor | `1.85.1` -> `1.86.0` |

---

### Release Notes

<details>
<summary>rust-lang/rust (rust)</summary>

### [`v1.86.0`](https://redirect.github.com/rust-lang/rust/blob/HEAD/RELEASES.md#Version-1860-2025-04-03)

[Compare Source](https://redirect.github.com/rust-lang/rust/compare/1.85.1...1.86.0)

\==========================

<a id="1.86.0-Language"></a>

## Language

-   [Stabilize upcasting trait objects to supertraits.](https://redirect.github.com/rust-lang/rust/pull/134367)
-   [Allow safe functions to be marked with the `#[target_feature]` attribute.](https://redirect.github.com/rust-lang/rust/pull/134090)
-   [The `missing_abi` lint now warns-by-default.](https://redirect.github.com/rust-lang/rust/pull/132397)
-   Rust now lints about double negations, to catch cases that might have intended to be a prefix decrement operator (`--x`) as written in other languages. This was previously a clippy lint, `clippy::double_neg`, and is [now available directly in Rust as `double_negations`.](https://redirect.github.com/rust-lang/rust/pull/126604)
-   [More pointers are now detected as definitely not-null based on their alignment in const eval.](https://redirect.github.com/rust-lang/rust/pull/133700)
-   [Empty `repr()` attribute applied to invalid items are now correctly rejected.](https://redirect.github.com/rust-lang/rust/pull/133925)
-   [Inner attributes `#![test]` and `#![rustfmt::skip]` are no longer accepted in more places than intended.](https://redirect.github.com/rust-lang/rust/pull/134276)

<a id="1.86.0-Compiler"></a>

## Compiler

-   [Debug-assert that raw pointers are non-null on access.](https://redirect.github.com/rust-lang/rust/pull/134424)
-   [Change `-O` to mean `-C opt-level=3` instead of `-C opt-level=2` to match Cargo's defaults.](https://redirect.github.com/rust-lang/rust/pull/135439)
-   [Fix emission of `overflowing_literals` under certain macro environments.](https://redirect.github.com/rust-lang/rust/pull/136393)

<a id="1.86.0-Platform-Support"></a>

## Platform Support

-   [Replace `i686-unknown-redox` target with `i586-unknown-redox`.](https://redirect.github.com/rust-lang/rust/pull/136698)
-   [Increase baseline CPU of `i686-unknown-hurd-gnu` to Pentium 4.](https://redirect.github.com/rust-lang/rust/pull/136700)
-   New tier 3 targets:
    -   [`{aarch64-unknown,x86_64-pc}-nto-qnx710_iosock`](https://redirect.github.com/rust-lang/rust/pull/133631).
        For supporting Neutrino QNX 7.1 with `io-socket` network stack.
    -   [`{aarch64-unknown,x86_64-pc}-nto-qnx800`](https://redirect.github.com/rust-lang/rust/pull/133631).
        For supporting Neutrino QNX 8.0 (`no_std`-only).
    -   [`{x86_64,i686}-win7-windows-gnu`](https://redirect.github.com/rust-lang/rust/pull/134609).
        Intended for backwards compatibility with Windows 7. `{x86_64,i686}-win7-windows-msvc` are the Windows MSVC counterparts that already exist as Tier 3 targets.
    -   [`amdgcn-amd-amdhsa`](https://redirect.github.com/rust-lang/rust/pull/134740).
    -   [`x86_64-pc-cygwin`](https://redirect.github.com/rust-lang/rust/pull/134999).
    -   [`{mips,mipsel}-mti-none-elf`](https://redirect.github.com/rust-lang/rust/pull/135074).
        Initial bare-metal support.
    -   [`m68k-unknown-none-elf`](https://redirect.github.com/rust-lang/rust/pull/135085).
    -   [`armv7a-nuttx-{eabi,eabihf}`, `aarch64-unknown-nuttx`, and `thumbv7a-nuttx-{eabi,eabihf}`](https://redirect.github.com/rust-lang/rust/pull/135757).

Refer to Rust's \[platform support page]\[platform-support-doc]
for more information on Rust's tiered platform support.

<a id="1.86.0-Libraries"></a>

## Libraries

-   The type of `FromBytesWithNulError` in `CStr::from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError>` was [changed from an opaque struct to an enum](https://redirect.github.com/rust-lang/rust/pull/134143), allowing users to examine why the conversion failed.
-   [Remove `RustcDecodable` and `RustcEncodable`.](https://redirect.github.com/rust-lang/rust/pull/134272)
-   [Deprecate libtest's `--logfile` option.](https://redirect.github.com/rust-lang/rust/pull/134283)
-   [On recent versions of Windows, `std::fs::remove_file` will now remove read-only files.](https://redirect.github.com/rust-lang/rust/pull/134679)

<a id="1.86.0-Stabilized-APIs"></a>

## Stabilized APIs

-   [`{float}::next_down`](https://doc.rust-lang.org/stable/std/primitive.f64.html#method.next_down)
-   [`{float}::next_up`](https://doc.rust-lang.org/stable/std/primitive.f64.html#method.next_up)
-   [`<[_]>::get_disjoint_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.get_disjoint_mut)
-   [`<[_]>::get_disjoint_unchecked_mut`](https://doc.rust-lang.org/stable/std/primitive.slice.html#method.get_disjoint_unchecked_mut)
-   [`slice::GetDisjointMutError`](https://doc.rust-lang.org/stable/std/slice/enum.GetDisjointMutError.html)
-   [`HashMap::get_disjoint_mut`](https://doc.rust-lang.org/std/collections/hash_map/struct.HashMap.html#method.get_disjoint_mut)
-   [`HashMap::get_disjoint_unchecked_mut`](https://doc.rust-lang.org/std/collections/hash_map/struct.HashMap.html#method.get_disjoint_unchecked_mut)
-   [`NonZero::count_ones`](https://doc.rust-lang.org/stable/std/num/struct.NonZero.html#method.count_ones)
-   [`Vec::pop_if`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.pop_if)
-   [`sync::Once::wait`](https://doc.rust-lang.org/stable/std/sync/struct.Once.html#method.wait)
-   [`sync::Once::wait_force`](https://doc.rust-lang.org/stable/std/sync/struct.Once.html#method.wait_force)
-   [`sync::OnceLock::wait`](https://doc.rust-lang.org/stable/std/sync/struct.OnceLock.html#method.wait)

These APIs are now stable in const contexts:

-   [`hint::black_box`](https://doc.rust-lang.org/stable/std/hint/fn.black_box.html)
-   [`io::Cursor::get_mut`](https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#method.get_mut)
-   [`io::Cursor::set_position`](https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#method.set_position)
-   [`str::is_char_boundary`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.is_char_boundary)
-   [`str::split_at`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.split_at)
-   [`str::split_at_checked`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.split_at_checked)
-   [`str::split_at_mut`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.split_at_mut)
-   [`str::split_at_mut_checked`](https://doc.rust-lang.org/stable/std/primitive.str.html#method.split_at_mut_checked)

<a id="1.86.0-Cargo"></a>

## Cargo

-   [When merging, replace rather than combine configuration keys that refer to a program path and its arguments.](https://redirect.github.com/rust-lang/cargo/pull/15066/)
-   [Error if both `--package` and `--workspace` are passed but the requested package is missing.](https://redirect.github.com/rust-lang/cargo/pull/15071/) This was previously silently ignored, which was considered a bug since missing packages should be reported.
-   [Deprecate the token argument in `cargo login` to avoid shell history leaks.](https://redirect.github.com/rust-lang/cargo/pull/15057/)
-   [Simplify the implementation of `SourceID` comparisons.](https://redirect.github.com/rust-lang/cargo/pull/14980/) This may potentially change behavior if the canonicalized URL compares differently in alternative registries.

<a id="1.86.0-Rustdoc"></a>

## Rustdoc

-   [Add a sans-serif font setting.](https://redirect.github.com/rust-lang/rust/pull/133636)

<a id="1.86.0-Compatibility-Notes"></a>

## Compatibility Notes

-   [The `wasm_c_abi` future compatibility warning is now a hard error.](https://redirect.github.com/rust-lang/rust/pull/133951)
    Users of `wasm-bindgen` should upgrade to at least version 0.2.89, otherwise compilation will fail.
-   [Remove long-deprecated no-op attributes `#![no_start]` and `#![crate_id]`.](https://redirect.github.com/rust-lang/rust/pull/134300)
-   [The future incompatibility lint `cenum_impl_drop_cast` has been made into a hard error.](https://redirect.github.com/rust-lang/rust/pull/135964) This means it is now an error to cast a field-less enum to an integer if the enum implements `Drop`.
-   [SSE2 is now required for "i686" 32-bit x86 hard-float targets; disabling it causes a warning that will become a hard error eventually.](https://redirect.github.com/rust-lang/rust/pull/137037)
    To compile for pre-SSE2 32-bit x86, use a "i586" target instead.

<a id="1.86.0-Internal-Changes"></a>

## Internal Changes

These changes do not affect any public interfaces of Rust, but they represent
significant improvements to the performance or internals of rustc and related
tools.

-   [Build the rustc on AArch64 Linux with ThinLTO + PGO.](https://redirect.github.com/rust-lang/rust/pull/133807)
    The ARM 64-bit compiler (AArch64) on Linux is now optimized with ThinLTO and PGO, similar to the optimizations we have already performed for the x86-64 compiler on Linux. This should make it up to 30% faster.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMjcuMyIsInVwZGF0ZWRJblZlciI6IjM5LjIyNy4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
2025-04-04 07:43:00 +00:00
camchenry 0f1e0e8771 refactor(linter): gate rule docs behind feature (#10027)
- related to https://github.com/oxc-project/oxc/issues/9998

Adds a `ruledocs` feature for capturing the documentation text in lint rule macros. This is only enabled for the website task currently.

Locally, this removes ~429K bytes from the binary size when running `cargo build --release -p oxlint`

<img width="247" alt="Screenshot 2025-03-25 at 12 18 23 AM" src="https://github.com/user-attachments/assets/52bbf254-eebf-45c5-8229-282fee921101" />
2025-03-25 04:53:21 +00:00
Uli 383181937c fix(linter): fix example lint declaration and macro syntax (#9626)
1. Add missing plugin to example declaration
2. Remove double empty line in example declaration
3. Normalize way of using `declare_oxc_lint!` to round braces
2025-03-09 16:46:40 +08:00
Boshen 1d81adac48 Rust Edition 2024 (#9289)
closes #9271

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-02-22 11:56:25 +08:00
Boshen 9f361819b9 refactor(rust): apply cllippy::nursery rules (#9232) 2025-02-20 01:51:04 +00:00
Boshen 3414824197 docs(oxc): enable clippy::too_long_first_doc_paragraph (#9237) 2025-02-19 15:58:28 +00:00
dalaoshu 5b548a1695 chore(oxc_macros): remove commented-out unused code (#8896)
- Add line breaks to `What it does` and `Why is this bad?` comments for
consistency with `Examples`
- Remove commented-out unused code
2025-02-08 23:11:02 +08:00
overlookmotel a4a8e7deda style(all): replace #[allow] with #[expect] (#8930)
Replace `#[allow]` with `#[expect]` through the whole codebase.

This also surfaced many places where the `#[allow]` attributes were outdated/pointless and could be removed entirely.

Only places `#[allow]` remains are:

1. In generated code and macros, where lint errors may or may not be triggered depending on the generated code.
2. A few places where clippy malfunctions. These use e.g. `#[allow(unused, clippy::allow_attributes)]`.
2025-02-07 14:50:02 +00:00
renovate 8b6d331631 chore(deps): update rust crates (#8452)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [convert_case](https://redirect.github.com/rutrum/convert-case) | workspace.dependencies | minor | `0.6.0` -> `0.7.0` |
| [prettyplease](https://redirect.github.com/dtolnay/prettyplease) | workspace.dependencies | patch | `0.2.27` -> `0.2.28` |
| [proc-macro2](https://redirect.github.com/dtolnay/proc-macro2) | workspace.dependencies | patch | `1.0.92` -> `1.0.93` |

---

### Release Notes

<details>
<summary>dtolnay/prettyplease (prettyplease)</summary>

### [`v0.2.28`](https://redirect.github.com/dtolnay/prettyplease/releases/tag/0.2.28)

[Compare Source](https://redirect.github.com/dtolnay/prettyplease/compare/0.2.27...0.2.28)

-   Expression precedence fixes ([#&#8203;90](https://redirect.github.com/dtolnay/prettyplease/issues/90), [#&#8203;92](https://redirect.github.com/dtolnay/prettyplease/issues/92), [#&#8203;95](https://redirect.github.com/dtolnay/prettyplease/issues/95), [#&#8203;96](https://redirect.github.com/dtolnay/prettyplease/issues/96), [#&#8203;97](https://redirect.github.com/dtolnay/prettyplease/issues/97), [#&#8203;98](https://redirect.github.com/dtolnay/prettyplease/issues/98), [#&#8203;100](https://redirect.github.com/dtolnay/prettyplease/issues/100))

</details>

<details>
<summary>dtolnay/proc-macro2 (proc-macro2)</summary>

### [`v1.0.93`](https://redirect.github.com/dtolnay/proc-macro2/releases/tag/1.0.93)

[Compare Source](https://redirect.github.com/dtolnay/proc-macro2/compare/1.0.92...1.0.93)

-   Optimize TokenStream's Drop ([#&#8203;489](https://redirect.github.com/dtolnay/proc-macro2/issues/489), [#&#8203;490](https://redirect.github.com/dtolnay/proc-macro2/issues/490), thanks [@&#8203;WalkerKnapp](https://redirect.github.com/WalkerKnapp))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 11am on monday" in timezone Asia/Shanghai, Automerge - "before 11am on monday" in timezone Asia/Shanghai.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS45Mi4wIiwidXBkYXRlZEluVmVyIjoiMzkuOTIuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
2025-01-15 13:29:46 +00:00
Alexander S. b6c1546d07 test(linter): use plugin name instead of category for finding rule (#8353)
needed for #8329

I wanted to use `proc_macro::Span::SourceFile` to auto detect the plugin
name. But this feature is unstable :/
2025-01-09 10:48:11 +08:00
Boshen 39b9c5d01b feat(linter)!: remove unmaintained security plugin (#7773) 2024-12-10 14:29:22 +00:00
camc314 bd0693bcd0 feat(linter): allow lint rules with the same name (#7496)
Apologies @Boshen for the stupidly large diff.

I've done the following:

 - `RuleEnum`'s members are now prefixed with the plugin name. e.g. `NoDebugger` has become `EslintNoDebugger`
- updated tester.rs to accept the rule's NAME, CATEGORY to allow us to test rules with the same name (diff category)
- updates `declare_all_lint_rules` satisfy the first above change.
2024-11-27 04:25:05 +00:00
DonIsaac 1691cab507 feat(linter): support user-configurable secrets for oxc-security/api-keys (#5938) 2024-10-28 18:55:19 +00:00
camchenry 97195ec5a2 refactor(linter): add run_on_jest_node to run rules on only jest nodes (#6721)
- part of https://github.com/oxc-project/oxc/issues/6038

Adds a new `run_on_jest_node` method for running lint rules which allows only Jest/Vitest nodes to be linted. This simplifies a number of Jest rules by removing the need to iterate/collect Jest nodes inside of them. Now, they can simply run on the Jest nodes that are passed to them directly. This also saves time by skipping the running of the rule if it is not a test file or the Jest/Vitest plugins are not enabled.
2024-10-21 02:13:58 +00:00
DonIsaac 34b6221036 docs(macros): add #![warn(missing_docs] to oxc_macros (#6710)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-21 00:09:27 +00:00
DonIsaac 87f3b8dc55 refactor(macros): clean up declare_oxc_secret (#5937) 2024-10-16 20:10:10 +00:00
DonIsaac d24985ed51 feat(linter): add oxc-security/api-keys (#5906)
## What This PR does
Adds a new `oxc-security/api-key` rule that scans for hard-coded API keys.

It is broken up into "secret rules", where each one is responsible for finding a different kind of key. It is architecturally identical to how lint rules themselves. This PR also includes the first of these rules, for AWS access key IDs.

Logic and rules are based on [keyhunter](https://github.com/Donisaac/keyhunter). I've licensed that repo under GNU GPLv3, but it's my code and I can do what I want with it 😈 (read: I'm fine with it being MIT for oxc).

This PR is a complete feature in its own right, but does not represent the end of this work. See https://github.com/oxc-project/backlog/issues/116 to track overall progress.
2024-09-22 22:39:56 +00:00
DonIsaac e413cad0d7 perf(linter): move shared context info to ContextHost (#5795)
> Related to #5770

## What This PR Does

Moves state that is constant over a linted file out of `LintContext` and into a shared `ContextHost` struct, turning `LintContext` into a [flyweight](https://en.wikipedia.org/wiki/Flyweight_pattern).

This brings `LintContext` from 144 bytes down to 96. `Linter::run` iterates over `(rule, ctx)` pairs in a very tight loop, and each rule instance gets its own clone of `ctx`. A smaller `LintContext` means better cache locality and a smaller heap allocation for this vec. I'm hoping to eventually get it small enough to fit in a single cache line.

I made a PR a while ago that did something similar to this one, but instead of using an `Rc`, each `LintContext` stored a read-only reference. This added an extra lifetime parameter, making it slightly unwieldy, but I saw up to 15%/25% perf improvements on local benchmarks. I'll dig around for it and add a link shortly.

### Architecture
![image](https://github.com/user-attachments/assets/9e8352ae-a581-46a3-a578-9eb855d4ebaf)
----
![image](https://github.com/user-attachments/assets/49213cd9-3c31-40dc-97ad-ddf010705ab6)
2024-09-16 04:22:07 +00:00
Boshen 63a830e08c chore(dprint): format toml files (#5599)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-09-08 14:26:16 +08:00
Boshen 1bed5ce2a5 chore: run cargo +nightly fmt to sort imports (#5503)
They are never going to be stable are they ... https://github.com/oxc-project/oxc/blob/cedf7a4daa4084523050d9ae1b4555e5174c6347/.rustfmt.toml#L8-L16
2024-09-06 04:04:26 +00:00