Commit graph

54 commits

Author SHA1 Message Date
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 ... cedf7a4daa/.rustfmt.toml (L8-L16)
2024-09-06 04:04:26 +00:00
DonIsaac
8862f0680e chore(linter): update docs for declare_oxc_lint! (#4825) 2024-08-11 15:27:54 +00:00
overlookmotel
7ea058d84f refactor(ast_codegen): replace Windows-style line breaks with Unix-style (#4769)
2 files in AST codegen had Windows-style CRLF line breaks. Change them to Unix-style LF. Does not alter contents of the files aside from the line breaks.
2024-08-08 17:28:58 +00:00
Don Isaac
69c6b650f2
perf(linter-macros): only iterate over all rules once (#4672) 2024-08-06 10:28:49 +08:00
DonIsaac
ddd8b27977 feat(linter): support conditional fix capabilities (#4559) 2024-07-31 05:27:16 +00:00
Don Isaac
654395847f
feat(linter): add auto-fix metadata to RuleMeta (#4557)
Add a `FIX` constant to `RuleMeta` that describes what kinds of auto
fixes a
rule can perform (if any). This PR also updates `declare_oxc_lint` to
accept a
fix capabilities field. Follow-up PRs in this stack will update existing
rules
and update other parts of the codebase to use this new field.

The end goal of this stack is to
1. automate creation of #4179 in a similar way we auto-update rule
progress,
2. use it in rule documentation pages when we eventually add lint rules
to the website
2024-07-31 10:51:51 +08:00
DonIsaac
f7da22da18 perf(linter): disable lint rules by file type (#4380)
### TL;DR

Added a `should_run` function to multiple lint rules to determine if a rule should be executed based on the source type. This change optimizes the linting process by avoiding unnecessary rule checks.

### What changed?

1. **New Method**: Introduced the `should_run` method in the `Rule` trait.
2. **Implementation**: Implemented the `should_run` method for various lint rules, particularly those related to React and TypeScript.
3. **Usage**: Updated the `Linter` to use the `should_run` method to filter rules before execution.
4. **Macro Update**: Modified the `declare_all_lint_rules` macro to incorporate the `should_run` method.

### How to test?

1. Run the linter on a project containing React and TypeScript files.
2. Verify that only relevant rules are executed based on the file type (e.g., JSX rules for React files).

### Why make this change?

This change improves the performance of the linter by ensuring that only applicable rules are run for a given file type, reducing unnecessary computation and potential false positives.

---
2024-07-21 15:22:54 +00:00
DonIsaac
7a75e0f8a7 refactor(linter): use diagnostic codes in lint rules (#4349)
> This PR is (unfortunately) quite large, but all changes are needed in tandem for this to work properly.

## What This PR Does

Updates the linter to populate diagnostics reported by rules with error codes statically derived from `RuleMeta` + `RuleEnum`.

Doing so required changing how we handle vitest rules. I know @mysterven was hoping to refactor that part of the code, and I think this approach is an improvement (but could probably be cleaned up further).

## Changes

### 1. Auto-Populate Error Codes
`LintContext` now sets an error code scope + error code number for diagnostics reported by lint rules. `LintContext` will not clobber existing codes set by rules, allowing for rule-specific override behavior (e.g. to use `eslint-plugin-react-hooks` as an error scope).

In order to accomplish this, I had to update every diagnostic factory for every rule. While doing this I found some incorrect error messages, or messages that could be easily improved. This is where a large majority of the snapshot diffs come from. Additionally, I was able to reduce string allocations from `format!` usages in diagnostic factories, especially within jest rules.

### 2. Framework and Library Detection
This PR adds `FrameworkFlags`, which specify what (if any) set of libraries and frameworks are being used by a project and/or file. They are passed in two ways:

1. `LintOptions` can specify a set of `framework_hints` that apply to the entire target codebase. Right now these are always empty, but I'm thinking in the future we could sniff `package.json`. It may be helpful for enabling/disabling default rules.
2. When `Linter` gets run on a file, framework information is sniffed from the `LintContext`. Right now, we are only checking for `vitest` imports in `ModuleRecord` and test path prefixes from `source_path`. It may be useful to do something similar for React/NextJS rules in the future. I know that [next/no-html-link-for-pages](https://nextjs.org/docs/messages/no-html-link-for-pages) could benefit greatly from this.
2024-07-20 03:35:00 +00:00
Boshen
f3a21a28d7
chore: do not compile test crates that have no tests 2024-06-24 00:20:04 +08:00
rzvxa
4d2b7f1227 refactor(linter): LintContext can now only be constructed with a cfg enabled semantic. (#3761)
It has the same spirit as #3747 but with a much simpler approach. I've used the fact that @Boshen mentioned about linter always using CFG so now we assert `semantic.cfg().is_some()` in the `LintContext::new` because of this assertion we can have a `LintContext::cfg` that unwraps unchecked.
Eliminates unnecessary checks in our hot paths.

It has the best of both worlds, No complicated typing yet we still get the CFG as a non-optional value without extra ASM or branching.
2024-06-19 13:01:33 +00:00
Boshen
060819894d
chore: crates should only publish src and examples directory 2024-06-08 16:35:16 +08:00
Boshen
1ad17eaee1 refactor(macros): remove the redundant trie builder (#3415) 2024-05-26 08:00:05 +00:00
Boshen
1e84644220
chore: update toml format 2024-05-21 22:15:47 +08:00
Boshen
8388c7bd21
perf(linter): use usize for RuleEnum hash (#3336) 2024-05-18 14:12:32 +08:00
Boshen
15f275f572
refactor(linter): reduce llvm lines generated by RuleEnum::read_json (#3207)
Previous: 

```
  Lines                 Copies               Function name
  -----                 ------               -------------
    9150 (1.1%, 13.8%)      1 (0.0%,  8.2%)  oxc_linter::rules::RuleEnum::read_json
```

After:

```
    2285 (0.3%, 36.2%)      1 (0.0%, 40.3%)  oxc_linter::rules::RuleEnum::read_json
```
2024-05-08 21:53:06 +08:00
Boshen
b15bf2826b
feat(napi/parser): remove experimental flexbuffer api (#2957) 2024-04-13 14:59:31 +08:00
Boshen
bd56d51443
chore(macros): only select required features from syn to reduce compile time (#2955) 2024-04-13 13:37:59 +08:00
Boshen
93897c530c
chore: bump syn to v2 (#2888) 2024-04-02 20:57:09 +08:00
Boshen
697b6b70c0
feat: merge features serde and wasm to serialize (#2716)
This PR merges the previous confusing features `serde` and `wasm` into a
single `serialize` feature.

We'll eventually do serialize + type information for both wasm and napi
targets.

`oxc_macros` is removed from `oxc_ast`'s dependency because it requires
`syn` and friends, which goes against our policy ["Third-party
dependencies should be
minimal."](https://oxc-project.github.io/docs/contribute/rules.html#development-policy)
2024-03-14 17:13:12 +08:00
overlookmotel
3c1e0db53f
refactor: reduce cfg_attr boilerplate with SerAttrs derive (#2669)
Closes #2641.

Also added `tsify` attribute to the `SerAttrs` derive macro, so `#[cfg_attr(feature = "wasm", tsify(...))]` can also be reduced to `#[tsify(...)]`.
2024-03-11 13:38:24 +08:00
Boshen
9e06bd7797
feat(linter): remove the --timings feature (#2049)
For a various reasons:

This features bloats the code size.

We have many tools for profiling in Rust (as compared to ESLint where the feature came from),
so a built-in feature is not really needed anymore.

ESLint needed `--timings` because it needs to monitor plugins.
We control all our code so we don't need this.
2024-01-16 14:21:04 +08:00
Boshen
32504cadb7
feat(linter): add a perf category (#1625)
relates to #1607
2023-12-04 17:31:34 +08:00
Boshen
1a576f60a8
refactor(rust): move to workspace lint table (#1444) 2023-11-20 14:38:10 +08:00
Boshen
db5417f9a9
refactor(clippy): allow clippy::too_many_lines 2023-10-16 15:18:11 +08:00
Boshen
693145107c
refactor(linter): less a global hashmap to reduce rule timer macro expansion (#822)
closes #819
2023-09-01 10:32:17 +08:00
Boshen
12798e075f
refactor: improve code coverage a little bit 2023-08-25 23:07:14 +08:00
Boshen
98e4240fe1
refactor(linter): manually declare lint rules because cargo fmt breaks (#671) 2023-07-31 15:16:21 +08:00
Boshen
1bc564eafc feat(linter): add style category and change no-empty-interface to style
It's officially change in typescript-eslint
2023-07-29 11:02:51 +08:00
Boshen
252d3342a1
feat(linter): add a run_once callback (#647)
For situations where you want to inspect the scopes and trivias.
2023-07-27 18:15:15 +08:00
Boshen
d587065436
chore(rust): update crate info, add minimal rust-version, add categories 2023-07-27 13:33:18 +08:00
Shannon Rothe
21f8abe273
feat(cli): add support for TIMING env var (#535) 2023-07-25 11:14:36 +08:00
Boshen
e1f815fd8e
feat(linter): print plugin names for --rules 2023-06-25 22:47:58 +08:00
Boshen
42b97fc270 feat(linter): add suspicious and pedantic categories 2023-06-21 13:58:26 +08:00
Boshen
d30735677b
refactor(semantic): merge semantic2 crate into semantic crate (#460) 2023-06-19 20:20:59 +08:00
Boshen
ad2835f11b
chore(rustfmt): run cargo fmt 2023-05-21 11:52:26 +08:00
Boshen
1004a1d197
chore: clean up workspace dependencies (#320) 2023-04-27 11:38:39 +08:00
Boshen
4801e68b56
chore: bump deps (#311) 2023-04-22 22:09:53 +08:00
Boshen
080baaa2db
chore: use taplo to reformat toml files 2023-04-22 15:58:59 +08:00
Boshen
5b3b757290
chore(linter): add test to ensure documentation exists (#296) 2023-04-18 22:14:54 +08:00
Boshen
043a751dc7
chore(linter) move bad_bitwise_operator to restriction category
closes #243
2023-04-05 14:29:32 +08:00
Boshen
abcda95e8e
deps: bump deps 2023-04-02 16:48:45 +08:00
Boshen
9e3675a575
chore: clean up Cargo.toml 2023-03-30 23:27:26 +08:00
Boshen
d46c7aabd9
chore: do not publish some of the crates 2023-03-30 22:41:52 +08:00
yangchenye
88cd82b698
feat(macros): property generate declarations for nested modules (#212) 2023-03-27 10:30:47 +08:00
Boshen
ef19895cc3
feat(cli): add -A all -D isolated-declarations (#211)
* feat(linter): add restriction category for lint rules

* feat(cli): add "--allow" and "--deny" commands

* feat(linter): use a single instance of linter

* feat(cli): derive rules from args

* feat(cli): print number of rules
2023-03-26 04:34:31 -07:00
yangchenye
0d8d67b593
feat(linter): implement eslint(no-const-assign) (#199)
* feat(linter): implement eslint(no-const-assign)

* feat(semantics & linter): resolve symbols

* Use run_on_symbol

* Add resolved_reference to SymbolTable
2023-03-23 12:55:40 +08:00
Boshen
b5af93575f
deps: update dependencies (#183) 2023-03-15 10:30:12 +08:00
Boshen
99dbf8e946
feat(linter): use only correctness rules for now 2023-03-11 22:36:58 +08:00
Boshen
e1971577cb
fix(oxc_macros): fix clippy warnings 2023-03-08 23:35:34 +08:00