diff --git a/lib/config.ts b/lib/config.ts new file mode 100644 index 00000000..782a635c --- /dev/null +++ b/lib/config.ts @@ -0,0 +1,68 @@ +export const config = { + "enableSemanticRules": { + "type": "boolean", + "title": "Enable semantic rules", + "description": "Allow passing a TypeScript program object to the linter. May negatively affect performance. See this page for details: https://palantir.github.io/tslint/usage/type-checking/", + "default": false, + "order": 1 + }, + "rulesDirectory": { + "type": "string", + "title": "Custom rules directory (absolute path)", + "default": "", + "order": 2 + }, + "fixOnSave": { + "title": "Fix errors on save", + "description": "Have tslint attempt to fix some errors automatically when saving the file.", + "type": "boolean", + "default": false, + "order": 3 + }, + "ignoreTypings": { + "type": "boolean", + "title": "Ignore typings files (.d.ts)", + "default": false, + "order": 4 + }, + "useLocalTslint": { + "type": "boolean", + "title": "Try to use the project's local tslint package, if it exists", + "default": true, + "order": 5 + }, + "useGlobalTslint": { + "type": "boolean", + "title": "Use the global tslint install", + "description": "If enabled, the global tslint installation will be used as a fallback, instead of the version packaged with linter-tslint.", + "default": false, + "order": 6 + }, + "globalNodePath": { + "type": "string", + "title": "Global node installation path", + "description": "The location of your global npm install. (Will default to `npm get prefix`.)", + "default": "", + "order": 7 + } +} + +export interface ConfigSchema { + enableSemanticRules: boolean, + rulesDirectory: string | null, + fixOnSave: boolean, + ignoreTypings: boolean, + useLocalTslint: boolean, + useGlobalTslint: boolean, + globalNodePath: string | null, +} + +export const defaultConfig = { + enableSemanticRules: false, + rulesDirectory: "", + fixOnSave: false, + ignoreTypings: false, + useLocalTslint: true, + useGlobalTslint: false, + globalNodePath: "", +} diff --git a/lib/main.ts b/lib/main.ts index 04b9707c..a1835e41 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -3,16 +3,13 @@ import path from 'path'; import { promises } from 'fs'; const { stat } = promises; import WorkerHelper from './workerHelper'; +export { config } from './config'; +import { defaultConfig } from "./config" const grammarScopes = ['source.ts', 'source.tsx']; const editorClass = 'linter-tslint-compatible-editor'; const idleCallbacks = new Set(); -const config = { - rulesDirectory: null, - useLocalTslint: false, - useGlobalTslint: false, - globalNodePath: null, -}; +const config = defaultConfig; // 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 b6794ea7..d5deee3c 100644 --- a/lib/worker.ts +++ b/lib/worker.ts @@ -6,12 +6,13 @@ import path from 'path'; import { getRuleUri } from 'tslint-rule-documentation'; import ChildProcess from 'child_process'; import getPath from 'consistent-path'; +import type { ConfigSchema } from "./config" process.title = 'linter-tslint worker'; const tslintModuleName = 'tslint'; const tslintCache = new Map(); -const config = { +const config: ConfigSchema = { useLocalTslint: false, }; @@ -251,7 +252,7 @@ async function lint(content: string, filePath: string, options: object) { }); } -export default async function TsLintWorker(initialConfig: object) { +export default async function TsLintWorker(initialConfig: ConfigSchema) { config.useLocalTslint = initialConfig.useLocalTslint; config.enableSemanticRules = initialConfig.enableSemanticRules; config.useGlobalTslint = initialConfig.useGlobalTslint; diff --git a/lib/workerHelper.ts b/lib/workerHelper.ts index 5781b151..2c476c9c 100644 --- a/lib/workerHelper.ts +++ b/lib/workerHelper.ts @@ -1,7 +1,9 @@ import { Task } from 'atom'; +import type { ConfigSchema } from "./config" import cryptoRandomString from 'crypto-random-string'; export default class WorkerHelper { + workerInstance: Task constructor() { this.workerInstance = null; } @@ -10,7 +12,7 @@ export default class WorkerHelper { return Boolean(this.workerInstance); } - startWorker(config) { + startWorker(config: ConfigSchema) { if (!this.workerInstance) { this.workerInstance = new Task(require.resolve('./worker.js')); this.workerInstance.start(config); diff --git a/package.json b/package.json index 8c3c2ef9..313cf095 100644 --- a/package.json +++ b/package.json @@ -23,54 +23,6 @@ "engines": { "atom": ">=1.14.0 <2.0.0" }, - "configSchema": { - "enableSemanticRules": { - "type": "boolean", - "title": "Enable semantic rules", - "description": "Allow passing a TypeScript program object to the linter. May negatively affect performance. See this page for details: https://palantir.github.io/tslint/usage/type-checking/", - "default": false, - "order": 1 - }, - "rulesDirectory": { - "type": "string", - "title": "Custom rules directory (absolute path)", - "default": "", - "order": 2 - }, - "fixOnSave": { - "title": "Fix errors on save", - "description": "Have tslint attempt to fix some errors automatically when saving the file.", - "type": "boolean", - "default": false, - "order": 3 - }, - "ignoreTypings": { - "type": "boolean", - "title": "Ignore typings files (.d.ts)", - "default": false, - "order": 4 - }, - "useLocalTslint": { - "type": "boolean", - "title": "Try to use the project's local tslint package, if it exists", - "default": true, - "order": 5 - }, - "useGlobalTslint": { - "type": "boolean", - "title": "Use the global tslint install", - "description": "If enabled, the global tslint installation will be used as a fallback, instead of the version packaged with linter-tslint.", - "default": false, - "order": 6 - }, - "globalNodePath": { - "type": "string", - "title": "Global node installation path", - "description": "The location of your global npm install. (Will default to `npm get prefix`.)", - "default": "", - "order": 7 - } - }, "dependencies": { "atom-package-deps": "7.2.3", "consistent-path": "2.0.3",