Skip to content

Commit ed85d00

Browse files
authored
explicit-length-check: Ignore this.{size,length} (#1289)
1 parent 36e7103 commit ed85d00

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

rules/explicit-length-check.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,18 @@ function create(context) {
151151

152152
return {
153153
[lengthSelector](lengthNode) {
154-
let node;
155-
let autoFix = true;
154+
if (lengthNode.object.type === 'ThisExpression') {
155+
return;
156+
}
156157

157158
const staticValue = getStaticValue(lengthNode, context.getScope());
158159
if (staticValue && (!Number.isInteger(staticValue.value) || staticValue.value < 0)) {
159160
// Ignore known, non-positive-integer length properties.
160161
return;
161162
}
162163

164+
let node;
165+
let autoFix = true;
163166
let {isZeroLengthCheck, node: lengthCheckNode} = getLengthCheckNode(lengthNode);
164167
if (lengthCheckNode) {
165168
const {isNegative, node: ancestor} = getBooleanAncestor(lengthCheckNode);

test/explicit-length-check.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,17 @@ test({
138138
});
139139

140140
test.snapshot({
141-
valid: [],
141+
valid: [
142+
// Ignored
143+
outdent`
144+
class A {
145+
a() {
146+
if (this.length);
147+
while (!this.size || foo);
148+
}
149+
}
150+
`
151+
],
142152
invalid: [
143153
outdent`
144154
if (

0 commit comments

Comments
 (0)