Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(linter): consolidate file loading logic #6130

Merged

Conversation

DonIsaac
Copy link
Contributor

@DonIsaac DonIsaac commented Sep 27, 2024

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.

Copy link

graphite-app bot commented Sep 27, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-linter Area - Linter label Sep 27, 2024
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @DonIsaac and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added the A-cli Area - CLI label Sep 27, 2024
@DonIsaac DonIsaac added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Sep 27, 2024 — with Graphite App
@DonIsaac DonIsaac marked this pull request as ready for review September 27, 2024 22:11
@DonIsaac
Copy link
Contributor Author

@Boshen I want to use oxc_resolver's FS abstraction so that we can plug the linter right into VSCode's file API. This will also help with integrating with Monaco. This cant be done unless FileSystemOs is exposed publically.

@DonIsaac DonIsaac force-pushed the don/09-27-refactor_linter_consolidate_file_loading_logic branch from 21cfcae to 185a594 Compare September 27, 2024 22:13
Copy link

codspeed-hq bot commented Sep 27, 2024

CodSpeed Performance Report

Merging #6130 will not alter performance

Comparing don/09-27-refactor_linter_consolidate_file_loading_logic (ea908f7) with main (183739f)

Summary

✅ 29 untouched benchmarks

Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now .d.ts files (and the like) will be linted as well

We should never lint .d.ts files from my experience, they are never hand written.

@qweered
Copy link

qweered commented Sep 28, 2024

I heard that some companies write them by hand

@DonIsaac
Copy link
Contributor Author

@Boshen this change (linting .d.ts) files only affects the LSP, not oxlint. If a user is opening a file in their editor, and it's not already ignored by version control, it's more than likely to be a source file.

Now I need to go back and check that oxc_language_server respects .gitignores...

@DonIsaac DonIsaac force-pushed the don/09-27-refactor_linter_consolidate_file_loading_logic branch 2 times, most recently from b61adda to e9c8675 Compare September 28, 2024 18:20
@DonIsaac
Copy link
Contributor Author

Update: The LSP does not respect gitignores, so I've re-added the VALID_EXTENSIONS check. Note that it looks like the LSP also doesn't support .eslintignore files. We should add this in the future.

@DonIsaac DonIsaac requested a review from Boshen September 28, 2024 18:21
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 29, 2024
Copy link

graphite-app bot commented Sep 29, 2024

Merge activity

  • Sep 28, 10:47 PM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 28, 10:47 PM EDT: Boshen added this pull request to the Graphite merge queue.
  • Sep 28, 10:52 PM EDT: Boshen merged this pull request with the Graphite merge queue.

# 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.
@Boshen Boshen force-pushed the don/09-27-refactor_linter_consolidate_file_loading_logic branch from e9c8675 to ea908f7 Compare September 29, 2024 02:48
@graphite-app graphite-app bot merged commit ea908f7 into main Sep 29, 2024
26 checks passed
@graphite-app graphite-app bot deleted the don/09-27-refactor_linter_consolidate_file_loading_logic branch September 29, 2024 02:52
This was referenced Oct 7, 2024
Boshen added a commit that referenced this pull request Oct 8, 2024
## [0.9.10] - 2024-10-07

### Features

- f272137 editors/vscode: Clear diagnostics on file deletion (#6326)
(dalaoshu)
- 1a5f293 editors/vscode: Update VSCode extention to use project's
language server (#6132) (dalaoshu)
- 376cc09 linter: Implement `no-throw-literal` (#6144) (dalaoshu)
- 5957214 linter: Allow fixing in files with source offsets (#6197)
(camchenry)
- a089e19 linter: Eslint/no-else-return (#4305) (yoho)
- 183739f linter: Implement prefer-await-to-callbacks (#6153) (dalaoshu)
- ae539af linter: Implement no-return-assign (#6108) (Radu Baston)

### Bug Fixes

- 9e9808b linter: Fix regression when parsing ts in vue files (#6336)
(Boshen)
- 93c6db6 linter: Improve docs and diagnostics message for
no-else-return (#6327) (DonIsaac)
- e0a3378 linter: Correct false positive in
`unicorn/prefer-string-replace-all` (#6263) (H11)
- ea28ee9 linter: Improve the fixer of `prefer-namespace-keyword`
(#6230) (dalaoshu)
- f6a3450 linter: Get correct source offsets for astro files (#6196)
(camchenry)
- be0030c linter: Allow whitespace control characters in
`no-control-regex` (#6140) (camchenry)
- e7e8ead linter: False positive in `no-return-assign` (#6128)
(DonIsaac)

### Performance

- ac0a82a linter: Reuse allocator when there are multiple source texts
(#6337) (Boshen)
- 50a0029 linter: Do not concat vec in `no-useless-length-check` (#6276)
(camchenry)

### Documentation

- 7ca70dd linter: Add docs for `ContextHost` and `LintContext` (#6272)
(camchenry)
- a949ecb linter: Improve docs for `eslint/getter-return` (#6229)
(DonIsaac)
- 14ba263 linter: Improve docs for `eslint-plugin-import` rules (#6131)
(dalaoshu)

### Refactor

- 642725c linter: Rename vars from `ast_node_id` to `node_id` (#6305)
(overlookmotel)
- 8413175 linter: Move shared function from utils to rule (#6127)
(dalaoshu)
- ba9c372 linter: Make jest/vitest rule mapping more clear (#6273)
(camchenry)
- 82b8f21 linter: Add schemars and serde traits to AllowWarnDeny and
RuleCategories (#6119) (DonIsaac)
- ea908f7 linter: Consolidate file loading logic (#6130) (DonIsaac)
- db751f0 linter: Use regexp AST visitor in `no-control-regex` (#6129)
(camchenry)
- 3aa7e42 linter: Use RegExp AST visitor for `no-hex-escape` (#6117)
(camchenry)
- 9d5b44a linter: Use regex visitor in `no-regex-spaces` (#6063)
(camchenry)
- 0d44cf7 linter: Use regex visitor in `no-useless-escape` (#6062)
(camchenry)
- eeb8873 linter: Use regex visitor in `no-empty-character-class`
(#6058) (camchenry)

### Testing

- d883562 linter: Invalid `eslint/no-unused-vars` options (#6228)
(DonIsaac)

---------

Co-authored-by: Boshen <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-cli Area - CLI A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants