From 0fa98a262ae90b2ced48fa5dbeaaac568caa0cc7 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Sat, 24 Jun 2023 19:15:35 +0200 Subject: [PATCH] fixes for `prefer-class-properties` (#3277) Co-Authored-By: Dimitri POSTOLOV --- .eslintrc.js | 1 + .../graphiql-toolkit/src/storage/__tests__/query.spec.ts | 3 +-- .../src/parser/CharacterStream.ts | 6 ++---- packages/monaco-graphql/src/workerManager.ts | 9 +++------ 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2fe883f22c0..9c371e0cf7f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -61,6 +61,7 @@ module.exports = { }, rules: { '@shopify/prefer-early-return': ['error', { maximumStatements: 2 }], + '@shopify/prefer-class-properties': 'off', // enable after https://github.com/Shopify/web-configs/issues/387 will be fixed 'sonarjs/no-inverted-boolean-check': 'error', '@arthurgeron/react-usememo/require-usememo': [ 'error', diff --git a/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts b/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts index 2c0d70fe61d..a59f9cdd22c 100644 --- a/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts +++ b/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts @@ -4,11 +4,10 @@ import { QueryStore } from '../query'; class StorageMock { shouldThrow: () => boolean; count: number; - map: any; + map = {}; storage: Storage; constructor(shouldThrow: () => boolean) { this.shouldThrow = shouldThrow; - this.map = {}; } set(key: string, value: string) { diff --git a/packages/graphql-language-service/src/parser/CharacterStream.ts b/packages/graphql-language-service/src/parser/CharacterStream.ts index 6675472132a..0d6120e5bdb 100644 --- a/packages/graphql-language-service/src/parser/CharacterStream.ts +++ b/packages/graphql-language-service/src/parser/CharacterStream.ts @@ -20,13 +20,11 @@ import { TokenPattern, CharacterStreamInterface } from './types'; export default class CharacterStream implements CharacterStreamInterface { - private _start: number; - private _pos: number; + private _start = 0; + private _pos = 0; private _sourceText: string; constructor(sourceText: string) { - this._start = 0; - this._pos = 0; this._sourceText = sourceText; } diff --git a/packages/monaco-graphql/src/workerManager.ts b/packages/monaco-graphql/src/workerManager.ts index 8697a26c8c7..3d3fa8ea1b4 100644 --- a/packages/monaco-graphql/src/workerManager.ts +++ b/packages/monaco-graphql/src/workerManager.ts @@ -15,24 +15,21 @@ const STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min export class WorkerManager { private _defaults: MonacoGraphQLAPI; private _idleCheckInterval: number; - private _lastUsedTime: number; + private _lastUsedTime = 0; private _configChangeListener: IDisposable; - private _worker: editor.MonacoWebWorker | null; - private _client: GraphQLWorker | null; + private _worker: editor.MonacoWebWorker | null = null; + private _client: GraphQLWorker | null = null; constructor(defaults: MonacoGraphQLAPI) { this._defaults = defaults; - this._worker = null; this._idleCheckInterval = window.setInterval( () => this._checkIfIdle(), 30 * 1000, ); - this._lastUsedTime = 0; // this is where we re-start the worker on config changes this._configChangeListener = this._defaults.onDidChange(() => { this._stopWorker(); }); - this._client = null; } private _stopWorker(): void {