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

Commit

Permalink
fix: create a copy of defaultConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 5, 2021
1 parent ff5e6b2 commit 1d9db83
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export interface ConfigSchema {
globalNodePath: string | null,
}

export const defaultConfig = {
export const defaultConfig = Object.freeze({
enableSemanticRules: false,
rulesDirectory: "",
fixOnSave: false,
ignoreTypings: false,
useLocalTslint: true,
useGlobalTslint: false,
globalNodePath: "",
}
} as const)
4 changes: 2 additions & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -17,9 +18,7 @@ process.title = 'linter-tslint worker';

const tslintModuleName = 'tslint';
const tslintCache = new Map<string, typeof Tslint.Linter>();
const config: ConfigSchema = {
useLocalTslint: false,
};
const config: ConfigSchema = { ...defaultConfig } // copy of default config

let fallbackLinter: typeof Tslint.Linter;
let requireResolve: typeof import("resolve");
Expand Down Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions lib/workerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class WorkerHelper {
export type ConfigMessage = {
messageType: 'config',
message: {
key: string,
value: any,
key: keyof ConfigSchema,
value: boolean | string | null,
}
}

Expand Down

0 comments on commit 1d9db83

Please sign in to comment.