Skip to content

Commit 62808cb

Browse files
Merge pull request #13666 from Snuffleupagus/eslint-operator-assignment
Enable the ESLint `operator-assignment` rule
2 parents de80590 + 819be0e commit 62808cb

17 files changed

+41
-42
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
},
189189
],
190190
"no-unneeded-ternary": "error",
191+
"operator-assignment": "error",
191192
"prefer-exponentiation-operator": "error",
192193
"spaced-comment": ["error", "always", {
193194
"block": {

external/cmapscompress/compress.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function parseCMap(binaryData) {
204204
bufferSize = 0;
205205
while (s.length < lengthInChars) {
206206
while (bufferSize < 4 && stack.length > 0) {
207-
buffer = (stack.pop() << bufferSize) | buffer;
207+
buffer |= stack.pop() << bufferSize;
208208
bufferSize += 7;
209209
}
210210
s = toHexDigit(buffer & 15) + s;
@@ -375,7 +375,7 @@ function writeNumber(n) {
375375
let i = n.length;
376376
while (i > 0) {
377377
--i;
378-
buffer = (fromHexDigit(n[i]) << bufferSize) | buffer;
378+
buffer |= fromHexDigit(n[i]) << bufferSize;
379379
bufferSize += 4;
380380
if (bufferSize >= 7) {
381381
s = writeByte((buffer & 0x7f) | (s.length > 0 ? 0x80 : 0)) + s;
@@ -409,7 +409,7 @@ function writeSigned(n) {
409409
const d = fromHexDigit(n[i]);
410410
c = (c << 4) | (neg ? d ^ 15 : d);
411411
t += toHexDigit(c >> 3);
412-
c = c & 7;
412+
c &= 7;
413413
}
414414
t += toHexDigit((c << 1) | (neg ? 1 : 0));
415415
return writeNumber(t);

src/core/ascii_85_stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Ascii85Stream extends DecodeStream {
2121
// Most streams increase in size when decoded, but Ascii85 streams
2222
// typically shrink by ~20%.
2323
if (maybeLength) {
24-
maybeLength = 0.8 * maybeLength;
24+
maybeLength *= 0.8;
2525
}
2626
super(maybeLength);
2727

src/core/ascii_hex_stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AsciiHexStream extends DecodeStream {
2020
// Most streams increase in size when decoded, but AsciiHex streams shrink
2121
// by 50%.
2222
if (maybeLength) {
23-
maybeLength = 0.5 * maybeLength;
23+
maybeLength *= 0.5;
2424
}
2525
super(maybeLength);
2626

src/core/cff_parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ const CFFParser = (function CFFParserClosure() {
936936
}
937937
raw = bytes.subarray(dataStart, dataEnd);
938938
}
939-
format = format & 0x7f;
939+
format &= 0x7f;
940940
return new CFFEncoding(predefined, format, encoding, raw);
941941
}
942942

@@ -1552,7 +1552,7 @@ class CFFCompiler {
15521552
if (value >= -107 && value <= 107) {
15531553
code = [value + 139];
15541554
} else if (value >= 108 && value <= 1131) {
1555-
value = value - 108;
1555+
value -= 108;
15561556
code = [(value >> 8) + 247, value & 0xff];
15571557
} else if (value >= -1131 && value <= -108) {
15581558
value = -value - 108;

src/core/cmap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {
534534
bufferSize = 0;
535535
while (i >= 0) {
536536
while (bufferSize < 8 && stack.length > 0) {
537-
buffer = (stack[--sp] << bufferSize) | buffer;
537+
buffer |= stack[--sp] << bufferSize;
538538
bufferSize += 7;
539539
}
540540
num[i] = buffer & 255;

src/core/crypto.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class Word64 {
213213
this.low = 0;
214214
} else {
215215
this.high = (this.high << places) | (this.low >>> (32 - places));
216-
this.low = this.low << places;
216+
this.low <<= places;
217217
}
218218
}
219219

@@ -1165,7 +1165,7 @@ class AES128Cipher extends AESBaseCipher {
11651165
t3 = s[t3];
11661166
t4 = s[t4];
11671167
// Rcon
1168-
t1 = t1 ^ rcon[i];
1168+
t1 ^= rcon[i];
11691169
for (let n = 0; n < 4; ++n) {
11701170
result[j] = t1 ^= result[j - 16];
11711171
j++;
@@ -1218,7 +1218,7 @@ class AES256Cipher extends AESBaseCipher {
12181218
t3 = s[t3];
12191219
t4 = s[t4];
12201220
// Rcon
1221-
t1 = t1 ^ r;
1221+
t1 ^= r;
12221222
if ((r <<= 1) >= 256) {
12231223
r = (r ^ 0x1b) & 0xff;
12241224
}

src/core/document.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class Page {
216216
if (rotate % 90 !== 0) {
217217
rotate = 0;
218218
} else if (rotate >= 360) {
219-
rotate = rotate % 360;
219+
rotate %= 360;
220220
} else if (rotate < 0) {
221221
// The spec doesn't cover negatives. Assume it's counterclockwise
222222
// rotation. The following is the other implementation of modulo.

src/core/glyf.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class SimpleGlyph {
286286
flags.push(flag);
287287
if (flag & REPEAT_FLAG) {
288288
const count = glyf.getUint8(++pos);
289-
flag = flag ^ REPEAT_FLAG;
289+
flag ^= REPEAT_FLAG;
290290
for (let m = 0; m < count; m++) {
291291
flags.push(flag);
292292
}
@@ -412,16 +412,15 @@ class SimpleGlyph {
412412
const x = contour.xCoordinates[i];
413413
let delta = x - lastX;
414414
if (delta === 0) {
415-
flag = flag | X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR;
415+
flag |= X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR;
416416
xCoordinates.push(0);
417417
} else {
418418
const abs = Math.abs(delta);
419419
if (abs <= 255) {
420-
flag =
421-
flag |
422-
(delta >= 0
420+
flag |=
421+
delta >= 0
423422
? X_SHORT_VECTOR | X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR
424-
: X_SHORT_VECTOR);
423+
: X_SHORT_VECTOR;
425424
xCoordinates.push(abs);
426425
} else {
427426
xCoordinates.push(delta);
@@ -432,16 +431,15 @@ class SimpleGlyph {
432431
const y = contour.yCoordinates[i];
433432
delta = y - lastY;
434433
if (delta === 0) {
435-
flag = flag | Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR;
434+
flag |= Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR;
436435
yCoordinates.push(0);
437436
} else {
438437
const abs = Math.abs(delta);
439438
if (abs <= 255) {
440-
flag =
441-
flag |
442-
(delta >= 0
439+
flag |=
440+
delta >= 0
443441
? Y_SHORT_VECTOR | Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR
444-
: Y_SHORT_VECTOR);
442+
: Y_SHORT_VECTOR;
445443
yCoordinates.push(abs);
446444
} else {
447445
yCoordinates.push(delta);
@@ -550,7 +548,7 @@ class CompositeGlyph {
550548
argument2 = glyf.getUint16(pos + 2);
551549
}
552550
pos += 4;
553-
flags = flags ^ ARG_1_AND_2_ARE_WORDS;
551+
flags ^= ARG_1_AND_2_ARE_WORDS;
554552
} else {
555553
argument1 = glyf.getUint8(pos);
556554
argument2 = glyf.getUint8(pos + 1);
@@ -652,7 +650,7 @@ class CompositeGlyph {
652650
this.argument2 <= 127
653651
)
654652
) {
655-
this.flags = this.flags | ARG_1_AND_2_ARE_WORDS;
653+
this.flags |= ARG_1_AND_2_ARE_WORDS;
656654
}
657655
} else {
658656
if (
@@ -663,7 +661,7 @@ class CompositeGlyph {
663661
this.argument2 <= 255
664662
)
665663
) {
666-
this.flags = this.flags | ARG_1_AND_2_ARE_WORDS;
664+
this.flags |= ARG_1_AND_2_ARE_WORDS;
667665
}
668666
}
669667

src/core/image.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ class PDFImage {
471471
value = max;
472472
}
473473
output[i] = value;
474-
buf = buf & ((1 << remainingBits) - 1);
474+
buf &= (1 << remainingBits) - 1;
475475
bits = remainingBits;
476476
}
477477
}

src/core/jbig2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ function decodeHalftoneRegion(
10881088
bit = 0;
10891089
patternIndex = 0;
10901090
for (j = bitsPerValue - 1; j >= 0; j--) {
1091-
bit = grayScaleBitPlanes[j][mg][ng] ^ bit; // Gray decoding
1091+
bit ^= grayScaleBitPlanes[j][mg][ng]; // Gray decoding
10921092
patternIndex |= bit << j;
10931093
}
10941094
patternBitmap = patterns[patternIndex];

src/core/jpx.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,7 @@ class Transform {
22412241
class IrreversibleTransform extends Transform {
22422242
filter(x, offset, length) {
22432243
const len = length >> 1;
2244-
offset = offset | 0;
2244+
offset |= 0;
22452245
let j, n, current, next;
22462246

22472247
const alpha = -1.586134342059924;
@@ -2327,7 +2327,7 @@ class IrreversibleTransform extends Transform {
23272327
class ReversibleTransform extends Transform {
23282328
filter(x, offset, length) {
23292329
const len = length >> 1;
2330-
offset = offset | 0;
2330+
offset |= 0;
23312331
let j, n;
23322332

23332333
for (j = offset, n = len + 1; n--; j += 2) {

src/core/type1_parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ const Type1CharString = (function Type1CharStringClosure() {
312312
}
313313
continue;
314314
} else if (value <= 246) {
315-
value = value - 139;
315+
value -= 139;
316316
} else if (value <= 250) {
317317
value = (value - 247) * 256 + encoded[++i] + 108;
318318
} else if (value <= 254) {

src/display/annotation_layer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ class AnnotationElement {
202202
// Underline styles only have a bottom border, so we do not need
203203
// to adjust for all borders. This yields a similar result as
204204
// Adobe Acrobat/Reader.
205-
width = width - 2 * data.borderStyle.width;
206-
height = height - 2 * data.borderStyle.width;
205+
width -= 2 * data.borderStyle.width;
206+
height -= 2 * data.borderStyle.width;
207207
}
208208

209209
const horizontalRadius = data.borderStyle.horizontalCornerRadius;

src/display/canvas.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ function addContextCurrentTransform(ctx) {
145145

146146
ctx.scale = function ctxScale(x, y) {
147147
const m = this._transformMatrix;
148-
m[0] = m[0] * x;
149-
m[1] = m[1] * x;
150-
m[2] = m[2] * y;
151-
m[3] = m[3] * y;
148+
m[0] *= x;
149+
m[1] *= x;
150+
m[2] *= y;
151+
m[3] *= y;
152152

153153
this._originalScale(x, y);
154154
};

test/integration/find_spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ describe("find bar", () => {
5454
const firstA = await highlights[0].boundingBox();
5555
const secondA = await highlights[1].boundingBox();
5656
// Subtract the page offset from the text bounding boxes;
57-
firstA.x = firstA.x - pageBox.x;
58-
firstA.y = firstA.y - pageBox.y;
59-
secondA.x = secondA.x - pageBox.x;
60-
secondA.y = secondA.y - pageBox.y;
57+
firstA.x -= pageBox.x;
58+
firstA.y -= pageBox.y;
59+
secondA.x -= pageBox.x;
60+
secondA.y -= pageBox.y;
6161
// They should be on the same line.
6262
expect(firstA.y).withContext(`In ${browserName}`).toEqual(secondA.y);
6363
const fontSize = 26.66; // From the PDF.

web/debugger.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ var StepperManager = (function StepperManagerClosure() {
220220
},
221221
selectStepper: function selectStepper(pageIndex, selectPanel) {
222222
let i;
223-
pageIndex = pageIndex | 0;
223+
pageIndex |= 0;
224224
if (selectPanel) {
225225
this.manager.selectPanel(this);
226226
}

0 commit comments

Comments
 (0)