Commit graph

1769 commits

Author SHA1 Message Date
Boshen
3b40fbdbac
fix(linter): false positive for filename_case where filename doesn't have a proper casing (#2032) 2024-01-15 14:36:48 +08:00
Boshen
68606c4d6d
fix(linter): keep rules disabled if the rule is not enabled in the config (#2031)
relates #1969
2024-01-15 05:32:51 +00:00
Bradley Farias
3490111c56
Commutative undefined minify (#2003)
this should probably be squashed, i'm not familiar with code commit
norms here. we can expand a bunch of the commutative compressions later.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-01-15 02:51:53 +00:00
Yuto Yoshino
530d1bea56
feat(linter): eslint-plugin-jsx-a11y no-redundant-roles rule (#1981)
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/no-redundant-roles.md
- code: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/no-redundant-roles.js
- test: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/__tests__/src/rules/no-redundant-roles-test.js
2024-01-14 21:03:58 +00:00
overlookmotel
b4d76f0b0d
refactor(parser): remove noop code (#2028)
This PR removes some code from the lexer which doesn't do anything.
2024-01-14 23:48:35 +08:00
keita hino
198f0e5d73
feat(linter): eslint-plugin-jsx-a11y aria-activedescendant-has-tabindex (#2012)
Part of: #1141

Based on:
- docs: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/aria-activedescendant-has-tabindex.md
- code: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/aria-activedescendant-has-tabindex.js
- test: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/__tests__/src/rules/aria-activedescendant-has-tabindex-test.js
2024-01-14 11:34:07 +00:00
overlookmotel
60a927d8f5
perf(parser): lexer match byte not char (#2025)
2 related changes to lexer's `read_next_token()`:

1. Hint to branch predictor that unicode identifiers and non-standard
whitespace are rare by marking that branch `#[cold]`.

2. The branch is on whether next character is ASCII or not. This check
only requires reading 1 byte, as ASCII characters are always single byte
in UTF8. So only do the work of getting a `char` in the cold path, once
it's established that character is not ASCII and this work is required.
2024-01-14 18:50:11 +08:00
kaykdm
a356918d83
feat(linter): eslint-plugin-next: no-document-import-in-page (#1997)
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-document-import-in-page.ts
-  https://nextjs.org/docs/messages/no-document-import-in-page

---------

Co-authored-by: Cameron <cameron.clark@hey.com>
2024-01-13 17:52:47 +00:00
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
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
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
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
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
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
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
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
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
keita hino
8d9894ad40
fix(linter): Support cases where aria-hidden includes expressions (#1964)
The rule for
[jsx-a11y/img-redundant-alt](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/img-redundant-alt.md)
states that if aria-hidden is true, the rule will always succeed:

> The rule will first check if aria-hidden is true to determine whether
to enforce the rule. If the image is hidden, then rule will always
succeed.

The [img_redundant_alt
rule](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/jsx_a11y/img_redundant_alt.rs),
ported to Oxlint, was in an incompatible state because an error occurred
even when including aria-hidden={true}, as demonstrated below:
```jsx
// error
<img alt='photo of cool person' aria-hidden={true} />
```

This issue arose because the
[is_hidden_from_screen_reader](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/utils/react.rs#L77-L95),
responsible for obtaining the state of aria-hidden, was not handling
cases where aria-hidden includes expressions. This PR addresses the
situation by adding support for cases where expressions are passed to
aria-hidden.
2024-01-09 22:33:55 +00:00
Yuto Yoshino
2b7ca5962f
feat(linter): eslint-plugin-jsx-a11y role-has-required-aria-props (#1881)
partof: https://github.com/oxc-project/oxc/issues/1141

Based on:
- doc: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/role-has-required-aria-props.md
- code: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/role-has-required-aria-props.js
- test: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/__tests__/src/rules/role-has-required-aria-props-test.js
2024-01-09 15:21:11 +00:00
Boshen
4706765d2a
refactor(parser): reduce Token size from 32 to 16 bytes (#1962)
Part of #1880

`Token` size is reduced from 32 to 16 bytes by changing the previous
token value `Option<&'a str>` to a u32 index handle.

It would be nice if this handle is eliminated entirely because
the normal case for a string is always
`&source_text[token.span.start.token.span.end]`

Unfortunately, JavaScript allows escaped characters to appear in
identifiers, strings and templates. These strings need to be unescaped
for equality checks, i.e. `"\a"  === "a"`.

This leads us to adding a `escaped_strings[]` vec for storing these
unescaped and allocated
strings.

Performance regression for adding this vec should be minimal because
escaped strings are rare.

Background Reading:

* https://floooh.github.io/2018/06/17/handles-vs-pointers.html
2024-01-09 15:17:02 +08:00