From 8bef3415423aa135f73fc52e69b0ed802190e7d0 Mon Sep 17 00:00:00 2001 From: JubeatWwW Date: Tue, 5 Nov 2019 17:31:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20linting=20scr?= =?UTF-8?q?ipt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 679db6d..db8614c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "type:declaration": "tsc --noEmit false --emitDeclarationOnly --declaration --declarationDir ./dist", "test": "cross-env TS_NODE_PROJECT=tsconfig.test.json mocha ./test/index.ts", "build": "$npm_execpath run build:babel && $npm_execpath run type:declaration", - "build:babel": "cross-env NODE_ENV=production babel ./src --out-dir ./dist --extensions '.ts'" + "build:babel": "cross-env NODE_ENV=production babel ./src --out-dir ./dist --extensions '.ts'", + "lint": "tslint -r tslint.json src/**/*.ts" }, "repository": { "type": "git", From 79fee0baf8c8f7a514e9904672353c0a8bc789f2 Mon Sep 17 00:00:00 2001 From: JubeatWwW Date: Tue, 5 Nov 2019 17:53:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Change=20tslint?= =?UTF-8?q?=20config=20and=20fix=20linting=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/sites/ptt/bot.ts | 2 +- src/utils/char.ts | 36 +++++----- src/utils/decode.ts | 4 +- src/utils/encode.ts | 4 +- src/utils/index.ts | 6 +- src/utils/keymap.ts | 2 +- tslint.json | 160 +++++++++++++++++++++---------------------- 8 files changed, 103 insertions(+), 113 deletions(-) diff --git a/package.json b/package.json index db8614c..a9a027f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "cross-env TS_NODE_PROJECT=tsconfig.test.json mocha ./test/index.ts", "build": "$npm_execpath run build:babel && $npm_execpath run type:declaration", "build:babel": "cross-env NODE_ENV=production babel ./src --out-dir ./dist --extensions '.ts'", - "lint": "tslint -r tslint.json src/**/*.ts" + "lint": "tslint -c tslint.json src/**/*.ts" }, "repository": { "type": "git", diff --git a/src/sites/ptt/bot.ts b/src/sites/ptt/bot.ts index 4613eb4..ae42c78 100644 --- a/src/sites/ptt/bot.ts +++ b/src/sites/ptt/bot.ts @@ -266,7 +266,7 @@ class Bot extends EventEmitter { } resetSearchCondition(): void { - this.searchCondition.init(); + this.searchCondition.init(); } isSearchConditionSet(): boolean { diff --git a/src/utils/char.ts b/src/utils/char.ts index 367003d..c8b9dd0 100644 --- a/src/utils/char.ts +++ b/src/utils/char.ts @@ -1,15 +1,15 @@ import wcwidth from 'wcwidth'; export function dbcswidth(str: string): number { - return str.split('').reduce(function(sum, c) { + return str.split('').reduce((sum, c) => { return sum + (c.charCodeAt(0) > 255 ? 2 : 1); }, 0); } /** -* calculate width of string. -* @params {string} widthType - calculate width by wcwidth or String.length -* @params {string} str - string to calculate -*/ + * calculate width of string. + * @params {string} widthType - calculate width by wcwidth or String.length + * @params {string} str - string to calculate + */ export function getWidth(widthType: string, str: string): number { switch (widthType) { case 'length': @@ -24,11 +24,11 @@ export function getWidth(widthType: string, str: string): number { } /** -* calculate the position that the prefix of string is a specific width -* @params {string} widthType - calculate width by wcwidth or String.length -* @params {string} str - string to calculate -* @params {number} width - the width of target string -*/ + * calculate the position that the prefix of string is a specific width + * @params {string} widthType - calculate width by wcwidth or String.length + * @params {string} str - string to calculate + * @params {number} width - the width of target string + */ export function indexOfWidth(widthType: string, str: string, width?: number): number { if (widthType === 'length') { return getWidth(widthType, str); @@ -42,14 +42,14 @@ export function indexOfWidth(widthType: string, str: string, width?: number): nu } /** -* extract parts of string, beginning at the character at the specified position, -* and returns the specified width of characters. if the character is incomplete, -* it will be replaced by space. -* @params {string} widthType - calculate width by wcwidth or String.length -* @params {string} str - string to calculate -* @params {number} startWidth - the beginning position of string -* @params {number} width - the width of target string -*/ + * extract parts of string, beginning at the character at the specified position, + * and returns the specified width of characters. if the character is incomplete, + * it will be replaced by space. + * @params {string} widthType - calculate width by wcwidth or String.length + * @params {string} str - string to calculate + * @params {number} startWidth - the beginning position of string + * @params {number} width - the width of target string + */ export function substrWidth(widthType: string, str: string, startWidth: number, width?: number): string { const ignoreWidth = typeof width === 'undefined'; let length = width; diff --git a/src/utils/decode.ts b/src/utils/decode.ts index 225acad..98183e7 100644 --- a/src/utils/decode.ts +++ b/src/utils/decode.ts @@ -1,6 +1,6 @@ import { decodeSync } from 'uao-js'; -const decode = (data, charset) => { +export const decode = (data, charset) => { let str = ''; switch (charset) { case 'utf8': @@ -15,5 +15,3 @@ const decode = (data, charset) => { } return str; }; - -export default decode; diff --git a/src/utils/encode.ts b/src/utils/encode.ts index ed1cd4b..a9518de 100644 --- a/src/utils/encode.ts +++ b/src/utils/encode.ts @@ -1,6 +1,6 @@ import { encodeSync } from 'uao-js'; -const encode = (str, charset) => { +export const encode = (str, charset) => { let buffer; switch (charset) { case 'utf8': @@ -15,5 +15,3 @@ const encode = (str, charset) => { } return buffer; }; - -export default encode; diff --git a/src/utils/index.ts b/src/utils/index.ts index af3887e..5f9276c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,4 @@ export { default as char } from './char'; -export { default as decode } from './decode'; -export { default as encode } from './encode'; -export { default as keymap } from './keymap'; +export { decode } from './decode'; +export { encode } from './encode'; +export { keymap } from './keymap'; diff --git a/src/utils/keymap.ts b/src/utils/keymap.ts index f9cfa4e..f042f43 100644 --- a/src/utils/keymap.ts +++ b/src/utils/keymap.ts @@ -1,4 +1,4 @@ -export default { +export const keymap = { Enter: '\r', ArrowLeft: '\x1b[D', ArrowRight: '\x1b[C', diff --git a/tslint.json b/tslint.json index 7d174a1..49a2f1c 100644 --- a/tslint.json +++ b/tslint.json @@ -1,84 +1,78 @@ { - "rules": { - "arrow-return-shorthand": true, - "callable-types": true, - "class-name": true, - "comment-format": [true, "check-space"], - "curly": true, - "deprecation": { "severity": "warn" }, - "eofline": true, - "forin": true, - "import-blacklist": [true, "rxjs/Rx"], - "import-spacing": true, - "indent": [true, "spaces"], - "interface-over-type-literal": true, - "label-position": true, - "max-line-length": [true, 140], - "member-access": false, - "member-ordering": [ - true, - { - "order": [ - "static-field", - "instance-field", - "static-method", - "instance-method" - ] - } - ], - "no-arg": true, - "no-bitwise": true, - "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], - "no-construct": true, - "no-debugger": true, - "no-duplicate-super": true, - "no-empty": false, - "no-empty-interface": true, - "no-eval": true, - "no-inferrable-types": [true, "ignore-params"], - "no-misused-new": true, - "no-non-null-assertion": true, - "no-shadowed-variable": true, - "no-string-literal": false, - "no-string-throw": true, - "no-switch-case-fall-through": true, - "no-trailing-whitespace": true, - "no-unnecessary-initializer": true, - "no-unused-expression": true, - "no-var-keyword": true, - "object-literal-sort-keys": false, - "one-line": [ - true, - "check-open-brace", - "check-catch", - "check-else", - "check-whitespace" - ], - "prefer-const": true, - "quotemark": [true, "single"], - "radix": true, - "semicolon": [true, "always"], - "triple-equals": [true, "allow-null-check"], - "typedef-whitespace": [ - true, - { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - } - ], - "unified-signatures": true, - "variable-name": false, - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ] - } -} - \ No newline at end of file + "rules": { + "array-type": [true, "array-simple"], + "arrow-return-shorthand": true, + "ban": [true, + {"name": ["it", "skip"]}, + {"name": ["it", "only"]}, + {"name": ["it", "async", "skip"]}, + {"name": ["it", "async", "only"]}, + {"name": ["describe", "skip"]}, + {"name": ["describe", "only"]}, + {"name": "parseInt", "message": "tsstyle#type-coercion"}, + {"name": "parseFloat", "message": "tsstyle#type-coercion"}, + {"name": "Array", "message": "tsstyle#array-constructor"}, + {"name": ["*", "innerText"], "message": "Use .textContent instead. tsstyle#browser-oddities"} + ], + "ban-ts-ignore": true, + "ban-types": [true, + ["Object", "Use {} instead."], + ["String", "Use 'string' instead."], + ["Number", "Use 'number' instead."], + ["Boolean", "Use 'boolean' instead."] + ], + "class-name": true, + "curly": [true, "ignore-same-line"], + "deprecation": true, + "forin": true, + "interface-name": [true, "never-prefix"], + "interface-over-type-literal": true, + "jsdoc-format": true, + "label-position": true, + "member-access": [true, "no-public"], + "new-parens": true, + "no-angle-bracket-type-assertion": true, + "no-any": true, + "no-arg": true, + "no-conditional-assignment": true, + "no-construct": true, + "no-debugger": true, + "no-default-export": true, + "no-duplicate-variable": true, + "no-inferrable-types": true, + "no-namespace": [true, "allow-declarations"], + "no-reference": true, + "no-string-throw": true, + "no-return-await": true, + "no-unsafe-finally": true, + "no-unused-expression": true, + "no-var-keyword": true, + "object-literal-shorthand": true, + "only-arrow-functions": [true, "allow-declarations", "allow-named-functions"], + "prefer-const": true, + "radix": true, + "semicolon": [true, "always", "ignore-bound-class-methods"], + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": { + "objects": "always", + "arrays": "always", + "functions": "never", + "typeLiterals": "ignore" + }, + "esSpecCompliant": true + } + ], + "triple-equals": [true, "allow-null-check"], + "use-isnan": true, + "variable-name": [ + true, + "check-format", + "ban-keywords", + "allow-leading-underscore", + "allow-trailing-underscore" + ] + } + } \ No newline at end of file