Commit graph

2413 commits

Author SHA1 Message Date
kaykdm
c70a065191
feat(linter): eslint-plugin-next: no-head-element (#2006)
Part of: https://github.com/oxc-project/oxc/issues/1929

Based on:

- code: https://github.com/vercel/next.js/blob/canary/packages/eslint-plugin-next/src/rules/no-head-element.ts
- test: https://github.com/vercel/next.js/blob/canary/test/unit/eslint-plugin-next/no-head-element.test.ts
- doc: https://nextjs.org/docs/messages/no-head-element

---------

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-01-13 17:47:32 +00:00
kaykdm
8f0f824a6a
feat(linter): eslint-plugin-next: no-typos (#1978)
Part of: https://github.com/oxc-project/oxc/issues/1929

Based on:
https://github.com/vercel/next.js/blob/canary/packages/eslint-plugin-next/src/rules/no-typos.ts
2024-01-13 17:42:11 +00:00
Dunqing
ac4b3a4f8d
feat(ast): visit TSTypeQuery (#2021)
```ts
type Bar = typeof Foo;
```
2024-01-14 00:38:18 +08:00
magic-akari
9b77d0e6e6
fix(prettier): Correctly print export declaration (#2014)
Before this PR:
<img width="912" alt="image"
src="https://github.com/oxc-project/oxc/assets/7829098/78605f25-3320-4bed-8a31-3ffa7604cdc7">

https://oxc-project.github.io/oxc/playground/?code=3YCAAICUgICAgICAgICyHorESipoTXBToMuz4zZHvH%2B4MPS3Y6F%2FfvvogA%3D%3D
2024-01-13 21:26:33 +08:00
Dunqing
6c7f983de5
feat(transformer/typescript): remove export specifier that import_kind is type (#2015) 2024-01-13 21:25:59 +08:00
magic-akari
869643b03b
fix(prettier): Correctly format call expression arguments (#2018) 2024-01-13 21:25:26 +08:00
Yuji Sugiura
04540f749d
feat(linter): eslint-plugin-jsx-a11y click-events-have-key-events (#1976)
( #1974  was lost due to mishandling. 🙈 )

Part of #1141 

### Refs
-
4c7e7815c1/docs/rules/click-events-have-key-events.md
-
4c7e7815c1/src/rules/click-events-have-key-events.js
-
4c7e7815c1/__tests__/src/rules/click-events-have-key-events-test.js

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-01-13 09:27:26 +00:00
Dunqing
ead4e8df1f
feat(transformer/typescript): remove import if only have type reference (#2001) 2024-01-13 08:52:14 +00:00
Boshen
b386177af2
refactor(linter): move away from tuples for test cases (#2011)
closes #1956
2024-01-13 16:23:16 +08:00
Boshen
1886a5b838
perf(parser): reduce Token size from 16 to 12 bytes (#2010)
I also had to change how the string for private identifiers are built,
otherwise they will always be allocated.
2024-01-13 12:42:39 +08:00
overlookmotel
6996948825
refactor(parser): remove extraneous code from regex parsing (#2008)
This PR removes some code in parsing regexp flags which is extraneous:

```rs
if !ch.is_ascii_lowercase() {
  self.error(diagnostics::RegExpFlag(ch, self.current_offset()));
  continue;
}
```

Which is followed by:

```rs
let flag = if let Ok(flag) = RegExpFlags::try_from(ch) {
  flag
} else {
  self.error(diagnostics::RegExpFlag(ch, self.current_offset()));
  continue;
};
```

`!ch.is_ascii_lowercase()` is equivalent to `ch < 'a' || ch > 'z'`. The
compiler implements `RegExpFlags::try_from(ch)` as `ch < 'd' || ch >
'y'` and then a jump table. So `ch.is_ascii_lowercase()` does nothing
that `RegExpFlags::try_from(ch)` doesn't do already.

https://godbolt.org/z/51GPPY9nx

(this PR built on top of #2007 for ease)
2024-01-13 02:34:05 +00:00
Cameron
107a32ea48
fix(linter): fix false positive for erasing-op in 0/0 case (#2009) 2024-01-13 10:32:26 +08:00
overlookmotel
712e99cf9b
fix(parser): restore regex flag parsing (#2007)
As discussed in
https://github.com/oxc-project/oxc/pull/1999#issuecomment-1888916383,
this PR restores some of regex parsing behavior to as it was prior to
#1926.
2024-01-13 03:19:33 +08:00
Boshen
1ecdeaa662
fix(MAINTENANCE): fix publish ordering 2024-01-12 23:39:35 +08:00
Boshen
61f37ea973
Publish crates v0.5.0 2024-01-12 23:33:47 +08:00
Boshen
feceac9388
chore(minifier,semantic): don't publish tests directory 2024-01-12 22:37:11 +08:00
Boshen
e621e9b843
Release oxlint and vscode extension v0.2.0 2024-01-12 22:29:25 +08:00
Boshen
c342875b55
chore(linter): change react/no-unknown-property to restriction
There's a lot of false positives in non-standard jsx usages.

For example the usage of `css` or `class` attribute.
2024-01-12 20:44:04 +08:00
Boshen
aa91fde1d9
refactor(parser): only allocate for escaped template strings (#2005) 2024-01-12 18:56:36 +08:00
Boshen
38f86b0cac
refactor(parser): remove string builder from number parsing (#2002)
The builder was used to build an allocated string for numbers with
underscores, this is no longer required because it is now allocated on
demand.


0d77e1e788/crates/oxc_parser/src/lexer/number.rs (L32)
2024-01-12 17:01:51 +08:00
Boshen
39f026f3e2
chore(benchmark): remove custom allocators because they are flaky (#2004) 2024-01-12 16:05:47 +08:00
underfin
0d77e1e788
fix: default visitor should visit prop init at visit_object_property (#2000)
The `visit_object_property` should visit `prop.int` node.
2024-01-12 13:43:12 +08:00
Dunqing
6a7e4be06c
feat(transformer): call enter_node/leave_node in visit_xxx (#1990) 2024-01-12 11:37:17 +08:00
overlookmotel
c7316856db
refactor(parser): reduce work parsing regexps (#1999)
#1926 produced a small performance regression because when parsing a
regexp, some work is repeated.
2024-01-12 11:36:30 +08:00
Boshen
74dfa3be8b
fix(webpack): update pnpm lock file 2024-01-12 11:30:51 +08:00
Dunqing
0a086860da
feat(ast): visit TSModuleReference (#1998)
### Failed cases:

* 7c29fbc4db/packages/babel-plugin-transform-typescript/test/fixtures/imports/elision-qualifiedname/input.ts
* 7c29fbc4db/packages/babel-plugin-transform-typescript/test/fixtures/imports/elide-react/input.ts

We need to distinguish whether a reference is a type or a js variable
2024-01-11 23:29:29 +08:00
Dunqing
afb2c501f5
feat(transformer): support for transform TSImportEqualsDeclaration (#1994) 2024-01-11 23:24:28 +08:00
luhc228
b1de10fbfd
docs: fix oxc-parser README demo error (#1993)
The type of `ret.program` is `string`, it need to parse it first to get
the `body`.
2024-01-11 23:19:09 +08:00
cin
d51c9f19f9
feat(linter): eslint-plugin-jest: no-test-return-statement (#1979)
Rule Detail:
[link](https://github.com/eryue0220/eslint-plugin-jest/blob/main/src/rules/no-test-return-statement.ts)
2024-01-11 23:01:52 +08:00
Boshen
ea22d3ceb8
fix(diagnostics): always print without considering the --max-warnings option (#1996)
closes #1958

`--max-warnings` is only used to control the exit code, it does not
affect diagnostic printing.
2024-01-11 20:41:06 +08:00
RiESAEX
ef67e08c6a
fix(playground): correct diagnostic position (#1995)
before

![image](https://github.com/oxc-project/oxc/assets/89718456/bca4d61e-b45f-4523-ab02-ccabfb761abc)
after

![image](https://github.com/oxc-project/oxc/assets/89718456/6fc7e41f-a985-417e-975f-66bc9af29498)
2024-01-11 20:23:16 +08:00
Boshen
fb5d0a740c
feat(linter): add support for same rule name but different plugin names (#1992)
e.g.

```
{
  "rules": {
    "semi": "off",
    "@typescript-eslint/semi": "error"
  }
}
```

closes #1975
2024-01-11 18:05:05 +08:00
Boshen
b7ea4e53fb
feat(linter): support vue generic component (#1989)
closes #1938
2024-01-11 15:48:56 +08:00
Dunqing
4e7b7dad78
feat(task): handle expected runtime error correctly (#1987) 2024-01-11 15:04:28 +08:00
Dunqing
6417d2ce9c
feat(task): test codegen runtime in run_async (#1980)
<img width="460" alt="image" src="https://github.com/oxc-project/oxc/assets/29533304/4f2d05a1-4d3e-422e-9722-0c77d4ff989d">
2024-01-11 14:59:29 +08:00
Dunqing
ee286a0a48
feat(task): support run async in suite (#1973) 2024-01-11 14:54:30 +08:00
Dunqing
633b21c5d2
feat(task): skips some cases we don't care about in codegen-runtime (#1986)
#1977
2024-01-11 14:50:39 +08:00
Boshen
0f6674563e
chore: remove DSL based linter plugin (#1985)
Due to maintenance issues, we are going to stop exploring a linter based
DSL plugins.
2024-01-11 04:54:39 +00:00
fi3ework
e0da12a868
fix(linter): allow eslintrc to add rule when overriding (#1984)
Fix a bug introduced in https://github.com/oxc-project/oxc/pull/1966.
Ideally, the rules in eslintrc should be merged into final rules as
described:

> The rules will start with the categories we apply, and then merge all
the configurations stated in the rules field.
>
> For example, if we begin with -D correctness with 80 rules, then
>
> "no-empty-file": "off" will remove the rule, yielding 79 rules
> "no-empty": "error" (restriction) will add the rule, yield 81 rules
> ""no-empty": ["error", { "allowEmptyCatch": true }]` add the rule's
configuration

However, the implementation did not include the newly added rules in the
eslintrc. As a test case and example, I added a new fixture to
`crates/oxc_cli/fixtures/no_undef`. No warn or deny will be found
without this PR.

This is my first Rust PR ever. Any nitpicking suggestions are welcome.
Thanks! 😊
2024-01-11 11:43:02 +08:00
kaykdm
c5887bcb2b
feat(linter): implement @typescript-eslint/triple-slash-reference (#1903)
implement @typescript-eslint/triple-slash-reference
Related issue: https://github.com/oxc-project/oxc/issues/503

original
- doc:
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/triple-slash-reference.md
- code:
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/triple-slash-reference.ts
2024-01-11 11:12:46 +08:00
Maurice Nicholson
d4acd140ad
fix(linter): jsx-key: handle anonymous functional components in arrays that have a function body (#1983)
Closes #1982
2024-01-10 22:46:17 +00:00
underfin
78b427bc50
feat(transform): support es2015 new target (#1967)
Here implementing the es2015 new target transform, see detail at
https://babel.dev/docs/babel-plugin-transform-template-new-target.

Here has three kinds need to be distinguished.

- `NewTargetKind::Method`, it from `AstKind::ObjectMethod` or
`AstKind::MethodDefinitionKind::Get/Set/Method`. It will be transformed
to `void 0`.
- `NewTargetKind::Constructor`, is from `
AstKind::MethodDefinitionKind::Constructor`. It will be transformed to
`this.constructor`.
- `NewTargetKind::Function`, is from ` AstKind::Function`, here the
function is not the above function. It will be transformed to `this
instanceof _target ? this.constructor : void 0`, here `_target` comes
from the function name or is created by scope uid ident.
2024-01-10 23:59:56 +08:00
Yuto Yoshino
ac704cce14
feat(linter): eslint-plugin-jsx-a11y autocomplete-valid (#1901)
Part of: https://github.com/oxc-project/oxc/issues/1141

Based on:
- doc: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/autocomplete-valid.md
- code: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/autocomplete-valid.js
- test: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/__tests__/src/rules/autocomplete-valid-test.js
2024-01-10 10:17:33 +00:00
Dunqing
fc7dbd9225
feat(task): codegen test262 runtime test (#1959) 2024-01-10 17:12:11 +08:00
zhangrunzhao
40dbfae3c2
feat(linter): eslint-plugin-react: no-direct-mutation-state (#1892)
#1022 

Based on:
- code: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/no-direct-mutation-state.js
- doc: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
- test: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/tests/lib/rules/no-direct-mutation-state.js

Co-authored-by: 张润钊 <zhangrunzhao@bytedance.com>
2024-01-10 08:32:19 +00:00
Boshen
856b9a59eb
feat(linter): support overriding oxlint rules by eslint config (#1966)
Previously if .eslintrc.json contains 

```
{
  "rules": {
    "no-empty": "off"
  }
}
```

Then no rules will be enabled.

---

This PR changes how we configure oxlint's rules.

The rules will start with the categories we apply, and then merge all
the configurations stated in the `rules` field.

For example, if we begin with `-D correctness` with 80 rules, then

* `"no-empty-file": "off"` will remove the rule, yielding 79 rules
* `"no-empty": "error"` (restriction) will add the rule, yield 81 rules
* ""no-empty": ["error", { "allowEmptyCatch": true }]` add the rule's
configuration
2024-01-10 15:44:53 +08:00
Boshen
a6717db423
refactor(formatter,linter,codegen): remove oxc_formatter (#1968)
closes #1941
2024-01-10 06:41:20 +00:00
Hao Cheng
b5f4f1eb68
fix(linter): fix plugin name parsing when reading config file (#1972)
This PR fixes the plugin parsing logic when reading a config file.

Specifically, the plugin names defined in `RuleEnum`s use snake-case
("jsx_a11y") while in the config file they are written as "jsx-a11y".
This inconsistency causes some rules to be filtered out.

I tested the change with the config json file provided in #1969.
- Before the change: `Finished in 21ms on 1 file with 157 rules using 8
threads.`
- After the change: `Finished in 23ms on 1 file with 178 rules using 8
threads.`

Related issue: #1969
2024-01-10 11:46:56 +08:00
Cameron
64310fa9b1
refactor(linter): remove duplicate get_jsx_attribute_name (#1971) 2024-01-10 11:45:34 +08:00
kaykdm
78916703c5
feat(linter): eslint-plugin-react: require-render-return (#1946)
Related issue: https://github.com/oxc-project/oxc/issues/1022

Based on:
- doc: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-render-return.md
- code: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/require-render-return.js
2024-01-09 22:50:02 +00:00