Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 1d9db83

Browse files
committed
fix: create a copy of defaultConfig
1 parent ff5e6b2 commit 1d9db83

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

lib/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ export interface ConfigSchema {
5757
globalNodePath: string | null,
5858
}
5959

60-
export const defaultConfig = {
60+
export const defaultConfig = Object.freeze({
6161
enableSemanticRules: false,
6262
rulesDirectory: "",
6363
fixOnSave: false,
6464
ignoreTypings: false,
6565
useLocalTslint: true,
6666
useGlobalTslint: false,
6767
globalNodePath: "",
68-
}
68+
} as const)

lib/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import path from 'path';
33
import { promises } from 'fs';
44
const { stat } = promises;
55
import { WorkerHelper } from './workerHelper';
6-
import { defaultConfig } from "./config"
6+
import { defaultConfig, ConfigSchema } from "./config"
77

88
const grammarScopes = ['source.ts', 'source.tsx'];
99
const editorClass = 'linter-tslint-compatible-editor';
1010
const idleCallbacks = new Set();
11-
const config = defaultConfig;
11+
const config: ConfigSchema = { ...defaultConfig } // copy of default config
1212

1313
// Worker still hasn't initialized, since the queued idle callbacks are
1414
// done in order, waiting on a newly queued idle callback will ensure that

lib/worker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getRuleUri } from 'tslint-rule-documentation';
77
import ChildProcess from 'child_process';
88
import getPath from 'consistent-path';
99
import { shim } from "./compat-shim";
10+
import { defaultConfig } from "./config"
1011
import type { ConfigSchema } from "./config"
1112
import type { emit } from 'node:cluster';
1213
import type * as Tslint from "tslint";
@@ -17,9 +18,7 @@ process.title = 'linter-tslint worker';
1718

1819
const tslintModuleName = 'tslint';
1920
const tslintCache = new Map<string, typeof Tslint.Linter>();
20-
const config: ConfigSchema = {
21-
useLocalTslint: false,
22-
};
21+
const config: ConfigSchema = { ...defaultConfig } // copy of default config
2322

2423
let fallbackLinter: typeof Tslint.Linter;
2524
let requireResolve: typeof import("resolve");
@@ -233,6 +232,7 @@ async function TsLintWorker(initialConfig: ConfigSchema) {
233232

234233
process.on('message', async (message: JobMessage | ConfigMessage) => {
235234
if (message.messageType === 'config') {
235+
// set the config for the worker
236236
config[message.message.key] = message.message.value;
237237

238238
if (message.message.key === 'useLocalTslint') {

lib/workerHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export class WorkerHelper {
8181
export type ConfigMessage = {
8282
messageType: 'config',
8383
message: {
84-
key: string,
85-
value: any,
84+
key: keyof ConfigSchema,
85+
value: boolean | string | null,
8686
}
8787
}
8888

0 commit comments

Comments
 (0)