From 19802e61dfe887f44b26648eb9068f231728d054 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 29 Nov 2022 12:14:19 +0100 Subject: [PATCH 1/2] build: Remove `no-plusplus` eslint rule --- packages/browser/test/integration/polyfills/promise.js | 1 - packages/eslint-config-sdk/src/index.js | 3 --- packages/replay/.eslintrc.js | 2 -- packages/utils/src/browser.ts | 1 - packages/utils/src/path.ts | 3 --- packages/utils/src/promisebuffer.ts | 1 - packages/utils/src/stacktrace.ts | 1 - 7 files changed, 12 deletions(-) diff --git a/packages/browser/test/integration/polyfills/promise.js b/packages/browser/test/integration/polyfills/promise.js index 5215bf5eb59b..a0af14994c34 100644 --- a/packages/browser/test/integration/polyfills/promise.js +++ b/packages/browser/test/integration/polyfills/promise.js @@ -102,7 +102,6 @@ observer.observe(node, { characterData: true }); return function () { - // eslint-disable-next-line no-plusplus node.data = iterations = ++iterations % 2; }; } diff --git a/packages/eslint-config-sdk/src/index.js b/packages/eslint-config-sdk/src/index.js index b2cb3b33f400..a405a12fc4bb 100644 --- a/packages/eslint-config-sdk/src/index.js +++ b/packages/eslint-config-sdk/src/index.js @@ -196,9 +196,6 @@ module.exports = { ], rules: { - // We want to prevent usage of unary operators outside of for loops - 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], - // Disallow usage of console and alert 'no-console': 'error', 'no-alert': 'error', diff --git a/packages/replay/.eslintrc.js b/packages/replay/.eslintrc.js index 90f4a84945d3..c30426ad113d 100644 --- a/packages/replay/.eslintrc.js +++ b/packages/replay/.eslintrc.js @@ -65,8 +65,6 @@ module.exports = { '@typescript-eslint/no-floating-promises': 'off', // TODO (medium-prio): Re-enable this after migration 'jsdoc/require-jsdoc': 'off', - // TODO: Do we even want to turn this on? Why not enable ++? - 'no-plusplus': 'off', }, }, { diff --git a/packages/utils/src/browser.ts b/packages/utils/src/browser.ts index cca2393a77db..d30b81044bdd 100644 --- a/packages/utils/src/browser.ts +++ b/packages/utils/src/browser.ts @@ -30,7 +30,6 @@ export function htmlTreeAsString(elem: unknown, keyAttrs?: string[]): string { const sepLength = separator.length; let nextStr; - // eslint-disable-next-line no-plusplus while (currentElem && height++ < MAX_TRAVERSE_HEIGHT) { nextStr = _htmlElementAsString(currentElem, keyAttrs); // bail out if diff --git a/packages/utils/src/path.ts b/packages/utils/src/path.ts index ba885a3f9a56..b626123505d3 100644 --- a/packages/utils/src/path.ts +++ b/packages/utils/src/path.ts @@ -11,18 +11,15 @@ function normalizeArray(parts: string[], allowAboveRoot?: boolean): string[] { parts.splice(i, 1); } else if (last === '..') { parts.splice(i, 1); - // eslint-disable-next-line no-plusplus up++; } else if (up) { parts.splice(i, 1); - // eslint-disable-next-line no-plusplus up--; } } // if the path is allowed to go above the root, restore leading ..s if (allowAboveRoot) { - // eslint-disable-next-line no-plusplus for (; up--; up) { parts.unshift('..'); } diff --git a/packages/utils/src/promisebuffer.ts b/packages/utils/src/promisebuffer.ts index 6866a42ee4f9..429d3dc62d4b 100644 --- a/packages/utils/src/promisebuffer.ts +++ b/packages/utils/src/promisebuffer.ts @@ -90,7 +90,6 @@ export function makePromiseBuffer(limit?: number): PromiseBuffer { // if all promises resolve in time, cancel the timer and resolve to `true` buffer.forEach(item => { void resolvedSyncPromise(item).then(() => { - // eslint-disable-next-line no-plusplus if (!--counter) { clearTimeout(capturedSetTimeout); resolve(true); diff --git a/packages/utils/src/stacktrace.ts b/packages/utils/src/stacktrace.ts index 87e27aa750cd..c5a02856aef7 100644 --- a/packages/utils/src/stacktrace.ts +++ b/packages/utils/src/stacktrace.ts @@ -130,7 +130,6 @@ function node(getModule?: GetModuleFn): StackLineParserFn { let methodStart = functionName.lastIndexOf('.'); if (functionName[methodStart - 1] === '.') { - // eslint-disable-next-line no-plusplus methodStart--; } From fef0ab43fa73b91f2a8a08aae952f0b938106fdc Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 29 Nov 2022 12:20:02 +0100 Subject: [PATCH 2/2] ref: Replace `+=1` && `-=1` with `++` / `--` --- packages/browser/src/helpers.ts | 4 ++-- packages/browser/test/integration/polyfills/promise.js | 8 ++++---- packages/core/src/baseclient.ts | 6 +++--- packages/core/test/mocks/transport.ts | 4 ++-- packages/gatsby/test/integration.test.tsx | 2 +- packages/integration-tests/utils/helpers.ts | 2 +- packages/integration-tests/utils/web-vitals/cls.ts | 4 ++-- packages/node/src/integrations/http.ts | 2 +- packages/tracing/src/browser/request.ts | 4 ++-- packages/tracing/src/idletransaction.ts | 2 +- packages/utils/src/instrument.ts | 4 ++-- packages/utils/src/normalize.ts | 2 +- packages/vue/src/components.ts | 2 +- scripts/ensure-bundle-deps.ts | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/browser/src/helpers.ts b/packages/browser/src/helpers.ts index 19fedc0a606e..68a1d25f00ce 100644 --- a/packages/browser/src/helpers.ts +++ b/packages/browser/src/helpers.ts @@ -25,9 +25,9 @@ export function shouldIgnoreOnError(): boolean { */ export function ignoreNextOnError(): void { // onerror should trigger before setTimeout - ignoreOnError += 1; + ignoreOnError++; setTimeout(() => { - ignoreOnError -= 1; + ignoreOnError--; }); } diff --git a/packages/browser/test/integration/polyfills/promise.js b/packages/browser/test/integration/polyfills/promise.js index a0af14994c34..5aae1ad18649 100644 --- a/packages/browser/test/integration/polyfills/promise.js +++ b/packages/browser/test/integration/polyfills/promise.js @@ -467,11 +467,11 @@ var id = 0; function nextId() { - return (id += 1); + return ++id; } function makePromise(promise) { - promise[PROMISE_ID] = id += 1; + promise[PROMISE_ID] = ++id; promise._state = undefined; promise._result = undefined; promise._subscribers = []; @@ -534,7 +534,7 @@ if (_then === then && entry._state !== PENDING) { this._settledAt(entry._state, i, entry._result); } else if (typeof _then !== 'function') { - this._remaining -= 1; + this._remaining--; this._result[i] = entry; } else if (c === Promise$2) { var promise = new c(noop); @@ -561,7 +561,7 @@ var promise = this.promise; if (promise._state === PENDING) { - this._remaining -= 1; + this._remaining--; if (state === REJECTED) { reject(promise, value); diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index 1f2bc293caf2..d4aeeca5fc8a 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -714,14 +714,14 @@ export abstract class BaseClient implements Client { * Occupies the client with processing and event */ protected _process(promise: PromiseLike): void { - this._numProcessing += 1; + this._numProcessing++; void promise.then( value => { - this._numProcessing -= 1; + this._numProcessing--; return value; }, reason => { - this._numProcessing -= 1; + this._numProcessing--; return reason; }, ); diff --git a/packages/core/test/mocks/transport.ts b/packages/core/test/mocks/transport.ts index dca1b52c7643..0541dab4a77d 100644 --- a/packages/core/test/mocks/transport.ts +++ b/packages/core/test/mocks/transport.ts @@ -18,10 +18,10 @@ export function makeFakeTransport(delay: number = 2000): { let sentCount = 0; const makeTransport = () => createTransport({ recordDroppedEvent: () => undefined, textEncoder: new TextEncoder() }, () => { - sendCalled += 1; + sendCalled++; return new SyncPromise(async res => { await sleep(delay); - sentCount += 1; + sentCount++; res({}); }); }); diff --git a/packages/gatsby/test/integration.test.tsx b/packages/gatsby/test/integration.test.tsx index 3fd06dc21990..fcad48c60032 100644 --- a/packages/gatsby/test/integration.test.tsx +++ b/packages/gatsby/test/integration.test.tsx @@ -22,7 +22,7 @@ describe('useEffect', () => { onClientEntry(undefined, { beforeSend: (event: any) => { expect(event).not.toBeUndefined(); - calls += 1; + calls++; return null; }, diff --git a/packages/integration-tests/utils/helpers.ts b/packages/integration-tests/utils/helpers.ts index d2a806b81bd4..9bacf6e9fbde 100644 --- a/packages/integration-tests/utils/helpers.ts +++ b/packages/integration-tests/utils/helpers.ts @@ -69,7 +69,7 @@ async function getMultipleRequests( function requestHandler(request: Request): void { if (urlRgx.test(request.url())) { try { - reqCount -= 1; + reqCount--; requestData.push(requestParser(request)); if (reqCount === 0) { diff --git a/packages/integration-tests/utils/web-vitals/cls.ts b/packages/integration-tests/utils/web-vitals/cls.ts index 7c0665769f08..8987d6a5fa7a 100644 --- a/packages/integration-tests/utils/web-vitals/cls.ts +++ b/packages/integration-tests/utils/web-vitals/cls.ts @@ -25,7 +25,7 @@ async function moveBy(elem: HTMLParagraphElement, percent: number): Promise max) { return; } @@ -52,7 +52,7 @@ function howMany(desiredCls: number): { extraSteps: number; createParagraphs: nu const extraSteps = Math.round((desiredCls - fullRuns * 0.095) / 0.005); let create = fullRuns; if (extraSteps > 0) { - create += 1; + create++; } return { extraSteps: extraSteps, createParagraphs: create }; diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index e4da4195f54e..9fbc79c335b4 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -247,7 +247,7 @@ function _createWrappedRequestMethodFactory( const transaction = parentSpan.transaction; if (transaction) { - transaction.metadata.propagations += 1; + transaction.metadata.propagations++; } } } diff --git a/packages/tracing/src/browser/request.ts b/packages/tracing/src/browser/request.ts index c065318ae360..dbd041619699 100644 --- a/packages/tracing/src/browser/request.ts +++ b/packages/tracing/src/browser/request.ts @@ -216,7 +216,7 @@ export function fetchCallback( options, ); - activeTransaction.metadata.propagations += 1; + activeTransaction.metadata.propagations++; } } } @@ -351,7 +351,7 @@ export function xhrCallback( handlerData.xhr.setRequestHeader(BAGGAGE_HEADER_NAME, sentryBaggageHeader); } - activeTransaction.metadata.propagations += 1; + activeTransaction.metadata.propagations++; } catch (_) { // Error: InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED. } diff --git a/packages/tracing/src/idletransaction.ts b/packages/tracing/src/idletransaction.ts index 6bc72d8e6ce2..f509ff931a45 100644 --- a/packages/tracing/src/idletransaction.ts +++ b/packages/tracing/src/idletransaction.ts @@ -265,7 +265,7 @@ export class IdleTransaction extends Transaction { const heartbeatString = Object.keys(this.activities).join(''); if (heartbeatString === this._prevHeartbeatString) { - this._heartbeatCounter += 1; + this._heartbeatCounter++; } else { this._heartbeatCounter = 1; } diff --git a/packages/utils/src/instrument.ts b/packages/utils/src/instrument.ts index c9f4c75a658b..319ac5e538a3 100644 --- a/packages/utils/src/instrument.ts +++ b/packages/utils/src/instrument.ts @@ -526,7 +526,7 @@ function instrumentDOM(): void { originalAddEventListener.call(this, type, handler, options); } - handlerForType.refCount += 1; + handlerForType.refCount++; } catch (e) { // Accessing dom properties is always fragile. // Also allows us to skip `addEventListenrs` calls with no proper `this` context. @@ -554,7 +554,7 @@ function instrumentDOM(): void { const handlerForType = handlers[type]; if (handlerForType) { - handlerForType.refCount -= 1; + handlerForType.refCount--; // If there are no longer any custom handlers of the current type on this element, we can remove ours, too. if (handlerForType.refCount <= 0) { originalRemoveEventListener.call(this, type, handlerForType.handler, options); diff --git a/packages/utils/src/normalize.ts b/packages/utils/src/normalize.ts index d2061af89a8c..ebeb5f0ff318 100644 --- a/packages/utils/src/normalize.ts +++ b/packages/utils/src/normalize.ts @@ -147,7 +147,7 @@ function visit( const visitValue = visitable[visitKey]; normalized[visitKey] = visit(visitKey, visitValue, depth - 1, maxProperties, memo); - numAdded += 1; + numAdded++; } // Once we've visited all the branches, remove the parent from memo storage diff --git a/packages/vue/src/components.ts b/packages/vue/src/components.ts index 654611d701cf..9aa78a5a23dc 100644 --- a/packages/vue/src/components.ts +++ b/packages/vue/src/components.ts @@ -61,7 +61,7 @@ export const generateComponentTrace = (vm?: ViewModel): string => { const last = tree[tree.length - 1] as any; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (last.constructor === vm.constructor) { - currentRecursiveSequence += 1; + currentRecursiveSequence++; vm = vm.$parent; // eslint-disable-line no-param-reassign continue; } else if (currentRecursiveSequence > 0) { diff --git a/scripts/ensure-bundle-deps.ts b/scripts/ensure-bundle-deps.ts index 06bdaf863582..cf14c819f509 100644 --- a/scripts/ensure-bundle-deps.ts +++ b/scripts/ensure-bundle-deps.ts @@ -74,7 +74,7 @@ export async function ensureBundleBuildPrereqs(options: { while (retries < maxRetries && !checkForBundleDeps(packagesDir, dependencyDirs)) { console.log('Bundle dependencies not found. Trying again in 5 seconds.'); - retries += 1; + retries++; await sleep(5000); }