Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add linting script #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 -c tslint.json src/**/*.ts"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tslint -c tslint.json --project . -t codeFrame

},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/sites/ptt/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class Bot extends EventEmitter {
}

resetSearchCondition(): void {
this.searchCondition.init();
this.searchCondition.init();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space

}

isSearchConditionSet(): boolean {
Expand Down
36 changes: 18 additions & 18 deletions src/utils/char.ts
Original file line number Diff line number Diff line change
@@ -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':
Expand All @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/utils/decode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeSync } from 'uao-js';

const decode = (data, charset) => {
export const decode = (data, charset) => {
let str = '';
switch (charset) {
case 'utf8':
Expand All @@ -15,5 +15,3 @@ const decode = (data, charset) => {
}
return str;
};

export default decode;
4 changes: 1 addition & 3 deletions src/utils/encode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { encodeSync } from 'uao-js';

const encode = (str, charset) => {
export const encode = (str, charset) => {
let buffer;
switch (charset) {
case 'utf8':
Expand All @@ -15,5 +15,3 @@ const encode = (str, charset) => {
}
return buffer;
};

export default encode;
6 changes: 3 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/utils/keymap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
export const keymap = {
Enter: '\r',
ArrowLeft: '\x1b[D',
ArrowRight: '\x1b[C',
Expand Down
160 changes: 77 additions & 83 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}

"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"
]
}
}