Commit graph

105 commits

Author SHA1 Message Date
overlookmotel
b553d6ff9c fix(span): fix clippy warning (#7591)
Fix clippy warning. Only triggers when running clippy in `--release` mode.
2024-12-03 02:18:57 +00:00
Boshen
823353a6fc refactor(linter): clean up APIs for ModuleRecord (#7556) 2024-12-01 04:48:42 +00:00
Boshen
d942a8d41a
chore: Rust v1.83.0 changes (#7535)
This PR does not upgrade rustc. Only changes are applied.

We cannot upgrade to the lastet Rust version yet due to wasm-bindgen
breaking some generated types.

THere's also some elided lifetimes in `**/generated/**`, which requires
modification to ast tools.
2024-11-29 11:59:45 +08:00
ottomated
9725e3c2ec feat(ast_tools): Add #[estree(always_flatten)] to Span (#6935)
Part of #6347

Other changes:
- added #[estree(skip)] to thisSpan in TSThisParameter
- Flattened the span in BoundaryAssertion (regex)
2024-10-28 02:13:24 +00:00
ottomated
169fa22350 feat(ast_tools): Default enums to rename_all = "camelCase" (#6933)
Part of #6347
2024-10-28 01:39:25 +00:00
Boshen
423d54cb74 refactor(rust): remove the annoying clippy::wildcard_imports (#6860) 2024-10-24 13:57:19 +00:00
ottomated
1145341a92 feat(ast_tools): output typescript to a separate package (#6755)
Part of #6347.

Moves typescript logic from derive_estree into a new ast_tools generator.
2024-10-24 13:08:57 +00:00
DonIsaac
85d52201b4 docs(span): enhance Span documentation (#6707)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-21 14:32:55 +00:00
Don Isaac
d4a2529439
test(span): add Span::is_empty unit tests (#6706) 2024-10-20 15:39:14 -04:00
overlookmotel
85e69a11ef refactor(ast_tools): add line breaks to generated code for ESTree derive (#6680)
Follow-on after #6404. Style nit. Add line breaks to generated code, to make it easier to read.
2024-10-19 19:50:13 +00:00
overlookmotel
ad8e293197 refactor(ast_tools): shorten generated code for impl Serialize (#6684)
Follow-on after #6404. Shorten generated code for `impl Serialize`.
2024-10-19 19:50:12 +00:00
overlookmotel
9ba2b0e3a3 refactor(ast_tools): move #[allow] attrs to top of generated files (#6679)
Follow-on after #6404. Shorten generated code for `impl Serialize` by moving `#[allow]` attrs to top of file.
2024-10-19 19:50:12 +00:00
ottomated
e310e52ca2
feat(parser): Generate Serialize impls in ast_tools (#6404)
Beginning of #6347. Instead of using serde-derive, we generate
`Serialize` impls manually.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-10-19 09:38:44 +01:00
overlookmotel
9e9fa9e741 docs(span): enable lint warnings on missing docs (#6617)
This attribute was added in #6610, but then removed again in #6612. I assume removing it was an accident.
2024-10-15 23:55:49 +00:00
DonIsaac
de22b81b83 docs(data-structures): enable lint warnings on missing docs, and add missing doc comments (#6612)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-15 22:50:47 +00:00
DonIsaac
28b1b4efe2 chore(span): enable lint warnings on missing docs (#6610)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-15 22:50:44 +00:00
DonIsaac
3faee66400 refactor(span): remove unused ContentHash::content_hash_slice (#6609)
I've replaced it with impls on `Vec<'a, T>`. I'm hoping this removes some bloat in final binaries.
2024-10-15 22:50:42 +00:00
Boshen
6a194f9086 docs(span): document validity of ModuleKind::Unambiguous (#6423)
relates #6249
2024-10-10 14:59:41 +00:00
Boshen
fd6798ffbc fix(parser): remove unintended pub Kind (#6109) 2024-09-27 12:44:40 +00:00
Boshen
a07f03aab3 feat(transformer): sync Program::source_type after transform (#5887)
closes #5552
2024-09-19 14:41:07 +00:00
DonIsaac
a5f2e9ac04 feat(span): impl From<Atom<'a>> for Atom (#5809) 2024-09-17 05:46:16 +00:00
Boshen
f49e6ebd41 fix(span): treat .js as module file (reverts the previous breaking change) (#5612)
As it turns out it's not ideal to treat `.js` as `script` in today's world anymore.

This makes https://github.com/oxc-project/oxlint-ecosystem-ci pass again.
2024-09-08 15:14:04 +00:00
overlookmotel
b3cbd56520 feat(span): format_compact_str! macro (#5610)
Add `format_compact_str!` macro to create a `CompactStr`, like `format!`.
2024-09-08 14:15:05 +00:00
overlookmotel
3d190a5728 refactor(span): move CompactStr into separate file (#5609)
Pure refactor. Split `atom.rs` into 2 files.
2024-09-08 14:15:04 +00:00
Boshen
4a8aec1605 feat(span)!: change SourceType::js to SourceType::cjs and SourceType::mjs (#5606) 2024-09-08 14:11:02 +00:00
Boshen
553262842c
refactor(span): put types and impl in the same mod file 2024-09-08 14:00:25 +08:00
Boshen
603817bef9 feat(oxc)!: add SourceType::Unambiguous; parse .js as unambiguous (#5557)
See https://babel.dev/docs/options#misc-options for background on `unambiguous`

Once `SourceType::Unambiguous` is parsed, it will correctly set the returned `Program::source_type` to either `module` or `script`.
2024-09-07 10:48:58 +00:00
Boshen
28b934ca74 fix(coverage): apply always_strict to test262 and typescript per the specifcation (#5555)
This also removes the confusing `SourceType::always_strict` field.

I hacked it with `SourceType::always_strict`, but what we actually want is add `'use strict'`.

This is technically a breaking change but I don't expect anyone using this outside of oxc.

The snapshot has a large diff due to every single line shifting by 1 row :-/
2024-09-06 17:14:01 +00: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
overlookmotel
3f204a9af5 docs(span): update docs about ContentEq Vec comparison speed (#5478)
Update the docs for `impl ContentEq for Vec` to state in what circumstances `PartialEq` is faster. See https://github.com/oxc-project/oxc/pull/5427#discussion_r1744290058.
2024-09-05 15:34:17 +00:00
overlookmotel
94a6ac63cf refactor(span): use Hasher from std (#5476)
Use `std:#️⃣:Hasher` instead of `core:#️⃣:Hasher`.

I don't actually know if importing `core` as well as `std` has any compile time perf impact, but as we're using `std` anyway, we may as well use it for everything.

Import into the `auto_impl_content_hash` module to make the macro a little easier to read.
2024-09-05 14:18:01 +00:00
rzvxa
9f6e0ed099 refactor(ast): simplify ContentEq trait definition. (#5468)
Addresses the concerns brought up in #5427
2024-09-05 05:36:51 +00:00
rzvxa
90facd3657 feat(ast): add ContentHash trait; remove noop Hash implementation from Span (#5451)
closes #5283

Also removes the noop Hash implementation on `Span` in favor of a real implementation.
2024-09-05 07:20:04 +03:30
rzvxa
23285f431d feat(ast): add ContentEq trait. (#5427)
Part of #5283
2024-09-04 11:53:50 +00:00
Boshen
1b20ceb70c feat(span): add CompactStr::to_compact_string method (#5385)
For cases where we want to get the inner string and mutate it.
2024-09-01 10:49:39 +00:00
DonIsaac
f81e8a126e feat(linter): add oxc/no-async-endpoint-handlers (#5364)
Adds `no-async-endpoint-handlers` rules, which bans async functions used as endpoint handlers in Express applications. These do not get caught by Express' error handler, causing the server to crash with an unhandled process rejection error.

```js
app.use(async (req, res) => {
  const foo = await api.getFoo(req.query) // server panics if this function rejects
  return res.json(foo)
})
```

I could not find this rule implemented in any ESLint plugin, but this is a problem I see quite often and I'm tired of dealing with it. I've added it to `oxc` for now, but we should consider adding an `express` or `api` plugin in the future.
2024-08-31 16:59:52 +00:00
DonIsaac
5a137f0985 feat(span/source-type): add SourceType factory methods (#5242) 2024-08-27 01:19:54 +00:00
DonIsaac
94f60e7748 refactor(span/source-type): make SourceType factories const (#5241)
I found myself wanting this while writing `no-unused-vars` and while using oxc
in some downstream personal projects.
2024-08-27 01:19:53 +00:00
DonIsaac
f5e05db302 feat(span/source-type): impl Display and Error for UnknownExtension (#5240) 2024-08-27 01:19:52 +00:00
DonIsaac
a6bb3b1b98 fix(span/source-type): consider .cjs and .cts files as ModuleKind::Script (#5239)
- fix: `SourceType::from_path` considers `.cjs` and `.cts` as modules, not scripts
- docs: improve rusdoc for `SourceType::from_path`
- test: add unit tests for `SourceType::from_path`
2024-08-27 01:19:52 +00:00
overlookmotel
770652327d refactor(span): clarify Atom conversion methods lifetimes (#4978)
Rename lifetimes on `FromIn` impls for `Atom`s to make it clear where the lifetime of the `Atom` comes from the allocator's lifetime.
2024-08-19 11:53:01 +00:00
overlookmotel
90d0b2ba65 refactor(allocator, ast, span, ast_tools): use allocator as var name for Allocator (#4900)
We mostly use `allocator` as var name for an `Allocator`, but in some places used the shorter name `alloc`. Use `allocator` everywhere for consistency.
2024-08-15 10:49:11 +00:00
DonIsaac
096ac7bee5 refactor(linter): clean up jsx-a11y/anchor-is-valid (#4831) 2024-08-12 01:11:54 +00:00
DonIsaac
b3c3125138 feat(linter): overhaul unicorn/no-useless-spread (#4791)
I got tired of seeing useless spreads on ternaries and `arr.reduce()` within my company's internal codebase so I overhauled this rule.

## Changes
- add fixer for object spreads
  ```js
  const before = { a, ...{ b, c }, d }
  const after = { a,  b, c, d } // fixer does not dedupe spaces before `b`
  ```
- recursively check for useless clones on complex expressions. This rule now catches and auto-fixes the following cases:
   ```js
  // ternaries when both branches create a new array or object
   const obj = { ...(foo ? { a: 1 } : { b: 2 }) }
  // recursive, so this can support complex cases
  const arr = [ ...(foo ? a.map(fn) : bar ? Array.from(iter) : await Promise.all(bar)) ]
  // reduce functions where the initial accumulator creates a new object or array
   const obj = { ...(arr.reduce(fn, {}) }
  ```
2024-08-10 04:50:09 +00:00
rzvxa
2e63618462 feat(span): implement CloneIn for the AST-related items. (#4729)
Follow-on after #4276, related to #4284.
2024-08-07 17:28:54 +00:00
overlookmotel
07607d3e94 feat(ast_codegen, span): process Span through ast_codegen (#4703)
Add `#[ast]` attr to `Span`.

Due to how AST codegen works, this necessitates putting the type def in a separate file. https://github.com/oxc-project/oxc/pull/4696#issuecomment-2271781995
2024-08-06 18:22:22 +00:00
overlookmotel
e1429e5ef1 refactor(span): reduce #[cfg_attr] boilerplate in type defs (#4702)
Similar to #4375 and #4698. #4696 added `#[ast]` attribute to types in `oxc_span`, so these types can use `#[serde]` attrs without the `#[cfg_attr(feature = "serialize", ...)]` guard.
2024-08-06 18:00:07 +00:00
rzvxa
125c5fd8ed feat(ast_codegen, span): process SourceType through ast_codegen. (#4696) 2024-08-06 17:42:12 +00:00
DonIsaac
6ff200d072 perf(linter): change react rules and utils to use Cow and CompactStr instead of String (#4603) 2024-08-03 21:26:08 +00:00
overlookmotel
54047e021c feat(ast): GetSpanMut trait (#4609)
Closes #4606.

Introduce `GetSpanMut` trait and implement it on all AST node types.

This has to be a separate trait, rather than adding `span_mut` method to `GetSpan` because `AstKind` implements `GetSpan`, and it only has an immutable `&` ref to AST node it contains.
2024-08-02 11:50:24 +00:00