Skip to content

Commit f21c4b2

Browse files
committed
Various tweaks
1 parent 890ad52 commit f21c4b2

63 files changed

Lines changed: 475 additions & 330 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/rules/no-array-for-each.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Benefits of [`for…of` statement](https://developer.mozilla.org/en-US/docs/Web/
1414
- Ability to exit early with `break` or `return`
1515
- Ability to skip iterations with `continue`
1616

17-
Additionally, using `for…of` has great benefits if you are using TypeScript, because it does not cause a function boundary to be crossed. This means that type-narrowing earlier on in the current scope will work properly while inside of the loop (without having to re-type-narrow). Furthermore, any mutated variables inside of the loop will picked up on for the purposes of determining if a variable is being used.
17+
Additionally, using `for…of` has great benefits if you are using TypeScript, because it does not cause a function boundary to be crossed. This means that type-narrowing earlier on in the current scope will work properly while inside of the loop (without having to re-type-narrow). Furthermore, any mutated variables inside of the loop will be picked up on for the purposes of determining if a variable is being used.
1818

1919
## Examples
2020

docs/rules/no-array-method-this-argument.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
The rule disallows using the `thisArg` argument in array methods:
1111

1212
- If the callback is an arrow function or a bound function, the `thisArg` won't affect it.
13-
- If you intent to use a custom `this` in the callback, it's better to use the variable directly or use `callback.bind(thisArg)`.
13+
- If you intend to use a custom `this` in the callback, it's better to use the variable directly or use `callback.bind(thisArg)`.
1414

1515
This rule checks following array methods accepts `thisArg`:
1616

docs/rules/no-immediate-mutation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ When you create a variable and immediately mutate it, you should instead include
1212
- Assign variable to an array literal and immediately mutate with `Array#{push,unshift}(…)`.
1313
- Assign variable to an object literal and immediately assign another property.
1414
- Assign variable to an object literal and immediately mutate with `Object.assign(…)`.
15-
- Assign variable to a `Set` or `WeakSet` from an array literal and immediately adding an new element with `{Set,WeakSet}.add(…)`.
15+
- Assign variable to a `Set` or `WeakSet` from an array literal and immediately adding a new element with `{Set,WeakSet}.add(…)`.
1616
- Assign variable to a `Map` or `WeakMap` from an array literal and immediately set another key with `{Map,WeakMap}.set(…, …)`.
1717

1818
## Examples

docs/rules/numeric-separators-style.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Example:
8282
/* eslint unicorn/numeric-separators-style: ["error", {"onlyIfContainsSeparator": true, "binary": {"onlyIfContainsSeparator": false}] */
8383
const number = 100000; // Pass, this number does not contain separators
8484
const binary = 0b101010001; // Fail, `binary` type don't require separators
85-
const hexadecimal = 0xD_EED_BEE_F; // Fail, it contain separators and it's incorrectly grouped
85+
const hexadecimal = 0xD_EED_BEE_F; // Fail, it contains separators and it's incorrectly grouped
8686
```
8787

8888
**`minimumDigits`**

docs/rules/prefer-add-event-listener.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Enforces the use of `.addEventListener()` and `.removeEventListener()` over thei
1111

1212
In most cases, it is safe to replace the `on`-function with the corresponding `addEventListener` counterpart, which is why this rule contains a fixer that swaps it automatically for you. For example, you might be assigning some static functionality to a UI button when the page first loads, and in this context, the functionality of the two would be equivalent.
1313

14-
However, __if you are assigning a listener in a dynamic context, then this rule's auto-fixer will make your code bugged__. This is because the `on` assignment replaces the current listener, but the `addEventListener` adds an additional listener in addition to the ones that are already assigned. For example, if you are dynamically updating the functionality of a button as new data comes in, then using `addEventListener` would not work, since it would cause N functions to be invoked for every previous data state. In this context, you should probably disable this lint rule and use the `on` form, since [removing existing event listeners is not possible](https://stackoverflow.com/questions/9251837/how-to-remove-all-listeners-in-an-element).
14+
However, __if you are assigning a listener in a dynamic context, then this rule's auto-fixer will make your code bugged__. This is because the `on` assignment replaces the current listener, but the `addEventListener` adds an additional listener to the ones that are already assigned. For example, if you are dynamically updating the functionality of a button as new data comes in, then using `addEventListener` would not work, since it would cause N functions to be invoked for every previous data state. In this context, you should probably disable this lint rule and use the `on` form, since [removing existing event listeners is not possible](https://stackoverflow.com/questions/9251837/how-to-remove-all-listeners-in-an-element).
1515

1616
## Examples
1717

docs/rules/prefer-array-some.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ We only check `.filter().length > 0` and `.filter().length !== 0`. These two non
1515

1616
- Using [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) or [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) to ensure at least one element in the array passes a given check.
1717

18-
- Comparing the result of [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) or [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) with `undefined`.
18+
- Comparing the result of [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) or [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) with `undefined`.
1919

2020
- Using [`Array#findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) or [`Array#findLastIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) to ensure at least one element in the array passes a given check.
2121

docs/rules/prefer-simple-condition-first.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ const x = bar || foo();
4646

4747
## Fix safety
4848

49-
Expressions with side effects or throwing potential are not flagged, since reordering would change program behavior:
49+
Expressions with side effects or observable property reads are not flagged, since reordering would change program behavior:
5050

5151
- Assignment expressions (`state.ready = true`)
5252
- Update expressions (`++counter`)
53-
- Deep member expression chains (`object.deep.value`)
53+
- Member expressions (`object.flag`, `object?.flag`, `object[index]`)
5454
- Tagged template expressions (`` tag`x` ``)
5555

56-
When the complex side contains function calls or `new` expressions, the fix is provided as a **suggestion** rather than an auto-fix, because reordering changes when the call executes due to short-circuit evaluation.
56+
Expressions containing function calls or `new` expressions on the complex side are not flagged, because reordering them is not semantics-preserving under short-circuit evaluation.
5757

58-
When both sides are side-effect-free (identifiers, simple member expressions, literals), the fix is applied automatically.
58+
When both sides are side-effect-free (identifiers, literals, and other pure expressions), the fix is applied automatically unless comments between the operands would be lost.

docs/rules/prefer-ternary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- end auto-generated rule header -->
88
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->
99

10-
This rule enforces the use of ternary expressions over 'simple' `if-else` statements, where 'simple' means the consequent and alternate are each one line and have the same basic type and form.
10+
This rule enforces the use of ternary expressions over 'simple' `if-else` statements, where 'simple' means the consequent and alternate are each one line and have the same basic type and form.
1111

1212
Using an `if-else` statement typically results in more lines of code than a single-line ternary expression, which leads to an unnecessarily larger codebase that is more difficult to maintain.
1313

docs/rules/prefer-type-error.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This rule enforces you to throw a `TypeError` after a type checking if-statement
1111

1212
It's aware of the most commonly used type checking operators and identifiers like `typeof`, `instanceof`, `.isString()`, etc, borrowed from [ES2017](https://tc39.github.io/ecma262/), [Underscore](https://underscorejs.org), [Lodash](https://lodash.com), and [jQuery](https://jquery.com). For a complete list of the recognized identifiers, please take a look at the [identifier-definition](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/prefer-type-error.js#L3).
1313

14-
The rule investigates every throw-statement which throws a generic `Error`. It will fail if the throw-statement is the only expression in the surrounding block and is preceeded by an if-statement whose condition consists of type-checks exclusively. You have to replace the `Error` with a `TypeError`.
14+
The rule investigates every throw-statement which throws a generic `Error`. It will fail if the throw-statement is the only expression in the surrounding block and is preceded by an if-statement whose condition consists of type-checks exclusively. You have to replace the `Error` with a `TypeError`.
1515

1616
## Examples
1717

docs/rules/switch-case-break-position.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Enforce that terminating statements (`break`, `return`, `continue`, `throw`) app
1010

1111
This can happen when refactoring — for example, removing an `if` wrapper but leaving the `break` outside the braces.
1212

13+
`break` and `continue` are auto-fixed. `return` and `throw` are still reported, but are left for manual fixes because moving them into the block can change lexical binding resolution.
14+
1315
## Examples
1416

1517
```js

0 commit comments

Comments
 (0)