# 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.
- fixes https://github.com/oxc-project/oxc/issues/6136
The original eslint rule checks if chars start with `\u` or `\x`, but our character spans are currently busted and only report 1 char for chars like `\u{0a}`. I've made whitespace an exception to the rule, so we don't report `\x0a` currently, which is fine for now I think
All TS transforms only need a subset of the options in `TypeScriptOptions` - mostly just a single `bool`. Store these specific options in the transforms, not the whole `TypeScriptOptions` object.
This makes the transformer types smaller, and also checking the option is cheaper as it doesn't involve going through a double-reference.
e.g. Accessing `only_remove_type_imports` option with Rust's deref sugar made explicit:
Before: `*(&*self.options).only_remove_type_imports`
After: `*self.only_remove_type_imports`
- closes https://github.com/oxc-project/oxc/issues/5416
Rewrites the `no-control-regex` rule to use a regular expression AST visitor instead of the `regex` crate and parsing by hand. This change simplifies the code and makes it easier to maintain.
One notable change in the snapshots is the printing of the control characters. Previously, we always printed from the source text. Now, we print a representation of the control character itself based on its numeric value. This resulted in the nonprintable chars being printed, which are invisible. The other reason for this change is that the spans output by the regex parser for unicode escapes do not match 1:1 when raw strings and escapes are involved. This resulted in goofy looking spans in the output:
```
⚠ eslint(no-control-regex): Unexpected control character: '*\\x'
╭─[no_control_regex.tsx:1:22]
1 │ new RegExp('\\u{1111}*\\x1F', 'u')
· ────
╰────
```
Not sure where the bug lies there yet.
Updates the `no-hex-escape` to use the new standard `Visit` trait for visiting the RegExp AST, replacing the handwritten implementation in this rule. This makes it much simpler to maintain.
In exponentiation operator transform, the first branch handling `**` was "falling through" to also run the 2nd branch which handles `**=`. The first branch replaces `**` with `Math.pow`, so it can never match on the 2nd branch.
Convert it to a `match` instead, so it only executes one branch or the other.
Similar to #6118.
Share `TypeScriptOptions` between transforms as a plain `&` reference, rather than an `Rc`, to reduce setup/teardown time.
The code to parse pragmas from comments is moved into `Transformer::new`. This isn't the ideal place for it, but it means `TypeScriptOptions` can be shared with the existing `'ctx` lifetime, rather than having to have a 3rd lifetime `TypeScript<'a, 'ctx, 'options>`.
Many transforms share `TransformCtx`. Currently it's shared with `Rc`, which has a cost as the `Rc` has to be cloned many times, and it also makes dropping `Transformer` more expensive.
The PR changes that to share it as a normal reference `&TransformCtx` instead.
This requires adding an inner `TransformerImpl`. `Transformer` is now just a facade which creates the `TransformCtx` and stores options. `Transformer::build_with_symbols_and_scopes` constructs `TransformerImpl` and runs the visitor on it.
Unlikely to have any perf impact on larger files, but for small files where setup/teardown is a larger % of the overall workload, it may help a little.
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
Introduce a wrapper around `NonNull` which enables methods which exist on `std::ptr::NonNull` but are not yet stable in our MSRV. These methods remove a lot of boilerplate code from `Stack` and `NonEmptyStack` and make them easier to understand - which is important, since they contain so much unsafe code.
`Stack` and `NonEmptyStack` contained a lot of the same logic. Move shared logic into a `StackCommon` trait that they both implement.
Also split out core allocation logic into non-generic free functions for faster compile time.
Similar to previous PRs, this refactors the `no-regex-spaces` rule to use the RegExp AST visitor, rather than the handwritten implementation in this rule. This makes the rule much simpler and easier to maintain in the future.
This PR updates this rule to use the new RegExp AST visitor trait, instead of a custom implementation, which makes this rule much simpler and easier to maintain. The core logic is the same though, and the output should be identical.
Replaces rule-specific regex AST visitor method with the standard `oxc_regular_expression` one. This simplifies the code and also enables more capabilities (visiting more than just terms, but also character class contents, etc.)
Fix incorrect debug assertion in `Stack`. The code itself was fine, but debug assertion was testing the wrong thing.
This error was spotted by @Boshen: https://github.com/oxc-project/oxc/pull/6095#pullrequestreview-2332830541
Also add more debug asserts and change test so it fails before the fix in this PR.