diff --git a/lib/config.ts b/lib/config.ts index 782a635c..3c3050c3 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -57,7 +57,7 @@ export interface ConfigSchema { globalNodePath: string | null, } -export const defaultConfig = { +export const defaultConfig = Object.freeze({ enableSemanticRules: false, rulesDirectory: "", fixOnSave: false, @@ -65,4 +65,4 @@ export const defaultConfig = { useLocalTslint: true, useGlobalTslint: false, globalNodePath: "", -} +} as const) diff --git a/lib/main.ts b/lib/main.ts index aeacd61f..a04fb051 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -3,12 +3,12 @@ import path from 'path'; import { promises } from 'fs'; const { stat } = promises; import { WorkerHelper } from './workerHelper'; -import { defaultConfig } from "./config" +import { defaultConfig, ConfigSchema } from "./config" const grammarScopes = ['source.ts', 'source.tsx']; const editorClass = 'linter-tslint-compatible-editor'; const idleCallbacks = new Set(); -const config = defaultConfig; +const config: ConfigSchema = { ...defaultConfig } // copy of default config // Worker still hasn't initialized, since the queued idle callbacks are // done in order, waiting on a newly queued idle callback will ensure that diff --git a/lib/worker.ts b/lib/worker.ts index 660a9cdd..e632bfdf 100644 --- a/lib/worker.ts +++ b/lib/worker.ts @@ -7,6 +7,7 @@ import { getRuleUri } from 'tslint-rule-documentation'; import ChildProcess from 'child_process'; import getPath from 'consistent-path'; import { shim } from "./compat-shim"; +import { defaultConfig } from "./config" import type { ConfigSchema } from "./config" import type { emit } from 'node:cluster'; import type * as Tslint from "tslint"; @@ -17,9 +18,7 @@ process.title = 'linter-tslint worker'; const tslintModuleName = 'tslint'; const tslintCache = new Map(); -const config: ConfigSchema = { - useLocalTslint: false, -}; +const config: ConfigSchema = { ...defaultConfig } // copy of default config let fallbackLinter: typeof Tslint.Linter; let requireResolve: typeof import("resolve"); @@ -233,6 +232,7 @@ async function TsLintWorker(initialConfig: ConfigSchema) { process.on('message', async (message: JobMessage | ConfigMessage) => { if (message.messageType === 'config') { + // set the config for the worker config[message.message.key] = message.message.value; if (message.message.key === 'useLocalTslint') { diff --git a/lib/workerHelper.ts b/lib/workerHelper.ts index 66a4664a..a7492930 100644 --- a/lib/workerHelper.ts +++ b/lib/workerHelper.ts @@ -81,8 +81,8 @@ export class WorkerHelper { export type ConfigMessage = { messageType: 'config', message: { - key: string, - value: any, + key: keyof ConfigSchema, + value: boolean | string | null, } }