Przejdź do głównej zawartości

noIncrementDecrement

Ta treść nie jest jeszcze dostępna w Twoim języku.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noIncrementDecrement": "error"
}
}
}
}

Disallows the usage of the unary operators ++ and —.

Because the unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code.

let i = 10;
let j = 20;
i ++
j
// i = 11, j = 20
code-block.js:4:1 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

2 │ let j = 20;
3 │
> 4 │ i ++
^^^^
5 │ j
6 │ // i = 11, j = 20

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

let i = 10;
let j = 20;
i
++
j
// i = 10, j = 21
code-block.js:5:1 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

4 │ i
> 5 │ ++
^^
> 6 │ j
^
7 │ // i = 10, j = 21
8 │

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

let foo = 0;
foo++;
code-block.js:2:1 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

1 │ let foo = 0;
> 2 │ foo++;
^^^^^
3 │

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

let bar = 42;
bar--;
code-block.js:2:1 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

1 │ let bar = 42;
> 2 │ bar—;
^^^^^
3 │

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

for (let i = 0; i < 10; i++) {
doSomething(i);
}
code-block.js:1:25 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

> 1 │ for (let i = 0; i < 10; i++) {
^^^
2 │ doSomething(i);
3 │ }

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

for (let i = 0; i < 10;) {
doSomething(i);
i++;
}
code-block.js:3:5 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

1 │ for (let i = 0; i < 10;) {
2 │ doSomething(i);
> 3 │ i++;
^^^
4 │ }
5 │

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

let foo = 0;
foo += 1;
let bar = 42;
bar -= 1;
for (let i = 0; i < 10; i += 1) {
doSomething(i);
}
for (let i = 0; i < 10;) {
doSomething(i);
i += 1;
}

Allows unary operators ++ and — in the afterthought (final expression) of a for loop.

Default false

biome.json
{
"linter": {
"rules": {
"nursery": {
"noIncrementDecrement": {
"options": {
"allowForLoopAfterthoughts": true
}
}
}
}
}
}
for (let i = 0; i < j; j = i++) {
doSomething(i, j);
}
code-block.js:1:28 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

> 1 │ for (let i = 0; i < j; j = i++) {
^^^
2 │ doSomething(i, j);
3 │ }

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

for (let i = 10; i--;) {
doSomething(i);
}
code-block.js:1:18 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

> 1 │ for (let i = 10; i—;) {
^^^
2 │ doSomething(i);
3 │ }

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

for (let i = 0; i < 10;) i++;
code-block.js:1:26 lint/nursery/noIncrementDecrement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of increment/decrement unary operator.

> 1 │ for (let i = 0; i < 10;) i++;
^^^
2 │

The unary ++ and — operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code. Instead use += or -=.

for (let i = 0; i < 10; i++) {
doSomething(i);
}
for (let i = 0, j = l; i < l; i++, j--) {
doSomething(i, j);
}