Skip to content

Commit

Permalink
feat: use eslint instead of tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Nov 15, 2018
1 parent ef016a1 commit 5066fd8
Show file tree
Hide file tree
Showing 76 changed files with 755 additions and 1,304 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@
"url": "https://github.com/fjc0k"
},
"scripts": {
"lint": "eslint --ext .ts src/",
"testOnly": "jest",
"test": "jest --coverage",
"build": "bili",
"release": "standard-version -a",
"postrelease": "git push --follow-tags origin master && npm publish"
},
"eslintConfig": {
"root": true,
"extends": "io"
},
"standard-version": {
"scripts": {
"postbump": "yarn build && git add -A"
Expand All @@ -59,15 +64,16 @@
"@types/sinon": "^5.0.5",
"bili": "^3.3.4",
"codecov": "^3.1.0",
"eslint": "^5.9.0",
"eslint-config-io": "^0.0.3",
"jest": "^23.6.0",
"moment": "^2.22.2",
"rollup-plugin-typescript2": "^0.17.2",
"sinon": "^6.3.5",
"standard-version": "^4.4.0",
"ts-jest": "^23.10.4",
"tslint": "^5.11.0",
"typed-we-app": "^1.7.0-update.6",
"typescript": "^3.1.1"
"typescript": "^3.1.6"
},
"dependencies": {
"is-chinese-phone-number": "^0.1.9"
Expand Down
8 changes: 4 additions & 4 deletions src/Disposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export default class Disposer {
* @param name 待处置项目名称
* @param dispose 处置行为
*/
public add(name: DisposerItemName, dispose: Dispose | Dispose[]): void {
public add (name: DisposerItemName, dispose: Dispose | Dispose[]): void {
dispose = Array.isArray(dispose) ? dispose : [dispose]
this.jar[name] = [
...(this.jar[name] || []),
...dispose
...dispose,
]
}

Expand All @@ -32,15 +32,15 @@ export default class Disposer {
*
* @param name 欲处置项目名称
*/
public dispose(name: DisposerItemName): void {
public dispose (name: DisposerItemName): void {
(this.jar[name] || /* istanbul ignore next */ []).forEach(dispose => dispose())
delete this.jar[name]
}

/**
* 处置所有未处置项目。
*/
public disposeAll(): void {
public disposeAll (): void {
for (const key in this.jar) {
this.dispose(key)
}
Expand Down
8 changes: 4 additions & 4 deletions src/EventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class EventBus<
* @param listener 监听器
* @returns 取消订阅函数
*/
public on<X extends K>(eventName: X, listener: T[X]): EventBusUnsubscribe {
public on<X extends K> (eventName: X, listener: T[X]): EventBusUnsubscribe {
if (!this.listeners[eventName]) {
this.listeners[eventName] = []
}
Expand All @@ -44,7 +44,7 @@ export default class EventBus<
* @param listener 监听器
* @returns 取消订阅函数
*/
public once<X extends K>(eventName: X, listener: T[X]): EventBusUnsubscribe {
public once<X extends K> (eventName: X, listener: T[X]): EventBusUnsubscribe {
const unsubscribe = this.on(eventName, (...args: any[]) => {
unsubscribe()
listener(...args)
Expand All @@ -58,7 +58,7 @@ export default class EventBus<
* @param eventName 事件名称
* @param [listener] 监听器
*/
public off<X extends K>(eventName: X, listener?: T[X]): void {
public off<X extends K> (eventName: X, listener?: T[X]): void {
if (listener) {
const listeners = this.listeners[eventName]
const index = listeners.indexOf(listener)
Expand All @@ -78,7 +78,7 @@ export default class EventBus<
* @param args 传给监听器的参数
* @returns 各监听器的返回结果组成的数组
*/
public emit<X extends K>(eventName: X, ...args: ArgumentsType<T[X]>): Array<ReturnType<T[X]>> {
public emit<X extends K> (eventName: X, ...args: ArgumentsType<T[X]>): Array<ReturnType<T[X]>> {
return (this.listeners[eventName] || []).map(listener => {
return listener(...args)
})
Expand Down
38 changes: 19 additions & 19 deletions src/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface ValidatorRule {
custom?: RegExp | ValidatorRuleCustom,
}
export interface ValidatorRules {
[key: string]: ValidatorRule | ValidatorRule[]
[key: string]: ValidatorRule | ValidatorRule[],
}

const typeValidators: { [key in ValidatorRuleType]: ValidatorRuleTypePredicate } = {
Expand All @@ -43,10 +43,10 @@ const typeValidators: { [key in ValidatorRuleType]: ValidatorRuleTypePredicate }
landline: isChinesePhoneNumber.landline,
id: isChineseIDCardNumber,
url: isUrl,
email: isEmail
email: isEmail,
}

function validate<D>(data: D, key: keyof D, rule: ValidatorRule): Promise<boolean> {
function validate<D> (data: D, key: keyof D, rule: ValidatorRule): Promise<boolean> {
return new Promise(resolve => {
const value = data[key] as any
const { required, type, len, min, max, custom } = rule
Expand Down Expand Up @@ -110,7 +110,7 @@ export default class Validator<R extends ValidatorRules> {
*
* @param rules 验证规则
*/
constructor(rules: R) {
public constructor (rules: R) {
this.rules = rules
}

Expand All @@ -120,12 +120,12 @@ export default class Validator<R extends ValidatorRules> {
* @param data 要验证的数据
* @returns 验证结果
*/
public validate<D extends { [key in keyof R]: any }>(data: Partial<D>): Promise<
public validate<D extends { [key in keyof R]: any }> (data: Partial<D>): Promise<
{ valid: true } | (
ValidatorRule & {
valid: false,
key: keyof D,
value: D[keyof D]
value: D[keyof D],
}
)
> {
Expand All @@ -137,20 +137,20 @@ export default class Validator<R extends ValidatorRules> {
return resolveItem()
}
return Promise.all(castArray(rules).map(rule => {
return new Promise((resolveRule, rejectRule) => {
validate(data, key, rule).then(valid => {
if (valid) {
resolveRule()
} else {
rejectRule({
...rule,
key,
value: data[key]
})
}
})
return new Promise((resolveRule, rejectRule) => {
validate(data, key, rule).then(valid => {
if (valid) {
resolveRule()
} else {
rejectRule({
...rule,
key,
value: data[key],
})
}
})
})).then(resolveItem, rejectItem)
})
})).then(resolveItem, rejectItem)
})
})).then(
() => resolve({ valid: true }),
Expand Down
2 changes: 1 addition & 1 deletion src/base64Decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { base64Decode as localBase64Decode } from './libs/base64'
* @param str 要解码的字符串
* @returns 解码后的字符串
*/
export default function base64Decode(str: string): string {
export default function base64Decode (str: string): string {
return localBase64Decode(str)
}
2 changes: 1 addition & 1 deletion src/base64Encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { base64Encode as localBase64Encode } from './libs/base64'
* @param str 要编码的字符串
* @returns 编码后的字符串
*/
export default function base64Encode(str: string | number): string {
export default function base64Encode (str: string | number): string {
return localBase64Encode(String(str))
}
2 changes: 1 addition & 1 deletion src/base64UrlDecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import base64Decode from './base64Decode'
* @returns 解码后的字符串
* @see http://www.ietf.org/rfc/rfc4648.txt
*/
export default function base64UrlDecode(str: string): string {
export default function base64UrlDecode (str: string): string {
return base64Decode(str.replace(/-/g, '+').replace(/_/g, '/'))
}
2 changes: 1 addition & 1 deletion src/base64UrlEncode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import base64Encode from './base64Encode'
* @returns 编码后的字符串
* @see http://www.ietf.org/rfc/rfc4648.txt
*/
export default function base64UrlEncode(str: string | number): string {
export default function base64UrlEncode (str: string | number): string {
return base64Encode(str)
.replace(/\+/g, '-')
.replace(/\//g, '_')
Expand Down
10 changes: 4 additions & 6 deletions src/bindEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ export type UnbindEventListener = () => void
* @param listener 事件监听器
* @param [options] 事件选项
*/
export default function bindEvent(
export default function bindEvent (
target: EventTarget,
types: BindEventTypes,
listener: EventListenerOrEventListenerObject,
options?: BindEventListenerOptions
): UnbindEventListener {
const disposes: Array<() => void> = [];
(Array.isArray(types) ? types : types.split(/\s+/)).forEach(eventType => {
const disposes: Array<() => void> = []
;(Array.isArray(types) ? types : types.split(/\s+/)).forEach(eventType => {
target.addEventListener(eventType, listener, options)
disposes.push(
() => target.removeEventListener(eventType, listener, options)
)
disposes.push(() => target.removeEventListener(eventType, listener, options))
})
return () => disposes.forEach(dispose => dispose())
}
2 changes: 1 addition & 1 deletion src/castArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* @param value 要处理的值
* @returns 转换后的数组
*/
export default function castArray<T>(value: T | ReadonlyArray<T>): T[] {
export default function castArray<T> (value: T | ReadonlyArray<T>): T[] {
return Array.isArray(value) ? value : [value]
}
4 changes: 2 additions & 2 deletions src/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* @param max 最大值
* @returns 结果值
*/
export default function clamp(value: number, min: number, max: number): number {
export default function clamp (value: number, min: number, max: number): number {
return value <= min ? min
: value >= max ? max
: value
: value
}
2 changes: 1 addition & 1 deletion src/endsWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* @param needle 要检索的字符串
* @returns 是(true)或否(false)
*/
export default function endsWith(str: string, needle: string): boolean {
export default function endsWith (str: string, needle: string): boolean {
return str.slice(-needle.length) === needle
}
2 changes: 1 addition & 1 deletion src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function fill(
* @param [end=arr.length] 结束位置
* @returns 填充改变后的数组
*/
function fill(
function fill (
arr: any[],
value?: any,
start: number = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/forOwn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export default function forOwn<
T extends { [key: string]: any },
K extends Extract<keyof T, string>
>(obj: T, callback: (value: T[K], key: K, obj: T) => any): void {
> (obj: T, callback: (value: T[K], key: K, obj: T) => any): void {
for (const key in obj) {
/* istanbul ignore else */
if (Object.prototype.hasOwnProperty.call(obj, key)) {
Expand Down
10 changes: 5 additions & 5 deletions src/formatCurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export interface FormatCurrencyOptions {
/** 是否处理小数 */
decimal?: boolean,
/** 保留小数位数 */
precision?: number
precision?: number,
}

const defaultOptions: FormatCurrencyOptions = {
thousands: true,
decimal: true,
precision: 2
precision: 2,
}

/**
Expand All @@ -22,17 +22,17 @@ const defaultOptions: FormatCurrencyOptions = {
* @param options 选项
* @returns 格式化后的值
*/
export default function formatCurrency(value: FormatCurrencyValue, options?: FormatCurrencyOptions): string {
export default function formatCurrency (value: FormatCurrencyValue, options?: FormatCurrencyOptions): string {
value = Number(value)
options = {
...defaultOptions,
...options
...options,
}
if (options.decimal) {
value = value.toFixed(options.precision)
}
if (options.thousands) {
let [integer, decimal = ''] = value.toString().split('.') // tslint:disable-line
let [integer, decimal = ''] = value.toString().split('.') // eslint-disable-line
value = ''
while (integer.length > 3) {
value = `,${integer.slice(-3)}${value}`
Expand Down
4 changes: 2 additions & 2 deletions src/formatDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import toDate from './toDate'
* @param template 格式化模板
* @returns 格式化后的值
*/
export default function formatDate(value: string | number | Date, template: string): string {
export default function formatDate (value: string | number | Date, template: string): string {
const date = toDate(value)
const patterns: { [key: string]: number } = {
y: date.getFullYear(), // 年
Expand All @@ -18,7 +18,7 @@ export default function formatDate(value: string | number | Date, template: stri
h: date.getHours(), // 时
i: date.getMinutes(), // 分
s: date.getSeconds(), // 秒
l: date.getMilliseconds() // 毫秒
l: date.getMilliseconds(), // 毫秒
}
return reduce(patterns, (result, patternValue, patternKey) => {
const patternValueStr = String(patternValue)
Expand Down
2 changes: 1 addition & 1 deletion src/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import toPath, { ToPathValue } from './toPath'
* @param [defaultValue] 默认值
* @returns 检索结果
*/
export default function get(obj: object, path: ToPathValue, defaultValue?: any): any {
export default function get (obj: object, path: ToPathValue, defaultValue?: any): any {
const normalizedPath = toPath(path)
let last: any = obj
for (let i = 0, len = normalizedPath.length; i < len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/getType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export type ValueType = (
* @see https://www.ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring
* @see https://www.ecma-international.org/ecma-262/5.1/#sec-8.6.2
*/
export default function getType(value: any): ValueType {
export default function getType (value: any): ValueType {
return Object.prototype.toString.call(value).slice(8, -1)
}
2 changes: 1 addition & 1 deletion src/has.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* @param key 要检查的键
* @returns 是(true)或否(false)
*/
export default function has(obj: object, key: string): boolean {
export default function has (obj: object, key: string): boolean {
return obj != null && Object.prototype.hasOwnProperty.call(obj, key)
}
2 changes: 1 addition & 1 deletion src/inBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let isInBrowser: boolean | undefined
* @param [callback] 在浏览器环境中执行的回调
* @returns 是(true)或否(false)
*/
export default function inBrowser(callback?: () => void): boolean {
export default function inBrowser (callback?: () => void): boolean {
if (isInBrowser === undefined) {
isInBrowser = typeof window === 'object'
&& typeof document === 'object'
Expand Down
8 changes: 4 additions & 4 deletions src/inNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ let isInNode: boolean | undefined
* @param [callback] 在 Node 环境中执行的回调
* @returns 是(true)或否(false)
*/
export default function inNode(callback?: () => void): boolean {
export default function inNode (callback?: () => void): boolean {
if (isInNode === undefined) {
isInNode = typeof process !== 'undefined' &&
process.versions != null &&
process.versions.node != null
isInNode = typeof process !== 'undefined'
&& process.versions != null
&& process.versions.node != null
}
if (isInNode && isFunction(callback)) {
callback()
Expand Down
2 changes: 1 addition & 1 deletion src/inWechatMiniProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let isInWechatMiniProgram: boolean | undefined
* @param [callback] 在微信小程序环境中执行的回调
* @returns 是(true)或否(false)
*/
export default function inWechatMiniProgram(callback?: () => void): boolean {
export default function inWechatMiniProgram (callback?: () => void): boolean {
if (isInWechatMiniProgram === undefined) {
isInWechatMiniProgram = !inBrowser() && isObject(wx) && isFunction(wx.getSystemInfo)
}
Expand Down
Loading

0 comments on commit 5066fd8

Please sign in to comment.