Skip to content

Commit f80b746

Browse files
authored
docs: add known limitations for no-self-compare (#19612)
1 parent 59ba6b7 commit f80b746

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

docs/src/rules/no-self-compare.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,32 @@ if (x === x) {
2626
```
2727

2828
:::
29+
30+
## Known Limitations
31+
32+
This rule works by directly comparing the tokens on both sides of the operator. It flags them as problematic if they are structurally identical. However, it doesn't consider possible side effects or that functions may return different objects even when called with the same arguments. As a result, it can produce false positives in some cases, such as:
33+
34+
::: incorrect
35+
36+
```js
37+
/*eslint no-self-compare: "error"*/
38+
39+
function parseDate(dateStr) {
40+
return new Date(dateStr);
41+
}
42+
43+
if (parseDate('December 17, 1995 03:24:00') === parseDate('December 17, 1995 03:24:00')) {
44+
// do something
45+
}
46+
47+
let counter = 0;
48+
function incrementUnlessReachedMaximum() {
49+
return Math.min(counter += 1, 10);
50+
}
51+
52+
if (incrementUnlessReachedMaximum() === incrementUnlessReachedMaximum()) {
53+
// ...
54+
}
55+
```
56+
57+
:::

0 commit comments

Comments
 (0)