Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 282 additions & 2 deletions .vitepress/data/rules.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/generated-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Arguments:
## Output

- **`-f`**, **`--format`**=_`ARG`_ —
Use a specific output format. Possible values: `checkstyle`, `default`, `github`, `gitlab`, `json`, `junit`, `stylish`, `unix`
Use a specific output format. Possible values: `checkstyle`, `default`, `github`, `gitlab`, `json`, `junit`, `sarif`, `stylish`, `unix`

## Miscellaneous

Expand Down
93 changes: 93 additions & 0 deletions src/docs/guide/usage/linter/generated-lsp-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
search: false
---

# LSP Options for linting, which can be defined for each workspace folder separately.

It can be sent by the client in `initialize` or `workspace/didChangeConfiguration` requests.
If the client supports `workspace/configuration`, the server will request the options from the client.

## Example

Example of `initialize` request:

```json
{
"processId": 123,
"rootUri": null,
"workspaceFolders": [],
"capabilities": {},
"initializationOptions": [
{
"workspaceUri": "file:///home/user/project",
"options": {
"unusedDisableDirectives": "deny",
"typeAware": true
}
}
]
}
```

Example of `workspace/didChangeConfiguration` request:

```json
{
"settings": [
{
"workspaceUri": "file:///home/user/project",
"options": {
"unusedDisableDirectives": "deny",
"disableNestedConfig": true
}
}
]
}
```

## configPath

type: `string`

Path to the config file. Similar to `--config` CLI option.
If set, it disables searching for config files.

## disableNestedConfig

type: `boolean`

Whether to disable nested config support. Similar to `--disable-nested-config` CLI option.
It gets automatically enabled when `configPath` is set.

## fixKind

type: `"safe_fix" | "safe_fix_or_suggestion" | "dangerous_fix" | "dangerous_fix_or_suggestion" | "none" | "all"`

What kind of fixes to generate for code actions.

## run

type: `"onSave" | "onType"`

If your editor does not support `textDocument/diagnostic`,
this option handles when diagnostics are sent to the client.

## tsConfigPath

type: `string`

Path to the tsconfig file. Similar to `--tsconfig` CLI option.
If set, it disables auto discovery for tsconfig files.

## typeAware

type: `boolean`

Whether to enable/disable type-aware linting.
It will override the root config's `typeAware` option if set.

## unusedDisableDirectives

type: `"allow" | "warn" | "deny"`

How to handle unused disable directives. By default, they are allowed and ignored.
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
title: "eslint/logical-assignment-operators"
category: "Style"
version: "next"
default: false
type_aware: false
fix: "pending"
---

<!-- This file is auto-generated by tasks/website_linter/src/rules/doc_page.rs. Do not edit it manually. -->

<script setup>
import { data } from '../version.data.js';
const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/eslint/logical_assignment_operators.rs`;
</script>

<RuleHeader />

### What it does

This rule requires or disallows logical assignment operator shorthand.

### Why is this bad?

ES2021 introduces the assignment operator shorthand for the logical operators `||`, `&&` and `??`.
Before, this was only allowed for mathematical operations such as `+` or `*` (see the rule `operator-assignment`).
The shorthand can be used if the assignment target and the left expression of a logical expression are the same.
For example `a = a || b` can be shortened to `a ||= b`.

### Examples

Examples of **incorrect** code for this rule with the default `always` option:

```js
a = a || b;
a = a && b;
a = a ?? b;
a || (a = b);
a && (a = b);
a ?? (a = b);
a = a || b || c;
a = a && b && c;
a = a ?? b ?? c;
```

Examples of **correct** code for this rule with the default `always` option:

```js
a = b;
a += b;
a ||= b;
a = b || c;
a || (b = c);
if (a) a = b;
a = a || b || c;
```

Examples of **incorrect** code for this rule with the `never` option:

```js
a ||= b;
a &&= b;
a ??= b;
```

Examples of **correct** code for this rule with the `never` option:

```js
a = a || b;
a = a && b;
a = a ?? b;
```

## Configuration

### The 1st option

type: `"always" | "never"`

#### `"always"`

This option checks for expressions that can be shortened using logical assignment operator.
For example, `a = a || b` can be shortened to `a ||= b`.
Expressions with associativity such as `a = a || b || c` are reported as being able to be shortened to `a ||= b || c` unless the evaluation order is explicitly defined using parentheses, such as `a = (a || b) || c`.

#### `"never"`

This option disallows logical assignment operator shorthand.
For example, `a ||= b` should be written as `a = a || b`.

### The 2nd option

This option is an object with the following properties:

#### enforceForIfStatements

type: `boolean`

default: `false`

This option checks for additional patterns with if statements which could be expressed with the logical assignment operator.
Only available if string option is set to `always`.

Examples of **incorrect** code for this rule with the `["always", { enforceForIfStatements: true }]` option:

```js
if (a) a = b; // <=> a &&= b
if (!a) a = b; // <=> a ||= b

if (a == null) a = b; // <=> a ??= b
if (a === null || a === undefined) a = b; // <=> a ??= b
```

Examples of **correct** code for this rule with the `["always", { enforceForIfStatements: true }]` option:

```js
if (a) b = c;
if (a === 0) a = b;
```

## How to use

<RuleHowToUse />

## Version

This rule was added in vnext.

## References

<RuleReferences />
Loading