From 2c50c2ff0ba842f7da0ad7aabb4a047e6176f257 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 26 Apr 2018 09:52:50 -0700 Subject: [PATCH] Add tslint --- package.json | 5 +- src/color.ts | 2 +- src/index.ts | 6 +-- src/interfaces.ts | 10 ++-- src/rules.ts | 8 +-- src/vscodeThemeGenerator.ts | 6 +-- tslint.json | 105 ++++++++++++++++++++++++++++++++++++ 7 files changed, 125 insertions(+), 17 deletions(-) create mode 100644 tslint.json diff --git a/package.json b/package.json index e2f88f4..df6840c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "tsc", "prestart": "tsc demo/generate.ts", "start": "node demo/generate.js", - "prepublish": "npm run build" + "prepublish": "npm run build", + "lint": "tslint src/*.ts" }, "author": "Tyriar", "license": "MIT", @@ -22,6 +23,8 @@ "typings": "dist/index", "devDependencies": { "@types/node": "^6.0.41", + "tslint": "^5.9.1", + "tslint-consistent-codestyle": "^1.13.0", "typescript": "^2.8.3" } } diff --git a/src/color.ts b/src/color.ts index b1fa2d3..614443a 100644 --- a/src/color.ts +++ b/src/color.ts @@ -1,4 +1,4 @@ -import { IColorSet, IBaseColorSet } from "./interfaces"; +import { IColorSet, IBaseColorSet } from './interfaces'; export function lighten(color: string, amount: number): string { const MAX = 255; diff --git a/src/index.ts b/src/index.ts index cb1bbea..9ab5ab6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,9 @@ import * as fs from 'fs'; import * as path from 'path'; -import { IColorSet } from './interfaces' -import { VscodeThemeGenerator } from './vscodeThemeGenerator' +import { IColorSet } from './interfaces'; +import { VscodeThemeGenerator } from './vscodeThemeGenerator'; -export function generateTheme(themeName: string, colorSet: IColorSet, outputFile: string) { +export function generateTheme(themeName: string, colorSet: IColorSet, outputFile: string): void { const themeJson = new VscodeThemeGenerator().generateTheme(themeName, colorSet); fs.writeFileSync(outputFile, themeJson); } diff --git a/src/interfaces.ts b/src/interfaces.ts index acb3afb..f22d515 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -14,7 +14,7 @@ export interface IBaseColorSet { } export interface IColorSet { - base: IBaseColorSet, + base: IBaseColorSet; syntax?: { boolean?: string; function?: string; @@ -33,7 +33,7 @@ export interface IColorSet { cssId?: string; cssTag?: string; markdownQuote?: string; - } + }; ui?: { /** The color of the editor cursor/caret */ cursor?: string; @@ -56,7 +56,7 @@ export interface IColorSet { wordHighlight?: string; wordHighlightStrong?: string; activeLinkForeground?: string; - }, + }; terminal?: { black?: string; red?: string; @@ -74,6 +74,6 @@ export interface IColorSet { brightMagenta?: string; brightCyan?: string; brightWhite?: string; - }, - overrides?: { [key: string]: string } + }; + overrides?: { [key: string]: string }; } diff --git a/src/rules.ts b/src/rules.ts index fa09a6d..82a94b0 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -1,4 +1,4 @@ -import { IColorSet, IThemeGenerator, IBaseColorSet } from './interfaces' +import { IColorSet, IThemeGenerator, IBaseColorSet } from './interfaces'; import { darken, lighten } from './color'; export interface IVscodeJsonThemeSetting { @@ -18,7 +18,7 @@ export interface IRuleGenerator { generate: ColorGenerator; } -enum FontStyle { +const enum FontStyle { NONE = 0, ITALIC = 1 << 0, BOLD = 1 << 1, @@ -32,7 +32,7 @@ function getGlobalSettingGenerator(name: string): ColorGenerator { } const result: any = {}; result[name] = color; - return result + return result; }; } @@ -59,7 +59,7 @@ function getSimpleColorGenerator(name: string, scope: string, fontStyle: number colorRule.settings.fontStyle = fontStyles.join(' '); } return colorRule; - } + }; } export const globalRules: IRuleGenerator[] = [ diff --git a/src/vscodeThemeGenerator.ts b/src/vscodeThemeGenerator.ts index 582ff8e..54b3f66 100644 --- a/src/vscodeThemeGenerator.ts +++ b/src/vscodeThemeGenerator.ts @@ -1,4 +1,4 @@ -import { IColorSet, IThemeGenerator, IBaseColorSet } from './interfaces' +import { IColorSet, IThemeGenerator, IBaseColorSet } from './interfaces'; import { darken, lighten, generateFallbackColorSet, addAlpha } from './color'; import { tokenRules, globalRules, IVscodeJsonThemeSetting } from './rules'; @@ -50,7 +50,7 @@ export class VscodeThemeGenerator implements IThemeGenerator { return JSON.stringify(theme, null, 2); } - private _applyWorkbenchColors(theme: IVscodeJsonTheme, colorSet: IColorSet) { + private _applyWorkbenchColors(theme: IVscodeJsonTheme, colorSet: IColorSet): void { const background1 = darken(colorSet.base.background, 0.2); const background2 = colorSet.base.background; const background3 = lighten(colorSet.base.background, 0.2); @@ -146,7 +146,7 @@ export class VscodeThemeGenerator implements IThemeGenerator { theme.colors['tab.activeBorder'] = colorSet.base.color1; theme.colors['tab.inactiveBackground'] = background4; // tab.inactiveForeground: Inactive tab foreground color in an active group. Tabs are the containers for editors in the editor area. Multiple tabs can be opened in one editor group. There can be multiple editor groups. - + // Editor Colors // editor.background: Editor background color. theme.colors['editor.background'] = background2; diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..a329710 --- /dev/null +++ b/tslint.json @@ -0,0 +1,105 @@ +{ + "rulesDirectory": [ + "tslint-consistent-codestyle" + ], + "rules": { + "array-type": [ + true, + "array" + ], + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": [ + true, + "ignore-same-line" + ], + "indent": [ + true, + "spaces" + ], + "interface-name": [ + true, + "always-prefix" + ], + "interface-over-type-literal": true, + "typedef": [ + true, + "call-signature", + "parameter" + ], + "eofline": true, + "no-duplicate-imports": true, + "no-eval": true, + "no-internal-module": true, + "no-trailing-whitespace": true, + "one-variable-per-declaration": true, + "no-unsafe-finally": true, + "no-var-keyword": true, + "quotemark": [ + true, + "single" + ], + "semicolon": [ + true, + "always" + ], + "trailing-comma": [ + true, + { + "multiline": { + "objects": "never", + "arrays": "never", + "functions": "never", + "typeLiterals": "ignore" + }, + "esSpecCompliant": true + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "variable-name": [ + true, + "ban-keywords", + "check-format", + "allow-leading-underscore" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-module", + "check-operator", + "check-rest-spread", + "check-separator", + "check-type", + "check-type-operator", + "check-preblock" + ], + + "naming-convention": [ + true, + {"type": "property", "modifiers": ["public", "static", "const"], "format": "UPPER_CASE"} + ], + "no-else-after-return": { + "options": "allow-else-if" + }, + "prefer-const-enum": [ + true + ] + } + } \ No newline at end of file