Commit graph

1477 commits

Author SHA1 Message Date
Jelle van der Waa
b867e5f16b
feat(linter/eslint-plugin-promise): implement catch-or-return (#5121)
Rule detail:

[link](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/catch-or-return.md)

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-31 17:04:06 +01:00
Jelle van der Waa
e5c755a7a6
feat(linter/promise): add spec-only rule (#5124)
Rule Detail:


[link](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/spec-only.md)

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-31 11:38:47 -04:00
dalaoshu
1967c6730b
feat(linter/eslint): implement no-new-func (#5360)
Related to #479

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-31 11:37:03 -04:00
camc314
4c0861f694 feat(linter/unicorn): add fixer for prefer-type-error (#5311) 2024-08-31 05:17:47 +00:00
DonIsaac
180b1a17fb feat(ast): add Function::name() (#5361) 2024-08-31 03:45:45 +00:00
overlookmotel
afb038e93e refactor(linter): react/jsx_no_undef use loop instead of recursion (#5347) 2024-08-30 17:48:05 +00:00
overlookmotel
fe62687bf1 refactor(linter): simplify skipping JSX elements in unicorn/consistent_function_scoping (#5351)
Follow-on after #5223. We're trying to ignore JSX identifiers, so there's no point walking downwards from `JSXElementName`, as all we'll find is JSX identifiers that we want to ignore.
2024-08-30 15:11:50 +00:00
overlookmotel
381d9fe624 refactor(linter): shorten code in react/jsx_no_useless_fragment (#5350)
Shorten code. Also do the enum match first, as its cheaper than a string comparison.
2024-08-30 15:06:46 +00:00
overlookmotel
f052a6d666 perf(linter): react/jsx_no_undef faster check for unbound references (#5349)
Follow-on after #5223.

Now that we are getting an `IdentifierReference` with a `reference_id`, we can use that ID for a faster lookup of whether the reference is bound or not.
2024-08-30 14:56:55 +00:00
overlookmotel
83b9a8240e
refactor(linter): fix indentation in nextjs/no_script_component_in_head rule (#5338) 2024-08-30 09:01:14 -04:00
overlookmotel
89f018889d
refactor(linter): improve docs for react/jsx_no_target_blank rule (#5342) 2024-08-30 09:00:43 -04:00
overlookmotel
05636b7725 perf(linter): avoid unnecessary work in jsx_a11y/anchor_is_valid rule (#5341)
Follow-on after #5223.

#5223 introduced the line `let span = jsx_el.opening_element.name.span();`. But the span is only needed when creating a diagnostic when the rule fails (cold path). Avoid the work of getting the span for the common case where the rule passes.
2024-08-30 12:52:39 +00:00
overlookmotel
57050ab16a refactor(linter): shorten code in jsx_a11y/aria_activedescendant_has_tabindex rule (#5340)
Shorten code which was introduced in #5223.
2024-08-30 12:17:09 +00:00
Dunqing
32f730085c feat(ast)!: add JSXElementName::IdentifierReference and JSXMemberExpressionObject::IdentifierReference (#5223)
close: #3528

part of #4746
2024-08-30 11:11:04 +00:00
Boshen
3ae94b8801
refactor(semantic): change build_module_record to accept &Path instead of PathBuf 2024-08-30 12:24:49 +08:00
camc314
b1037372b7 feat(linter): improve no-accumulating-spread (#5302)
VSCode has a couple violations. examples:

```
  x oxc(no-accumulating-spread): Do not spread accumulators in loops
    ,-[src/vs/workbench/services/textMate/common/TMGrammarFactory.ts:65:5]
 64 |                 let injections: string[] = [];
 65 |                 for (let i = 1; i <= scopeParts.length; i++) {
    :                 ^|^
    :                  `-- For this loop
 66 |                     const subScopeName = scopeParts.slice(0, i).join('.');
 67 |                     injections = [...injections, ...(this._injections[subScopeName] || [])];
    :                                   ^^^^^^|^^^^^^
    :                                         `-- From this spread
 68 |                 }
    `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/base/common/actions.ts:205:3]
 204 |         let out: IAction[] = [];
 205 |         for (const list of actionLists) {
     :         ^|^
     :          `-- For this loop
 206 |             if (!list.length) {
 207 |                 // skip
 208 |             } else if (out.length) {
 209 |                 out = [...out, new Separator(), ...list];
     :                        ^^^|^^
     :                           `-- From this spread
 210 |             } else {
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  help: It looks like you're spreading an `Array`. Consider using the `Array.push` or `Array.concat` methods to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/workbench/contrib/extensions/browser/extensionsActions.ts:302:3]
 301 |         let actions: IAction[] = [];
 302 |         for (const visibleActions of actionsGroups) {
     :         ^|^
     :          `-- For this loop
 303 |             if (visibleActions.length) {
 304 |                 actions = [...actions, ...visibleActions, new Separator()];
     :                            ^^^^^|^^^^
     :                                 `-- From this spread
 305 |             }
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
      ,-[src/vs/workbench/contrib/extensions/browser/extensionsActions.ts:1141:3]
 1140 |         let actions: IAction[] = [];
 1141 |         for (const menuActions of menuActionGroups) {
      :         ^|^
      :          `-- For this loop
 1142 |             actions = [...actions, ...menuActions, new Separator()];
      :                        ^^^^^|^^^^
      :                             `-- From this spread
 1143 |         }
      `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/workbench/contrib/extensions/browser/extensionsViews.ts:334:4]
 333 |             let actions: IAction[] = [];
 334 |             for (const menuActions of groups) {
     :             ^|^
     :              `-- For this loop
 335 |                 actions = [...actions, ...menuActions, new Separator()];
     :                            ^^^^^|^^^^
     :                                 `-- From this spread
 336 |             }
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

```
2024-08-29 14:17:44 +00:00
DonIsaac
9c22ce9c99 feat(linter): add hyperlinks to diagnostic messages (#5318)
Adds hyperlinks to diagnostic codes.

Diagnostics without codes will not have links. In practice, this means linter diagnostics have links, while semantic and parser diagnostics do not.

![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/OVwvhVoSj4tgQWTUipoY/11790a3a-7dfa-4c6d-be43-550d8b6370a9.png)

> notice the underline under the error code
2024-08-29 05:50:04 +00:00
oxc-bot
53ff3493ef
Release oxlint v0.9.1 (#5316)
## [0.9.1] - 2024-08-29

### Features

- 6633972 linter: Add fixer for `no-empty` (#5276) (camc314)
- a58e448 linter/eslint: Add fixer to `no-var` (#5144) (camc314)
- a6e9769 linter/jsx-a11y: Add `label-has-associated-control` (#5163)
(Billy Levin)
- c8e8532 linter/unicorn: Add fixer to `throw-new-error` (#5275)
(camc314)
- 7ccde4b linter/unicorn: Add fixer to `prefer-date-now` (#5147)
(camc314)

### Bug Fixes

- 76e86f8 linter: Eslint-plugin-unicorn prefer-spread wrong linter
suggestion on variables of type string (#5265) (Arian94)
- b39544e linter/jest: Fixer for `prefer-jest-mocked` creates invalid
LHS expressions (#5243) (camc314)
- 9953fa5 linter/no-null: Incorrect fixer for `NullLiteral` within
`ReturnStatement` (#5247) (Dunqing)
- 318479e linter/no-unused-vars: Mark the class/function in the new
expression as used (#5306) (magic-akari)

### Refactor

- fa1d460 linter: Clean up Fixer and Message (#5308) (DonIsaac)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-29 13:04:52 +08:00
cinchen
fdef8aec72
fix(linter): jest/vitest rule compat (#4797)
This pr is for jest/vitest compat and add another jest rule condition

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
Co-authored-by: Wang Wenzhe <mysteryven@gmail.com>
2024-08-29 11:04:00 +08:00
camc314
bb995f6361 feat(jsx-a11y/linter) add fixer for scope (#5310) 2024-08-29 00:51:00 +00:00
camc314
e5ead86d43 feat(linter) catch more cases for misrefactored-assign-op (#5309)
changes from using `without_parenthesis` to using `get_inner_expression` to ignore type casts, non null assertions ect.

this helps catch more error cases
2024-08-29 00:47:38 +00:00
DonIsaac
fa1d460852 refactor(linter): clean up Fixer and Message (#5308)
- refactor(linter): clean up Fixer and Message
- perf(linter): replace sort_by_key with sort_unstable_by_key in fixer
2024-08-28 23:19:46 +00:00
magic-akari
318479ec4d
fix(linter/no-unused-vars): mark the class/function in the new expression as used (#5306)
Fix: #5274
2024-08-28 13:38:16 -04:00
camc314
6633972663 feat(linter): add fixer for no-empty (#5276)
adds a suggestion for `no-empty` eslint lint rule
2024-08-28 15:06:29 +00:00
Arian94
76e86f80df
fix(linter): eslint-plugin-unicorn prefer-spread wrong linter suggestion on variables of type string (#5265)
fixes #5248.

Similar issue found in here:
https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1147
2024-08-28 09:26:44 +01:00
Kevin Deng 三咲智子
234a24c14d
fix(ast)!: merge UsingDeclaration into VariableDeclaration (#5270)
relate #2854
2024-08-28 11:26:05 +08:00
camc314
d6b84ec44e fix(linter) bug in fixer for no-null (#5273)
i tested this in the microsoft/vscode repo and there were no syntax errors after running the fixer 🎉

hopefully this is the last fix.
2024-08-28 02:14:38 +00:00
camc314
c8e85323cb feat(linter/unicorn): add fixer to throw-new-error (#5275)
got merged into the wrong branch (https://github.com/oxc-project/oxc/pull/5148), hence setting to merge when ready (as was already approved)
2024-08-27 20:51:35 +00:00
Dunqing
9953fa54a4 fix(linter/no-null): incorrect fixer for NullLiteral within ReturnStatement (#5247)
close: #5194

It’s a long time no contributed to Linter, I'd like to try it
2024-08-27 03:51:56 +00:00
Billy Levin
a6e97690a7
feat(linter/jsx-a11y): add label-has-associated-control (#5163) 2024-08-26 23:33:55 -04:00
camc314
b39544e0f2 fix(linter/jest): fixer for prefer-jest-mocked creates invalid LHS expressions (#5243)
closes #5228

interestingly `eslint-plugin-jest` reports an error on this code, it also immedietly fixes it.
however fixing here is not good as it results in invalid code.

should fix https://github.com/oxc-project/oxlint-ecosystem-ci/actions/runs/10518058484/job/29247525457
2024-08-27 00:42:01 +00:00
camc314
9f772c9872 fix(linter) bug in fixer for func-names when function name is shadowed (#5231)
closes #5229
2024-08-26 14:32:42 +00:00
camc314
7ccde4b853 feat(linter/unicorn): add fixer to prefer-date-now (#5147) 2024-08-26 14:05:01 +00:00
camc314
a58e44845f feat(linter/eslint): add fixer to no-var (#5144) 2024-08-26 13:59:26 +00:00
oxc-bot
2a001a043c
Release oxlint v0.9.0 (#5219)
## [0.9.0] - 2024-08-26

- 5946748 linter: [**BREAKING**] Parse and display syntax errors for
regular expressions (#5214) (Boshen)

- b894d3b linter: [**BREAKING**] Make `no-unused-vars` correctness
(#5081) (DonIsaac)

### Features

- 1ce9630 linter/config: Implement FromIterator for LintPluginOptions
(#5102) (DonIsaac)
- 34bfaf6 linter/react: Add fixer to `jsx-props-no-spread-multi` (#5145)
(camc314)
- 982bd6e linter/unicorn: Add fixer to `require-array-join-separator`
(#5152) (camc314)
- a6704bd linter/unicorn: Add fixer to `prefer-set-size` (#5149)
(camc314)
- ac7edcc linter/unicorn: Add fixer to `prefer-array-some` (#5153)
(camc314)
- 1d01aa3 linter/unicorn: Add partial fixer for `prefer-array-flat`
(#5143) (camc314)
- 22d57f9 linter/unicorn: Add fixer to `prefer-string-slice` (#5150)
(Cameron)
- 2fe4415 linter/unicorn: Add fixer to `no-redundant-roles` (#5146)
(Cameron)
- d35c6f5 linter/unicorn: Add fixer to `prefer-regexp-test` (#5151)
(Cameron)
- 27db769 linter/unicorn: Add fixer to `text-encoding-identifier-case`
(#5154) (Cameron)
- f7958c4 linter/unicorn: Add prefer-structured-clone (#5095) (Jelle van
der Waa)
- 004ffa0 linter/vitest: Implement `prefer-each` (#5203) (dalaoshu)

### Bug Fixes

- aaaf26c linter: Error in fixer for prefer-to-have-length (#5197)
(dalaoshu)
- 1f5b6b6 linter: Bug in fixer for prefer-to-have-length (#5164)
(dalaoshu)
- 7eb052e linter: `no-hex-escape` fixer removing regex flags (#5137)
(Cameron)
- 76c66b4 linter/max-lines: Point span to end of file for disable
directive to work (#5117) (Boshen)
- 8ff6f2c linter/no-unused-vars: Panic on UsingDeclarations (#5206)
(DonIsaac)
- d29042e linter/no-unused-vars: Function expression in implicit arrow
function return (#5155) (DonIsaac)
- 36e4a28 linter/no-unused-vars: Panic in variable declarator usage
checks (#5160) (DonIsaac)
- ba62a71 linter/react: Fixed false positive with missing key inside
React.Children.toArray() for fragments (#5133) (Earl Chase)
- fd1031a linter/unicorn: Breaking fixer in case statements for
`no-null` (#5176) (DonIsaac)
- 7b86ed6 linter/unicorn: Handle type casts and parens in `no-null`
(#5175) (Don Isaac)
- b629e16 linter/unicorn: Improve diagnostic message for `no-null`
(#5172) (DonIsaac)

### Performance
- ce454cf Use simdutf8 to validate UTF-8 when reading files (#5196)
(dalaoshu)

### Refactor

- 543cad6 codegen: Remove some pub APIs (Boshen)
- 0d3661a linter: Remove meaningless `span0` (#5209) (dalaoshu)
- 2a91ef1 linter: `eslint/no_redeclare` rule use `run_on_symbol` not
`run_once` (#5201) (overlookmotel)
- 33599b0 linter: Split options into multiple files (#5101) (DonIsaac)
- 7ab6152 linter/unicorn: Clean up `no-null` (#5174) (DonIsaac)

### Testing

- a877e5a linter/no-unused-vars: Ensure type annotations on property
accessors are considered used (#5183) (DonIsaac)
- 7886618 linter/unicorn: Add fixer tests for `no-null` (#5173)
(DonIsaac)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-26 16:50:15 +08:00
Boshen
5946748ca6 feat(linter)!: parse and display syntax errors for regular expressions (#5214)
cc @leaysgur shipping to production!

This is marked as breaking change because there may be false positives.
2024-08-26 05:23:45 +00:00
dalaoshu
0d3661a23c
refactor(linter): remove meaningless span0 (#5209)
Yes. Those were added due to a code mod. the number suffixes were to
avoid name collisions.

_Originally posted by @DonIsaac in
https://github.com/oxc-project/oxc/pull/5203#discussion_r1730578314_
2024-08-26 12:29:45 +08:00
dalaoshu
004ffa082c
feat(linter/vitest): implement prefer-each (#5203)
Related to #4656

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-08-25 23:00:13 -04:00
dalaoshu
ce454cf426
perf: use simdutf8 to validate UTF-8 when reading files (#5196)
closes #5191

---------

Co-authored-by: overlookmotel <j@dummett.org>
2024-08-26 10:14:21 +08:00
overlookmotel
2a91ef10ea refactor(linter): eslint/no_redeclare rule use run_on_symbol not run_once (#5201)
`eslint/no_redeclare` rule iterates over all symbols. Use `run_on_symbols` for this, instead of `run_once`.
2024-08-25 21:40:58 +00:00
DonIsaac
8ff6f2cb86 fix(linter/no-unused-vars): panic on UsingDeclarations (#5206)
Closes #5202
2024-08-25 21:26:45 +00:00
camc314
982bd6ecb7 feat(linter/unicorn): add fixer to require-array-join-separator (#5152) 2024-08-25 21:07:17 +00:00
camc314
a6704bd293 feat(linter/unicorn): add fixer to prefer-set-size (#5149) 2024-08-25 21:04:10 +00:00
dalaoshu
aaaf26cee4
fix(linter): error in fixer for prefer-to-have-length (#5197)
closes #5195
2024-08-25 17:13:56 +01:00
camc314
ac7edccab3 feat(linter/unicorn): add fixer to prefer-array-some (#5153) 2024-08-25 13:25:12 +00:00
Boshen
543cad6370
refactor(codegen): remove some pub APIs 2024-08-25 13:32:55 +08:00
DonIsaac
a877e5a612 test(linter/no-unused-vars): ensure type annotations on property accessors are considered used (#5183) 2024-08-25 01:02:51 +00:00
camc314
1d01aa316f feat(linter/unicorn): add partial fixer for prefer-array-flat (#5143) 2024-08-24 22:58:38 +00:00
DonIsaac
fd1031abeb fix(linter/unicorn): breaking fixer in case statements for no-null (#5176) 2024-08-24 22:24:10 +00:00
Don Isaac
7b86ed61d1
fix(linter/unicorn): handle type casts and parens in no-null (#5175) 2024-08-24 18:18:52 -04:00