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

Commit

Permalink
fix: move config to config.ts and add types for config
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 5, 2021
1 parent f256c92 commit 20a1e06
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 57 deletions.
68 changes: 68 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
@@ -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: "",
}
9 changes: 3 additions & 6 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/workerHelper.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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);
Expand Down
48 changes: 0 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 20a1e06

Please sign in to comment.