Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 13 additions & 1 deletion src/docs/guide/usage/linter/generated-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ Example
"settings": {},
"rules": {
"eqeqeq": "warn",
"import/no-cycle": "error"
"import/no-cycle": "error",
"react/self-closing-comp": [
"error",
{
"html": false
}
]
},
"overrides": [
{
Expand Down Expand Up @@ -84,6 +90,12 @@ Predefine global variables.

Environments specify what global variables are predefined. See [ESLint's list of environments](https://eslint.org/docs/v8.x/use/configure/language-options#specifying-environments) for what environments are available and what each one provides.

## extends

type: `string[]`

Paths of configuration files that this configuration file extends (inherits from). The files are resolved relative to the location of the configuration file that contains the `extends` property. The configuration files are merged from the first to the last, with the last file overriding the previous ones.

## globals

type: `Record<string, string>`
Expand Down
29 changes: 21 additions & 8 deletions src/docs/guide/usage/linter/generated-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The progress of all rule implementations is tracked [here](https://github.com/oxc-project/oxc/issues/481).

- Total number of rules: 487
- Total number of rules: 500
- Rules turned on by default: 123

**Legend for 'Fixable?' column:**
Expand All @@ -13,7 +13,7 @@ The progress of all rule implementations is tracked [here](https://github.com/ox
- ⚠️💡: a dangerous suggestion is available for this rule
- 🚧: an auto-fix or suggestion is possible, but currently not implemented

## Correctness (173):
## Correctness (174):

Code that is outright wrong or useless.
| Rule name | Source | Default | Fixable? |
Expand Down Expand Up @@ -146,6 +146,7 @@ Code that is outright wrong or useless.
| [double-comparisons](/docs/guide/usage/linter/rules/oxc/double-comparisons.html) | oxc | ✅ | 🛠️ |
| [erasing-op](/docs/guide/usage/linter/rules/oxc/erasing-op.html) | oxc | ✅ | 💡 |
| [missing-throw](/docs/guide/usage/linter/rules/oxc/missing-throw.html) | oxc | ✅ | 💡 |
| [no-redundant-constructor-init](/docs/guide/usage/linter/rules/oxc/no-redundant-constructor-init.html) | oxc | ✅ | 🚧 |
| [number-arg-out-of-range](/docs/guide/usage/linter/rules/oxc/number-arg-out-of-range.html) | oxc | ✅ | |
| [only-used-in-recursion](/docs/guide/usage/linter/rules/oxc/only-used-in-recursion.html) | oxc | ✅ | ⚠️🛠️️ |
| [uninvoked-array-callback](/docs/guide/usage/linter/rules/oxc/uninvoked-array-callback.html) | oxc | ✅ | |
Expand Down Expand Up @@ -207,7 +208,7 @@ Code that can be written to run faster.
| [jsx-no-new-object-as-prop](/docs/guide/usage/linter/rules/react_perf/jsx-no-new-object-as-prop.html) | react_perf | | |
| [prefer-set-has](/docs/guide/usage/linter/rules/unicorn/prefer-set-has.html) | unicorn | | ⚠️🛠️️ |

## Restriction (62):
## Restriction (64):

Lints which prevent the use of language and library features. Must not be enabled as a whole, should be considered on a case-by-case basis before enabling.
| Rule name | Source | Default | Fixable? |
Expand All @@ -225,6 +226,7 @@ Lints which prevent the use of language and library features. Must not be enable
| [no-proto](/docs/guide/usage/linter/rules/eslint/no-proto.html) | eslint | | 🚧 |
| [no-regex-spaces](/docs/guide/usage/linter/rules/eslint/no-regex-spaces.html) | eslint | | 🚧 |
| [no-restricted-globals](/docs/guide/usage/linter/rules/eslint/no-restricted-globals.html) | eslint | | |
| [no-restricted-imports](/docs/guide/usage/linter/rules/eslint/no-restricted-imports.html) | eslint | | |
| [no-undefined](/docs/guide/usage/linter/rules/eslint/no-undefined.html) | eslint | | |
| [no-unused-expressions](/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html) | eslint | | |
| [no-var](/docs/guide/usage/linter/rules/eslint/no-var.html) | eslint | | 🛠️ |
Expand All @@ -250,6 +252,7 @@ Lints which prevent the use of language and library features. Must not be enable
| [catch-or-return](/docs/guide/usage/linter/rules/promise/catch-or-return.html) | promise | | |
| [spec-only](/docs/guide/usage/linter/rules/promise/spec-only.html) | promise | | |
| [button-has-type](/docs/guide/usage/linter/rules/react/button-has-type.html) | react | | |
| [jsx-filename-extension](/docs/guide/usage/linter/rules/react/jsx-filename-extension.html) | react | | 🚧 |
| [no-danger](/docs/guide/usage/linter/rules/react/no-danger.html) | react | | |
| [no-unknown-property](/docs/guide/usage/linter/rules/react/no-unknown-property.html) | react | | 🚧 |
| [explicit-function-return-type](/docs/guide/usage/linter/rules/typescript/explicit-function-return-type.html) | typescript | | |
Expand All @@ -275,7 +278,7 @@ Lints which prevent the use of language and library features. Must not be enable
| [prefer-node-protocol](/docs/guide/usage/linter/rules/unicorn/prefer-node-protocol.html) | unicorn | | 🛠️ |
| [prefer-number-properties](/docs/guide/usage/linter/rules/unicorn/prefer-number-properties.html) | unicorn | | 🚧 |

## Suspicious (25):
## Suspicious (27):

code that is most likely wrong or useless.
| Rule name | Source | Default | Fixable? |
Expand All @@ -286,6 +289,7 @@ code that is most likely wrong or useless.
| [no-unneeded-ternary](/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.html) | eslint | | 🚧 |
| [no-useless-concat](/docs/guide/usage/linter/rules/eslint/no-useless-concat.html) | eslint | | |
| [no-useless-constructor](/docs/guide/usage/linter/rules/eslint/no-useless-constructor.html) | eslint | | 🛠️ |
| [no-absolute-path](/docs/guide/usage/linter/rules/import/no-absolute-path.html) | import | | 🚧 |
| [no-duplicates](/docs/guide/usage/linter/rules/import/no-duplicates.html) | import | | |
| [no-named-as-default](/docs/guide/usage/linter/rules/import/no-named-as-default.html) | import | | |
| [no-named-as-default-member](/docs/guide/usage/linter/rules/import/no-named-as-default-member.html) | import | | |
Expand All @@ -298,6 +302,7 @@ code that is most likely wrong or useless.
| [iframe-missing-sandbox](/docs/guide/usage/linter/rules/react/iframe-missing-sandbox.html) | react | | 🚧 |
| [jsx-no-comment-textnodes](/docs/guide/usage/linter/rules/react/jsx-no-comment-textnodes.html) | react | | |
| [jsx-no-script-url](/docs/guide/usage/linter/rules/react/jsx-no-script-url.html) | react | | 🚧 |
| [no-namespace](/docs/guide/usage/linter/rules/react/no-namespace.html) | react | | |
| [react-in-jsx-scope](/docs/guide/usage/linter/rules/react/react-in-jsx-scope.html) | react | | |
| [style-prop-object](/docs/guide/usage/linter/rules/react/style-prop-object.html) | react | | |
| [no-confusing-non-null-assertion](/docs/guide/usage/linter/rules/typescript/no-confusing-non-null-assertion.html) | typescript | | 🚧 |
Expand Down Expand Up @@ -390,11 +395,12 @@ Lints which are rather strict or have occasional false positives.
| [prefer-type-error](/docs/guide/usage/linter/rules/unicorn/prefer-type-error.html) | unicorn | | 🛠️ |
| [require-number-to-fixed-digits-argument](/docs/guide/usage/linter/rules/unicorn/require-number-to-fixed-digits-argument.html) | unicorn | | 🛠️ |

## Style (128):
## Style (137):

Code that should be written in a more idiomatic way.
| Rule name | Source | Default | Fixable? |
| ------------------------------------ | ---------- | ------- | -------- |
| [curly](/docs/guide/usage/linter/rules/eslint/curly.html) | eslint | | 🛠️ |
| [default-case-last](/docs/guide/usage/linter/rules/eslint/default-case-last.html) | eslint | | |
| [default-param-last](/docs/guide/usage/linter/rules/eslint/default-param-last.html) | eslint | | |
| [func-names](/docs/guide/usage/linter/rules/eslint/func-names.html) | eslint | | 🛠️💡 |
Expand All @@ -417,8 +423,9 @@ Code that should be written in a more idiomatic way.
| [no-new-func](/docs/guide/usage/linter/rules/eslint/no-new-func.html) | eslint | | |
| [no-return-assign](/docs/guide/usage/linter/rules/eslint/no-return-assign.html) | eslint | | 🚧 |
| [no-script-url](/docs/guide/usage/linter/rules/eslint/no-script-url.html) | eslint | | |
| [no-template-curly-in-string](/docs/guide/usage/linter/rules/eslint/no-template-curly-in-string.html) | eslint | | 🚧 |
| [no-template-curly-in-string](/docs/guide/usage/linter/rules/eslint/no-template-curly-in-string.html) | eslint | | ⚠️🛠️️ |
| [no-ternary](/docs/guide/usage/linter/rules/eslint/no-ternary.html) | eslint | | |
| [operator-assignment](/docs/guide/usage/linter/rules/eslint/operator-assignment.html) | eslint | | ⚠️🛠️️ |
| [prefer-exponentiation-operator](/docs/guide/usage/linter/rules/eslint/prefer-exponentiation-operator.html) | eslint | | |
| [prefer-numeric-literals](/docs/guide/usage/linter/rules/eslint/prefer-numeric-literals.html) | eslint | | 🛠️ |
| [prefer-object-has-own](/docs/guide/usage/linter/rules/eslint/prefer-object-has-own.html) | eslint | | 🛠️ |
Expand All @@ -430,7 +437,10 @@ Code that should be written in a more idiomatic way.
| [sort-keys](/docs/guide/usage/linter/rules/eslint/sort-keys.html) | eslint | | 🚧 |
| [vars-on-top](/docs/guide/usage/linter/rules/eslint/vars-on-top.html) | eslint | | |
| [yoda](/docs/guide/usage/linter/rules/eslint/yoda.html) | eslint | | 🛠️ |
| [exports-last](/docs/guide/usage/linter/rules/import/exports-last.html) | import | | |
| [first](/docs/guide/usage/linter/rules/import/first.html) | import | | 🚧 |
| [no-anonymous-default-export](/docs/guide/usage/linter/rules/import/no-anonymous-default-export.html) | import | | |
| [no-mutable-exports](/docs/guide/usage/linter/rules/import/no-mutable-exports.html) | import | | |
| [no-named-default](/docs/guide/usage/linter/rules/import/no-named-default.html) | import | | |
| [no-namespace](/docs/guide/usage/linter/rules/import/no-namespace.html) | import | | 🚧 |
| [consistent-test-it](/docs/guide/usage/linter/rules/jest/consistent-test-it.html) | jest | | 🛠️ |
Expand Down Expand Up @@ -472,9 +482,12 @@ Code that should be written in a more idiomatic way.
| [require-top-level-describe](/docs/guide/usage/linter/rules/jest/require-top-level-describe.html) | jest | | |
| [no-exports-assign](/docs/guide/usage/linter/rules/node/no-exports-assign.html) | node | | 🛠️ |
| [avoid-new](/docs/guide/usage/linter/rules/promise/avoid-new.html) | promise | | |
| [no-nesting](/docs/guide/usage/linter/rules/promise/no-nesting.html) | promise | | 🚧 |
| [no-return-wrap](/docs/guide/usage/linter/rules/promise/no-return-wrap.html) | promise | | 🚧 |
| [param-names](/docs/guide/usage/linter/rules/promise/param-names.html) | promise | | |
| [prefer-await-to-callbacks](/docs/guide/usage/linter/rules/promise/prefer-await-to-callbacks.html) | promise | | |
| [prefer-await-to-then](/docs/guide/usage/linter/rules/promise/prefer-await-to-then.html) | promise | | |
| [prefer-catch](/docs/guide/usage/linter/rules/promise/prefer-catch.html) | promise | | 🚧 |
| [jsx-boolean-value](/docs/guide/usage/linter/rules/react/jsx-boolean-value.html) | react | | 🛠️ |
| [jsx-curly-brace-presence](/docs/guide/usage/linter/rules/react/jsx-curly-brace-presence.html) | react | | |
| [no-set-state](/docs/guide/usage/linter/rules/react/no-set-state.html) | react | | |
Expand All @@ -492,6 +505,7 @@ Code that should be written in a more idiomatic way.
| [prefer-function-type](/docs/guide/usage/linter/rules/typescript/prefer-function-type.html) | typescript | | 🛠️ |
| [prefer-namespace-keyword](/docs/guide/usage/linter/rules/typescript/prefer-namespace-keyword.html) | typescript | | 🛠️ |
| [catch-error-name](/docs/guide/usage/linter/rules/unicorn/catch-error-name.html) | unicorn | | 🛠️ |
| [consistent-date-clone](/docs/guide/usage/linter/rules/unicorn/consistent-date-clone.html) | unicorn | | 🛠️ |
| [consistent-existence-index-check](/docs/guide/usage/linter/rules/unicorn/consistent-existence-index-check.html) | unicorn | | 🛠️ |
| [empty-brace-spaces](/docs/guide/usage/linter/rules/unicorn/empty-brace-spaces.html) | unicorn | | 🛠️ |
| [error-message](/docs/guide/usage/linter/rules/unicorn/error-message.html) | unicorn | | |
Expand Down Expand Up @@ -524,14 +538,13 @@ Code that should be written in a more idiomatic way.
| [prefer-to-be-object](/docs/guide/usage/linter/rules/vitest/prefer-to-be-object.html) | vitest | | 🛠️ |
| [prefer-to-be-truthy](/docs/guide/usage/linter/rules/vitest/prefer-to-be-truthy.html) | vitest | | 🛠️ |

## Nursery (12):
## Nursery (11):

New lints that are still under development.
| Rule name | Source | Default | Fixable? |
| ----------------------- | ---------- | ------- | -------- |
| [constructor-super](/docs/guide/usage/linter/rules/eslint/constructor-super.html) | eslint | | |
| [getter-return](/docs/guide/usage/linter/rules/eslint/getter-return.html) | eslint | | |
| [no-restricted-imports](/docs/guide/usage/linter/rules/eslint/no-restricted-imports.html) | eslint | | |
| [no-undef](/docs/guide/usage/linter/rules/eslint/no-undef.html) | eslint | | |
| [no-unreachable](/docs/guide/usage/linter/rules/eslint/no-unreachable.html) | eslint | | |
| [export](/docs/guide/usage/linter/rules/import/export.html) | import | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ oxlint --deny array-callback-return

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs)
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ oxlint --deny constructor-super

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/constructor_super.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/constructor_super.rs)
72 changes: 72 additions & 0 deletions src/docs/guide/usage/linter/rules/eslint/curly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

# eslint/curly <Badge type="info" text="Style" />

<div class="rule-meta">
<Alert class="fix" type="info">
<span class="emoji">🛠️</span> An auto-fix is available for this rule.
</Alert>
</div>

### What it does

This rule enforces the use of curly braces `{}` for all control statements (`if`, `else`, `for`, `while`, `do`, etc.).
It ensures that all blocks are enclosed in curly braces to improve code clarity and maintainability.

### Why is this bad?

Omitting curly braces can reduce code readability and increase the likelihood of errors, especially in deeply nested or indented code.
It can also lead to bugs if additional statements are added later without properly enclosing them in braces.
Using curly braces consistently makes the code safer and easier to modify.

### Examples

Examples of **incorrect** code for this rule:

```js
if (foo) foo++;

for (let i = 0; i < 10; i++) doSomething(i);

while (bar) bar--;
```

Examples of **correct** code for this rule:

```js
if (foo) {
foo++;
}

for (let i = 0; i < 10; i++) {
doSomething(i);
}

while (bar) {
bar--;
}
```

## How to use

To **enable** this rule in the CLI or using the config file, you can use:

::: code-group

```bash [CLI]
oxlint --deny curly
```

```json [Config (.oxlintrc.json)]
{
"rules": {
"curly": "error"
}
}
```

:::

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/curly.rs)
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ oxlint --deny default-case-last

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/default_case_last.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/default_case_last.rs)
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/eslint/default-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ oxlint --deny default-case

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/default_case.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/default_case.rs)
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ oxlint --deny default-param-last

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/default_param_last.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/default_param_last.rs)
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/eslint/eqeqeq.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ oxlint --deny eqeqeq

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/eqeqeq.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/eqeqeq.rs)
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/eslint/for-direction.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ oxlint --deny for-direction

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/for_direction.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/for_direction.rs)
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/eslint/func-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ oxlint --deny func-names

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/func_names.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/func_names.rs)
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/eslint/func-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ oxlint --deny func-style

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/func_style.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/func_style.rs)
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/eslint/getter-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ oxlint --deny getter-return

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/getter_return.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/getter_return.rs)
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ oxlint --deny grouped-accessor-pairs

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs)
38 changes: 35 additions & 3 deletions src/docs/guide/usage/linter/rules/eslint/guard-for-in.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,50 @@

### What it does

This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.
Require for-in loops to include an if statement.

### Why is this bad?

### Example
Looping over objects with a `for in` loop will include properties that are inherited through
the prototype chain. Using a `for in` loop without filtering the results in the loop can
lead to unexpected items in your for loop which can then lead to unexpected behaviour.

### Examples

Examples of **incorrect** code for this rule:

```javascript
for (key in foo) {
doSomething(key);
}
```

Examples of **correct** code for this rule:

```javascript
for (key in foo) {
if (Object.hasOwn(foo, key)) {
doSomething(key);
}
}
```

```javascript
for (key in foo) {
if (Object.prototype.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}
```

```javascript
for (key in foo) {
if ({}.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}
```

## How to use

To **enable** this rule in the CLI or using the config file, you can use:
Expand All @@ -41,4 +73,4 @@ oxlint --deny guard-for-in

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/30318457d425dbf627aa428aad8004f6b92b1c59/crates/oxc_linter/src/rules/eslint/guard_for_in.rs)
- [Rule Source](https://github.com/oxc-project/oxc/blob/89b6e4c7a880c5e0e6ac98dda359a08759d62e4c/crates/oxc_linter/src/rules/eslint/guard_for_in.rs)
Loading