Commit graph

75 commits

Author SHA1 Message Date
Boshen
0f3f67a05a refactor(linter): add capability of adding semantic data to module record (#7561)
closes #5814
closes #5816
2024-12-01 08:14:43 +00:00
Boshen
c2ced15dfd feat(parser,linter)!: use a different ModuleRecord for linter (#7554)
The parser returns a simple `ModuleRecord` that is allocated in the arena for performance reasons.

The linter uses a more complicated, `Send` + `Sync` `ModuleRecord` that will hold more cross-module information.

The next step is to return more esm information from the parser to eliminated the need of the `oxc_module_lexer` crate.
2024-11-30 16:02:01 +00:00
Boshen
0be5233c84 refactor(semantic)!: remove ModuleRecord from Semantic (#7548)
`ModuleRecord` will eventually be moved to be linter specific thing for cross module data sharing, which means we can add more data to it.
2024-11-29 16:30:54 +00:00
overlookmotel
55f3636ecf perf(language_server): use FxDashMap for diagnostics reports map (#7523)
Same as #7521. Use `FxDashMap` instead of plain `DashMap` for hash map storing diagnostics.
2024-11-28 11:52:13 +00:00
Nicholas Rayburn
32f860d238
feat(linter): Add support for ignorePatterns property within config file (#7092)
This could probably use some tests, but I'm not really sure what exactly
should be tested.

Will leave a review with a few comments on things that might need a
different approach.

Closes #7032.
2024-11-28 17:32:44 +08:00
Nicholas Rayburn
99ecc687ba
feat(language_server): Add code actions to disable rules for the current line or entire file (#6968)
This definitely needs some cleanup by somebody more familiar with Rust,
but I think it contains most of the important pieces. I'll leave a
review with the different pieces that I know need cleanup.

Ref #6966.
2024-11-28 10:30:53 +08:00
Alexander S.
571d7e2419
fix(language_server): calculate correct column when Unicode chars (#7484)
Before:

![grafik](https://github.com/user-attachments/assets/ddae446d-9167-405b-b44e-c7f76850ffd0)

After:

![grafik](https://github.com/user-attachments/assets/e8d7ac5c-8fe9-4c51-897d-bdb55f7f33dc)

Closes #3625
2024-11-26 10:44:13 +08:00
Alexander S.
a3ecbde369
fix(language_server): do not tell clients about codeActionProvider when they do not support codeActionLiteralSupport (#7445)
VSCode output:

```
                "codeActionLiteralSupport": {
                    "codeActionKind": {
                        "valueSet": [
                            "",
                            "quickfix",
                            "refactor",
                            "refactor.extract",
                            "refactor.inline",
                            "refactor.rewrite",
                            "source",
                            "source.organizeImports"
                        ]
                    }
                },
```

See also eslint implementation
b33437b5ad/server/src/eslintServer.ts (L221-L225)
2024-11-25 14:30:02 +08:00
Alexander S.
25d9ed9b10
fix(language_server): revalidate files when configPath has changed (#7447)
closes #7446 

![revalidate-files-when-config-changes](https://github.com/user-attachments/assets/a5f4a612-9e0d-4f14-932c-f3b9b956a24a)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-25 14:29:26 +08:00
Alexander S.
84fcc43cf5
docs(language_server): add readme (#7429)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-24 12:31:23 +08:00
Cameron
c6d790b287
fix(language-server): fix panic by building scope tree child ids (#7440)
closes #7434

i couldn't test this. but what's happening is semaitc is being build
without scope child ids. When exhaustive_deps tries to access it its an
empty vec - hence the panic
2024-11-23 23:19:11 +08:00
Alexander S.
216d533b01
fix(language_server): revalidate files when oxlint config is changing (#7259)
![lsp-refresh-files](https://github.com/user-attachments/assets/e6b64f73-966d-490a-9191-b3ec64d3ac1e)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-14 10:45:17 +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
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
Nicholas Rayburn
6cb1973f4a
fix(editor): Publish diagnostics on open for all run modes except disabled (#6965) 2024-10-28 08:39:47 +08:00
injuly
aa3222ac88
fix(oxc_language_server): gitignores now applied to their respective files (#6899) 2024-10-26 10:46:35 -04:00
dalaoshu
3116fd3dc1
fix(oxc_language_server): correct diagnostic link (#6765) 2024-10-22 06:23:54 -04:00
Boshen
435a89c6e4 refactor(oxc): remove useless allocator.alloc(program) calls (#6571) 2024-10-15 02:21:20 +00:00
IWANABETHATGUY
1a93033b7b feat(oxc_language_server): add diagnostic code with link (#6487)
1. follow #6479
2. Adding related doc link to lsp diagnostic code.
## Preview
![image](https://github.com/user-attachments/assets/dad5b6a2-787a-43c3-b308-ebe74e38e21c)

**after click**
![image](https://github.com/user-attachments/assets/5b725fcd-cacd-4779-9b2a-15824d7c0cf7)

The UI looks a little wired, due to aba9ea3f1d/crates/oxc_diagnostics/src/lib.rs (L113-L120),

I suggest change the code above to
```rs
format!("{scope}/{number}")
```
2024-10-13 07:07:43 +00:00
IWANABETHATGUY
66dccc0584
feat(oxc_language_server): add related code for lsp_types::Diagnostic#source (#6479)
Closed #6477
# Before
# After

![image](https://github.com/user-attachments/assets/20377c2f-ba94-4fb5-a21c-fbd269f40385)

![image](https://github.com/user-attachments/assets/fae901b3-9753-4610-8b36-61974781f770)

Compare to eslint: 

![image](https://github.com/user-attachments/assets/0037b265-0a84-4eae-8bc9-4cbb66197485)

we could polish in the feature and link to
`lsp_types::Diagnostic#source`
2024-10-13 01:53:05 +08:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen
2b7be08af4 feat(ast)! add source_text to Program (#6444) 2024-10-11 04:13:41 +00:00
DonIsaac
2566ce787d refactor(linter): remove OxlintOptions (#6098)
Removed in favor of LinterBuilder
2024-10-11 02:30:26 +00:00
camchenry
5957214f4c feat(linter): allow fixing in files with source offsets (#6197)
- fixes https://github.com/oxc-project/oxc/issues/5913

This PR fixes the calculation of spans when dealing with files that have multiple sources and non-zero source start offsets. This is almost always the case for `.vue`, `.astro`, and `.svelte` files. This enables us to correctly apply fixes for these file types both in the CLI with `oxlint` and also in editors like VS Code.

https://github.com/user-attachments/assets/2836c8bd-09be-4e59-801d-7c95f8c2491f

I'm open to ideas on how to improve testing in this area, as I don't think that we currently have any tests for fixing files end-to-end (beyond what the linter rules check). I did run this locally on the gitlab repository (which is written in Vue) and all of the fixes appeared to be applied correctly.
2024-10-03 00:53:30 +00:00
DonIsaac
ea908f742d refactor(linter): consolidate file loading logic (#6130)
# Human Description
Low on time, so this one is short.
- consolidate source file and partial loader logic into `loader` module. I have more plans for this.
- ~LSP no longer uses `VALID_EXTENSIONS`, so now `.d.ts` files (and the like) will be linted as well~ LSP does not respect `.gitignore` files, so this change was reverted.

# AI Description
## Refactor Loader and Partial Loader

This PR refactors the loader and partial loader functionality in the oxc_linter crate:

* Introduce a new `Loader` struct with methods for checking if a file can be loaded and loading file contents
* Move `partial_loader` module to `loader/partial_loader`
* Rename `JavaScriptSource` to `source.rs` and move it to the `loader` module
* Update `JavaScriptSource` to use `u32` for `start` offset instead of `usize`
* Refactor `IsolatedLintHandler` to use the new `Loader`
* Update imports and module references throughout the codebase

This change improves the organization of the loader-related code and provides a more unified interface for loading different file types.
2024-09-29 02:48:01 +00:00
Cam McHenry
0c9dee1eda
chore(oxc): ban std::collections::HashMap in favor of FxHashMap (#5996)
Co-authored-by: camchenry <1514176+camchenry@users.noreply.github.com>
2024-09-24 16:41:36 +08:00
camchenry
02d5637dbc perf(ast-tools): use FxHashMap over std::collections::HashMap (#5997) 2024-09-23 18:28:54 +00:00
DonIsaac
5ae9b48509 refactor(linter): start internal/external split of OxlintOptions (#5659)
re-creation of #5141
2024-09-10 03:19:04 +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
b06052501a refactor(semantic)!: remove source_type argument from SemanticBuilder::new (#5553)
Realized we can get the source type from the AST.

The next PR will introduce `unambiguous` to `SourceType` and directly set `Program::source_type` to either `script` or `module`.
2024-09-06 16:40:10 +00:00
Boshen
b2ff2df5af refactor(parser)!: remove builder pattern from Parser struct (#5000)
part of #4455

use `with_options(ParseOptions { ..ParseOptions::default() })` API instead.
2024-08-20 07:40:25 +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
DonIsaac
7afa1f06c3 feat(linter): support suggestions and dangerous fixes (#4223) 2024-07-18 02:20:30 +00:00
Boshen
83bd40db4e
chore: turn off doctest for all [[bin]] 2024-07-14 16:55:19 +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
051ceb6539
chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
Boshen
f6752b482f
feat!(ast): make Trivias clonable by adding Arc (#3638)
This makes `Trivias` cloneable and stops us from using `Rc::new` and
`Rc::clone` everywhere.

`Trivias` is rarely cloned so an `Arc` should suffice.
2024-06-12 13:16:10 +08:00
Dunqing
5793ff1986
refactor(transformer): replace &’a Trivias with Rc<Trivias> (#3580)
`Transformer` needs to borrow `Trivias`.
8be1cc8052 (r1630711060)
2024-06-11 13:23:41 +08:00
overlookmotel
fa116448c9 refactor(linter): pass Rc by value (#3587)
Same as #3586.
2024-06-08 11:19:02 +00:00
Boshen
060819894d
chore: crates should only publish src and examples directory 2024-06-08 16:35:16 +08:00
Boshen
899a52bf28
fix: fix some nightly warnings 2024-05-19 00:54:52 +08:00
Boshen
f13fe8a18b
feat!(linter): enforce rule severity from the cli and configuration file (#3337)
closes #2059

Breaking change:

* `--deny` / `-D` from the CLI and `error` from configuration file will
report diagnostics as severity "error".
* `--warn` / `-W` from the CLI and `warn` from configuration file will
report diagnostics as severity "warning".
2024-05-18 17:45:19 +08:00
Boshen
893af230c0
refactor: clean up more diagnostics usages 2024-05-12 21:46:03 +08:00
Boshen
dbde5b3a04
refactor(diagnostics): remove export of miette 2024-05-12 11:46:48 +08:00
Boshen
2064ae9e0a refactor(parser,diagnostic): one diagnostic struct to eliminate monomorphization of generic types (#3214)
part of #3213

We should only have one diagnostic struct instead 353 copies of them, so we don't end up choking LLVM with 50k lines of the same code due to monomorphization.

If the proposed approach is good, then I'll start writing a codemod to turn all the existing structs to plain functions.

---

Background:

Using `--timings`, we see `oxc_linter` is slow on codegen (the purple part).

![image](https://github.com/zkat/miette/assets/1430279/c1df4f7d-90ef-4c0f-9956-2ec3194db7ca)

The crate currently contains 353 miette errors. [cargo-llvm-lines](https://github.com/dtolnay/cargo-llvm-lines) displays

```
cargo llvm-lines -p oxc_linter --lib --release

  Lines                 Copies               Function name
  -----                 ------               -------------
  830350                33438                (TOTAL)
   29252 (3.5%,  3.5%)    808 (2.4%,  2.4%)  <alloc::boxed::Box<T,A> as core::ops::drop::Drop>::drop
   23298 (2.8%,  6.3%)    353 (1.1%,  3.5%)  miette::eyreish::error::object_downcast
   19062 (2.3%,  8.6%)    706 (2.1%,  5.6%)  core::error::Error::type_id
   12610 (1.5%, 10.1%)     65 (0.2%,  5.8%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
   12002 (1.4%, 11.6%)    706 (2.1%,  7.9%)  miette::eyreish::ptr::Own<T>::boxed
    9215 (1.1%, 12.7%)    115 (0.3%,  8.2%)  core::iter::traits::iterator::Iterator::try_fold
    9150 (1.1%, 13.8%)      1 (0.0%,  8.2%)  oxc_linter::rules::RuleEnum::read_json
    8825 (1.1%, 14.9%)    353 (1.1%,  9.3%)  <miette::eyreish::error::ErrorImpl<E> as core::error::Error>::source
    8822 (1.1%, 15.9%)    353 (1.1%, 10.3%)  miette::eyreish::error::<impl miette::eyreish::Report>::construct
    8119 (1.0%, 16.9%)    353 (1.1%, 11.4%)  miette::eyreish::error::object_ref
    8119 (1.0%, 17.9%)    353 (1.1%, 12.5%)  miette::eyreish::error::object_ref_stderr
    7413 (0.9%, 18.8%)    353 (1.1%, 13.5%)  <miette::eyreish::error::ErrorImpl<E> as core::fmt::Display>::fmt
    7413 (0.9%, 19.7%)    353 (1.1%, 14.6%)  miette::eyreish::ptr::Own<T>::new
    6669 (0.8%, 20.5%)     39 (0.1%, 14.7%)  alloc::raw_vec::RawVec<T,A>::try_allocate_in
    6173 (0.7%, 21.2%)    353 (1.1%, 15.7%)  miette::eyreish::error::<impl miette::eyreish::Report>::from_std
    6027 (0.7%, 21.9%)     70 (0.2%, 16.0%)  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
    6001 (0.7%, 22.7%)    353 (1.1%, 17.0%)  miette::eyreish::error::object_drop
    6001 (0.7%, 23.4%)    353 (1.1%, 18.1%)  miette::eyreish::error::object_drop_front
    5648 (0.7%, 24.1%)    353 (1.1%, 19.1%)  <miette::eyreish::error::ErrorImpl<E> as core::fmt::Debug>::fmt
```

It's totalling more than 50k llvm lines, and is putting pressure on rustc codegen (the purple part on `oxc_linter` in the image above.

---

It's pretty obvious by looking at https://github.com/zkat/miette/blob/main/src/eyreish/error.rs, the generics can expand out to lots of code.
2024-05-11 04:56:22 +00:00
Boshen
95fc28168c
chore: apply cargo autoinherit (#2826)
See https://github.com/mainmatter/cargo-autoinherit
2024-03-26 23:57:50 +08:00
renovate[bot]
b822b6d9eb
chore(deps): update rust crates (#2671) 2024-03-11 13:39:02 +08:00
renovate[bot]
9bd1d5b25e
chore(deps): update rust crates (#2589) 2024-03-04 11:23:06 +08:00
Clément Lafont
2263377e3f
fix(oxc_language_server): use config path at init (#2569)
`config_path` was not use in initialization.
Must merge #2568 before to fix vscode.

Co-authored-by: Clément Lafont <johnrazeur@MacBook-Pro-de-Clement.local>
2024-03-03 14:01:16 +08:00
IWANABETHATGUY
ad8ca2a066
fix(oxc_language_server): serialize with camelCase (#2568)
Closed https://github.com/oxc-project/oxc/issues/2563
2024-03-02 22:56:06 +08:00