From e87b68525b44d91477fd922ad7433dd70f8d4cba Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Fri, 7 Sep 2018 12:42:24 +0200 Subject: [PATCH] Add tslint --- package.json | 4 ++ src/BuildService.ts | 8 +-- src/ExtractService.ts | 8 +-- src/FileService.ts | 2 +- src/index.ts | 6 +- tslint.json | 34 ++++++++++ yarn.lock | 154 +++++++++++++++++++++++++++++++++++++++++- 7 files changed, 202 insertions(+), 14 deletions(-) create mode 100644 tslint.json diff --git a/package.json b/package.json index 7ac7f0b4..e6e1ba91 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,9 @@ "jasmine": "3.2.0", "prettier": "1.14.2", "rimraf": "2.6.2", + "tslint": "5.11.0", + "tslint-config-prettier": "1.15.0", + "tslint-plugin-prettier": "1.3.0", "typescript": "3.0.3" }, "files": [ @@ -30,6 +33,7 @@ "build": "tsc", "clean": "rimraf dist", "dist": "yarn clean && yarn build", + "lint": "tslint --project tsconfig.json", "prettier": "prettier --write \"src/*.ts\" \"spec/*.js\"", "test": "yarn dist && jasmine" }, diff --git a/src/BuildService.ts b/src/BuildService.ts index de6b0b5e..52881091 100644 --- a/src/BuildService.ts +++ b/src/BuildService.ts @@ -1,9 +1,9 @@ -import * as logdown from 'logdown'; import * as JSZip from 'jszip'; +import * as logdown from 'logdown'; import * as path from 'path'; import * as progress from 'progress'; +import {FileService, fsPromise} from './FileService'; import {CLIOptions, Entry} from './Interfaces'; -import {fsPromise, FileService} from './FileService'; class BuildService { private readonly fileService: FileService; @@ -12,7 +12,7 @@ class BuildService { private readonly options: Required; private readonly progressBar: progress; private entries: Entry[]; - private ignoreEntries: RegExp[]; + private readonly ignoreEntries: RegExp[]; public outputFile: string | null; public compressedFilesCount: number; @@ -56,11 +56,11 @@ class BuildService { return this.jszip.generateAsync( { - type: 'nodebuffer', compression: compressionType, compressionOptions: { level: this.options.compressionLevel, }, + type: 'nodebuffer', }, ({percent}) => { const diff = Math.floor(percent) - Math.floor(lastPercent); diff --git a/src/ExtractService.ts b/src/ExtractService.ts index 3fc7853e..38ac8391 100644 --- a/src/ExtractService.ts +++ b/src/ExtractService.ts @@ -1,10 +1,10 @@ -import * as logdown from 'logdown'; import * as JSZip from 'jszip'; -import * as path from 'path'; +import * as logdown from 'logdown'; import * as os from 'os'; +import * as path from 'path'; import * as progress from 'progress'; +import {FileService, fsPromise} from './FileService'; import {CLIOptions} from './Interfaces'; -import {fsPromise, FileService} from './FileService'; class ExtractService { private readonly fileService: FileService; @@ -43,7 +43,7 @@ class ExtractService { const resolvedPath = path.resolve(entry); const data = await this.fileService.readFile(resolvedPath); - const entries: [string, JSZip.JSZipObject][] = []; + const entries: Array<[string, JSZip.JSZipObject]> = []; await jszip.loadAsync(data, {createFolders: true}); diff --git a/src/FileService.ts b/src/FileService.ts index 3907f179..1f47ecc9 100644 --- a/src/FileService.ts +++ b/src/FileService.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; -import * as path from 'path'; import * as logdown from 'logdown'; +import * as path from 'path'; import {promisify} from 'util'; import {CLIOptions} from './Interfaces'; diff --git a/src/index.ts b/src/index.ts index a3ab6b35..fd84434b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ -import {CLIOptions} from './Interfaces'; import {BuildService} from './BuildService'; import {ExtractService} from './ExtractService'; +import {CLIOptions} from './Interfaces'; const defaultOptions: Required = { + compressionLevel: 5, dereferenceLinks: false, force: false, ignoreEntries: [], - compressionLevel: 5, outputEntry: null, quiet: false, verbose: false, @@ -15,7 +15,7 @@ const defaultOptions: Required = { export class JSZipCLI { private readonly buildService: BuildService; private readonly extractService: ExtractService; - private options: Required; + private readonly options: Required; constructor(options: CLIOptions = defaultOptions) { this.options = {...defaultOptions, ...options}; diff --git a/tslint.json b/tslint.json new file mode 100644 index 00000000..6b20a4f7 --- /dev/null +++ b/tslint.json @@ -0,0 +1,34 @@ +{ + "extends": ["tslint-config-prettier", "tslint-plugin-prettier"], + "rules": { + "array-type": [true, "array-simple"], + "ban-comma-operator": true, + "curly": true, + "jsdoc-format": [true, "check-multiline-start"], + "no-duplicate-imports": true, + "no-duplicate-switch-case": true, + "no-duplicate-variable": [true, "check-parameters"], + "no-invalid-template-strings": true, + "no-object-literal-type-assertion": true, + "no-return-await": true, + "no-sparse-arrays": true, + "ordered-imports": [ + true, + { + "named-imports-order": "lowercase-last" + } + ], + "no-this-assignment": true, + "object-literal-sort-keys": true, + "prefer-conditional-expression": true, + "prefer-const": true, + "prefer-object-spread": true, + "prefer-readonly": true, + "prefer-template": true, + "prettier": true, + "space-within-parens": [true, 0] + }, + "linterOptions": { + "exclude": ["**/bower_components/**", "**/dist/**", "**/node_modules/**"] + } +} diff --git a/yarn.lock b/yarn.lock index ded459b0..1336086b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,12 +18,34 @@ dependencies: "@types/node" "*" +ansi-regex@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + +ansi-styles@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" + ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" dependencies: color-convert "^1.9.0" +argparse@^1.0.7: + version "1.0.10" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" + dependencies: + sprintf-js "~1.0.2" + +babel-code-frame@^6.22.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" + dependencies: + chalk "^1.1.3" + esutils "^2.0.2" + js-tokens "^3.0.2" + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -35,6 +57,20 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +builtin-modules@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" + +chalk@^1.1.3: + version "1.1.3" + resolved "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" + dependencies: + ansi-styles "^2.2.1" + escape-string-regexp "^1.0.2" + has-ansi "^2.0.0" + strip-ansi "^3.0.0" + supports-color "^2.0.0" + chalk@^2.3.0: version "2.4.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" @@ -57,6 +93,10 @@ commander@2.18.0: version "2.18.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.18.0.tgz#2bf063ddee7c7891176981a2cc798e5754bc6970" +commander@^2.12.1: + version "2.18.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.18.0.tgz#2bf063ddee7c7891176981a2cc798e5754bc6970" + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -69,19 +109,42 @@ core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" +diff@^3.2.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" + es6-promise@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-3.0.2.tgz#010d5858423a5f118979665f46486a95c6ee2bb6" -escape-string-regexp@^1.0.5: +escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" +eslint-plugin-prettier@^2.2.0: + version "2.6.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.6.2.tgz#71998c60aedfa2141f7bfcbf9d1c459bf98b4fad" + dependencies: + fast-diff "^1.1.1" + jest-docblock "^21.0.0" + +esprima@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" + +esutils@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" + +fast-diff@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" -glob@^7.0.5, glob@^7.0.6: +glob@^7.0.5, glob@^7.0.6, glob@^7.1.1: version "7.1.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" dependencies: @@ -92,6 +155,12 @@ glob@^7.0.5, glob@^7.0.6: once "^1.3.0" path-is-absolute "^1.0.0" +has-ansi@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" + dependencies: + ansi-regex "^2.0.0" + has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" @@ -126,6 +195,21 @@ jasmine@3.2.0: glob "^7.0.6" jasmine-core "~3.2.0" +jest-docblock@^21.0.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" + +js-tokens@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" + +js-yaml@^3.7.0: + version "3.12.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1" + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + jszip@3.1.5: version "3.1.5" resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.1.5.tgz#e3c2a6c6d706ac6e603314036d43cd40beefdf37" @@ -168,6 +252,10 @@ path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" +path-parse@^1.0.5: + version "1.0.6" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + prettier@1.14.2: version "1.14.2" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.2.tgz#0ac1c6e1a90baa22a62925f41963c841983282f9" @@ -191,22 +279,84 @@ readable-stream@~2.0.6: string_decoder "~0.10.x" util-deprecate "~1.0.1" +resolve@^1.3.2: + version "1.8.1" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26" + dependencies: + path-parse "^1.0.5" + rimraf@2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" dependencies: glob "^7.0.5" +semver@^5.3.0: + version "5.5.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477" + +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + string_decoder@~0.10.x: version "0.10.31" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" +strip-ansi@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" + dependencies: + ansi-regex "^2.0.0" + +supports-color@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + supports-color@^5.3.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" dependencies: has-flag "^3.0.0" +tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1: + version "1.9.3" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" + +tslint-config-prettier@1.15.0: + version "1.15.0" + resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.15.0.tgz#76b9714399004ab6831fdcf76d89b73691c812cf" + +tslint-plugin-prettier@1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/tslint-plugin-prettier/-/tslint-plugin-prettier-1.3.0.tgz#7eb65d19ea786a859501a42491b78c5de2031a3f" + dependencies: + eslint-plugin-prettier "^2.2.0" + tslib "^1.7.1" + +tslint@5.11.0: + version "5.11.0" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.11.0.tgz#98f30c02eae3cde7006201e4c33cb08b48581eed" + dependencies: + babel-code-frame "^6.22.0" + builtin-modules "^1.1.1" + chalk "^2.3.0" + commander "^2.12.1" + diff "^3.2.0" + glob "^7.1.1" + js-yaml "^3.7.0" + minimatch "^3.0.4" + resolve "^1.3.2" + semver "^5.3.0" + tslib "^1.8.0" + tsutils "^2.27.2" + +tsutils@^2.27.2: + version "2.29.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99" + dependencies: + tslib "^1.8.1" + typescript@3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"