Commit graph

2349 commits

Author SHA1 Message Date
Boshen
35e3b0f1cb
fix(transformer): fix incorrect jsx whitespace text handling (#2969) 2024-04-14 18:40:40 +08:00
Wang Wenzhe
5b02ae1175
feat(linter/tree-shaking): support ConditionalExpression (#2965) 2024-04-14 13:41:44 +08:00
Wang Wenzhe
da5ea411dd
feat(linter/tree-shaking): support Class (#2964) 2024-04-14 13:39:27 +08:00
Boshen
bd9fc6d169
feat(transformer): react jsx transform (#2961) 2024-04-14 10:50:17 +08:00
Cameron
01e64bf64d
feat(linter) eslint-plugin-unicorn no await in promise methods (#2963) 2024-04-14 10:44:36 +08:00
Cameron
98a3acd8b5
feat(linter) eslint-plugin-unicorn no single promise in promise methods (#2962)
part of #684
2024-04-14 10:39:12 +08:00
Miles Johnson
e67355045e
feat(transformer): start on TypeScript annotation removal (#2951) 2024-04-13 18:49:54 +08:00
Boshen
93ce5a919a
chore: fix internal doc warnings 2024-04-13 15:59:24 +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
063b281c39
feat(allocator): make Box's PhantomData own the passed in T (#2952) 2024-04-13 12:31:40 +08:00
Boshen
e651e50bda
feat(transformer): add the most basic plugin toggles (#2950) 2024-04-12 20:25:34 +08:00
Boshen
60ccbb105c
refactor(transformer): clean up some code (#2949) 2024-04-12 20:23:44 +08:00
Boshen
14754777a4
feat(transformer): implement react-jsx-source (#2948) 2024-04-12 20:21:54 +08:00
branchseer
f159f60084
Make ast types covariant over the allocator lifetime. (#2943)
## Why

Due to the usage of `&'alloc mut T` in `oxc_allocator::Box`, and
`bumpalo::collections::Vec` in `oxc_allocator::Vec`, ast types are
currently invariant over their allocator lifetime `'a`. This prevents
`ouroboros` from generating `borrow_*` on ast type fields, leading to
the unfriendly `with_*` api:
c250b288ef/crates/oxc_parser/examples/multi-thread.rs (L82-L84)

## How

- For `oxc_allocator::Vec`, switch to `allocator_api2::vec::Vec`, which
has a covariant relationship with the allocator lifetime.
- For `oxc_allocator::Box`, use `std::ptr::NonNull` which is
specifically designed to be covariant. I don't use
`allocator_api2::boxed::Box` because it holds the allocator for
dropping, so the size is bigger.

## Downside

Now that `oxc_allocator::Box` uses the unsafe `NonNull`. It has to be a
private field to be safe. This make it impossible to do `Box(....)`
pattern matching.
2024-04-12 18:12:18 +08:00
Boshen
f903a225a8
feat(transformer): implement react-jsx-self (#2946) 2024-04-12 18:08:36 +08:00
Yuji Sugiura
ba2121f17d
feat(linter): Add --jsdoc-plugin flag (#2935)
Add flag to:

```sh
$ oxlint --jsdoc-plugin
```


![image](https://github.com/oxc-project/oxc/assets/6259812/0e12ceab-966f-47e1-b4b9-5bc2eb6bdb56)
2024-04-12 10:39:12 +08:00
Boshen
0c04bf743f
feat(transformer): transform TypeScript namespace (#2942) 2024-04-12 10:19:13 +08:00
Boshen
c250b288ef
fix(cli): return error if --format receives an unknown value 2024-04-11 21:38:39 +08:00
Boshen
3419306ac0
feat(transformer): add filename (#2941) 2024-04-11 18:43:51 +08:00
Boshen
614f73b66c
Release crates v0.12.3 2024-04-11 16:18:17 +08:00
Boshen
98bf7e6767
fix(cli): fix oxlint --format json yields 0 files to lint (#2940)
closes #2930
2024-04-11 16:03:31 +08:00
Boshen
02adc76760
feat(transformer): implement plugin-transform-react-display-name top-down (#2937)
Missing case:


https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-display-name/test/fixtures/display-name/nested/input.js

```js
var foo = qux(createReactClass({}));
var bar = qux(React.createClass({}));
```

This requires recursing down.

Top-down implementation in swc:


67ec5e09b9/crates/swc_ecma_transforms_react/src/display_name/mod.rs (L108-L132)

Or bottom-up in babel:


08b0472069/packages/babel-plugin-transform-react-display-name/src/index.ts (L87-L98)
2024-04-11 15:32:32 +08:00
Boshen
59748199da
refactor(ast): clean up the ts type visit methods 2024-04-11 15:26:24 +08:00
Brad Zacher
6c0090882f
feat(oxc_ast): add missing ast visits for types (#2938)
Fixes #2936

*personally* I think it's best if all of the `_ => {}` match cases were
removed from the codebase so that things are provably exhaustive.
This does exactly that specifically for `walk_ts_type` - filling in the
missing cases and all the required code for them.
2024-04-11 07:11:00 +00:00
cinchen
6757dbab8a
feat(linter): eslint-plugin-jest/prefer-lowercase-title (#2911)
part of https://github.com/oxc-project/oxc/issues/492

Rule Detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/prefer-lowercase-title.ts)
2024-04-10 21:56:56 +08:00
Todor Andonov
b4b471f4cf
feat(linter): typescript-eslint/consistent-type-definitions (#2885)
Co-authored-by: wenzhe <mysteryven@gmail.com>
2024-04-10 21:09:05 +08:00
Boshen
255c74ccc5
feat(transformer): add transform context to all plugins (#2931) 2024-04-10 14:49:00 +08:00
Yuji Sugiura
0a77d621e2
refactor(semantic/jsdoc): Rework JSDoc struct for better Span handling (#2917)
> The error message emphasizes "empty text" so I would put the span on
the extra text.
> https://github.com/oxc-project/oxc/pull/2893#discussion_r1548843621

To address this, special `Span` handling should be implemented for
comment part.

So, this PR introduces:

- `JSDocCommentPart` struct holds raw `.span` and special
`.span_trimmed_first_line()`
- Add `JSDocKindPart`, `JSDocTypePart` and `JSDocTypeNamePart` in the
same manner
  - `JSDocTag` uses these depending on the purpose
2024-04-10 14:32:51 +08:00
Boshen
79ca6feca9
feat(transformer): add transform callback methods (#2929)
For milestone 1, I think it's safe to just layout all the
transformations manually.


In TypeScript, the transformers are collected dynamically and ran on
each ast node; this achieves a single AST pass.
https://github.com/microsoft/TypeScript/blob/main/src/compiler/transformer.ts#L129-L145

To maximize performance and reduce confusion, I think it's safe to
layout all the transformations manually for milestone 1.

The next PR will add transformation context to all presets so we can
start adding "context".
2024-04-10 11:06:49 +08:00
underfin
8662f4f613
feat(sourcemap): add x_google_ignoreList (#2928) 2024-04-09 20:55:04 +08:00
underfin
5cb3991b67
feat(sourcemap): add sourceRoot (#2926) 2024-04-09 15:42:23 +08:00
Kalven Schraut
6eba02f472
fix(cli): if format is json do not print summary information (#2899) (#2925)
this allows the ability to redirect the stdout to so can create a valid
json file

this also matches with eslint's format option

closes #2899
2024-04-09 14:26:10 +08:00
Boshen
d65eab3b8b
feat(transformer): add react preset (#2921) 2024-04-09 12:39:33 +08:00
John Daly
5abbb0cada
fix(linter): import/no-cycle ignore type-only imports (#2924)
A fix for the work done in: https://github.com/oxc-project/oxc/pull/2905

The existing code checks if _all_ import entries in a ModuleRecord are
type-only, when determining if the ModuleRecord should be skipped when
checking for cycles. This is incorrect.

To demonstrate the problem: Running the `no-cycles` rule, with
`ignoreTypes` enabled, on the following example code will cause a cycle
to be reported between Module A and Module B

```typescript
// Module A
import type { Bar } from './b';
import { Baz } from './c'

// Module B
import type { Foo } from './a';

// Module C
export const Baz = 'baz';
```

The reason this is happening is because the import to Module C in Module
A is causing the `was_imported_as_type` variable to evaluate to `false`,
since the Module C import is not type-only.

What we actually want to do is skip visiting Module B entirely, by
checking if its import request from Module A is type-only.

This PR fixes the logic so that only the import entries for the next
ModuleRecord are considered when determining `was_imported_as_type`.
2024-04-09 12:38:15 +08:00
Wang Wenzhe
990eda61d7
feat(linter/tree-shaking): support part BinaryExpression (#2922) 2024-04-09 12:33:51 +08:00
Boshen
09452659e2
Release crates v0.12.2 2024-04-08 11:13:13 +08:00
renovate[bot]
cd6f4f1938
chore(deps): lock file maintenance rust crates (#2913) 2024-04-08 02:49:53 +00:00
underfin
96f02e6e21
feat(sourcemap): optional JSONSourceMap fileds (#2910)
Support optional JSONSourceMap fileds to support js side complex typing.
2024-04-07 23:32:12 +08:00
underfin
d87cf179a6
feat(sourcemap): add methods to mutate SourceMap (#2909) 2024-04-07 23:30:16 +08:00
underfin
74aca1c937
feat(sourcemap): add SourceMapBuilder file (#2908) 2024-04-07 23:29:25 +08:00
John Daly
6de1b77b1b
feat(linter/import): Add ignoreTypes option for the import/no-cycle rule (#2905)
Fixes: https://github.com/oxc-project/oxc/issues/2904

Adds an `ignoreTypes` option for the `import/no-cycle` rule, to ignore
imports that don't have any runtime effect.
2024-04-07 05:07:45 +00:00
Kalven Schraut
79e2c95e2d
fix(linter): handle self closing script tags in astro partial loader (#2017) (#2907)
Added tests to figure out what the problem from the issue was and
realize the self closing tag was not expected. Added code to handle this
case.

I am not that familiar with astro to know how common self closing script
tags are, their docs seem to use an opening and closing one for inline
scripts
https://docs.astro.build/en/guides/client-side-scripts/#load-external-scripts
2024-04-07 13:02:09 +08:00
Kalven Schraut
1cd5e7511b
fix(linter): svelte partial loader handle generics (#2875) (#2906)
While looking into this, I knew vue would have similar problems. Which
then led me to realize the generic case was handled already so I tried
abstract out the function so both the vue and svelte partial loaders
could reuse the code. Finally added some svelte test cases to prove this
resolved the issue.

I am a bit new to rust so if there was a better way to reuse the
find_script_closing_angle function open to suggestions.
2024-04-07 13:00:55 +08:00
Wang Wenzhe
b053d54b6f
feat(linter/tree-shaking): support try-catch and AwaitExpression (#2902) 2024-04-06 14:02:42 +08:00
Wang Wenzhe
59869d0a96
feat(linter/tree-shaking): check this in different environment (#2901) 2024-04-06 13:58:47 +08:00
Denis Gonchar
acb6eb2573
feat(linter): @typescript-eslint/prefer-for-of (#2789) 2024-04-06 13:31:31 +08:00
Don Isaac
1ea24ea0a7
fix(semantic): symbols inside functions and classes incorrectly flagged as exported (#2896)
# What This PR Does

Symbols declared inside exported functions and classes were being
incorrectly flagged with `SymbolFlags::Export`.

For example,
```ts
export function foo<T>(a: T) {
  let b = String(a)
  return b
}
```
`T`, `a`, and `b` were all flagged as exported.

## Further Work
It doesn't seem like exported enums and interfaces are being included in
`ModuleRecord`. Am I looking in the wrong place, or are they actually
missing?
2024-04-05 23:01:27 +08:00
Yuji Sugiura
aa63b6491f
feat(linter): Implement jsdoc/check-access (#2642)
Part of #1170, Finally... 🗻 

Some preparation PRs may be needed in advance.

- [x] settings.jsdoc #2706 
- [x] new struct design #2765
- [x] handle `Span` for diagnostics #2815

Implement plugin itself.

-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-access.md
-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/src/rules/checkAccess.js

I'll send a PR to make this plugin public after confirming that a few
more rules can be implemented without any problems.
2024-04-04 22:36:39 +08:00
Yuji Sugiura
6823482ad6
feat(linter): Implement jsdoc/empty-tags (#2893)
Part of #1170 

-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/empty-tags.md
-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/src/rules/emptyTags.js
2024-04-04 10:33:33 +08:00