Skip to content

Commit

Permalink
make tslint:recommend happy (wechaty#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Jul 21, 2018
1 parent 2d74c6f commit ed48018
Show file tree
Hide file tree
Showing 33 changed files with 345 additions and 339 deletions.
2 changes: 1 addition & 1 deletion bin/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Wechaty } from '../src/wechaty'
const wechaty = Wechaty.instance()
const doctor = new Doctor()

async function main() {
async function main () {
let ipcTestResult: string
try {
await doctor.testTcp()
Expand Down
2 changes: 1 addition & 1 deletion bin/io-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ client.start()
client.initWeb()
.catch(onError.bind(client))

async function onError(
async function onError (
this : IoClient,
e : Error,
) {
Expand Down
2 changes: 1 addition & 1 deletion examples/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*
*/
import {
config,
Contact,
Message,
Wechaty,
config,
} from '../src/' // from 'wechaty'

import { FileBox } from 'file-box'
Expand Down
10 changes: 6 additions & 4 deletions scripts/development-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
* https://github.com/zixia
* License: Apache-2.0
*/
import readPkgUp from 'read-pkg-up'
import { minor } from 'semver'

const version: string = require('../package.json').version
const pkg = readPkgUp.sync({ cwd: __dirname }).pkg
export const VERSION = pkg.version

if (minor(version) % 2 === 0) { // production release
console.log(`${version} is production release`)
if (minor(VERSION) % 2 === 0) { // production release
console.log(`${VERSION} is production release`)
process.exit(1) // exit 1 for not development
}

// development release
console.log(`${version} is development release`)
console.log(`${VERSION} is development release`)
process.exit(0)
3 changes: 2 additions & 1 deletion scripts/package-publish-config-tag-next.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env ts-node
import * as fs from 'fs'
import * as path from 'path'
import readPkgUp from 'read-pkg-up'

const PACKAGE_JSON = path.join(__dirname, '../package.json')

const pkg = require(PACKAGE_JSON)
const pkg = readPkgUp.sync({ cwd: __dirname }).pkg

// pkg.publishConfig.tag = 'next'
pkg.publishConfig = {
Expand Down
6 changes: 3 additions & 3 deletions scripts/retry-unit-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { spawn } from 'child_process'

const MAX_RETRY_NUM = 3

async function main(): Promise<number> {
async function main (): Promise<number> {
console.log('Safe Test: starting...')

let round = 0
Expand All @@ -26,16 +26,16 @@ async function main(): Promise<number> {
return 1 // fail finally :(
}

async function unitTest() {
async function unitTest () {
const child = spawn(
'npm',
[
'run',
'test:unit',
],
{
stdio: 'inherit',
shell: true, // https://stackoverflow.com/a/39682805/1123955
stdio: 'inherit',
},
)
return new Promise<boolean>((resolve, reject) => {
Expand Down
12 changes: 6 additions & 6 deletions scripts/sort-contributiveness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const contributeMap: {
[contributor: string]: string[],
} = {}

function parseLine(line: string): string[] | null {
function parseLine (line: string): string[] | null {
// [\#264](https://github.com/Chatie/wechaty/pull/264) ([lijiarui](https://github.com/lijiarui))
// const regex = /(\[\\#\d+\]\([^\)]+\))\s+(\(\[[^]]+\]\([^)]+\)))/i
const regex = /(\[\\#\d+\])(\([^\)]+\))\s+\((\[[^\]]+\]\([^\)]+\))/
Expand All @@ -21,7 +21,7 @@ function parseLine(line: string): string[] | null {
return matches
}

function processLine(line: string): void {
function processLine (line: string): void {
const matches = parseLine(line)
if (matches) {
// console.log('match:', line)
Expand All @@ -40,17 +40,17 @@ function processLine(line: string): void {
}
}

function outputContributorMd() {
function outputContributorMd () {
const MIN_MAINTAINER_COMMIT_NUM = 2
function isMaintainer(committer: string): boolean {
function isMaintainer (committer: string): boolean {
return contributeMap[committer].length >= MIN_MAINTAINER_COMMIT_NUM
}

const activeContributorList = Object.keys(contributeMap)
.filter(isMaintainer)
.sort(desc)

function desc(committerA: string, committerB: string): number {
function desc (committerA: string, committerB: string): number {
return contributeMap[committerB].length - contributeMap[committerA].length
}

Expand Down Expand Up @@ -90,7 +90,7 @@ function outputContributorMd() {

}

async function main() {
async function main () {
// https://stackoverflow.com/a/20087094/1123955
const rl = readline.createInterface({
input: process.stdin,
Expand Down
14 changes: 7 additions & 7 deletions scripts/update-license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class LicenseTransformer extends Transform {
private updating = false
private updated = false

constructor(options?: TransformOptions) {
constructor (options?: TransformOptions) {
super(options)
}

public _transform(chunk: any, _: string /* encoding: string */, done: Function) {
public _transform (chunk: any, _: string /* encoding: string */, done: () => void) {
if (this.updated) {
this.push(chunk)
} else {
Expand All @@ -56,7 +56,7 @@ class LicenseTransformer extends Transform {
done()
}

private updateChunk(chunk: any): string {
private updateChunk (chunk: any): string {
const buffer = this.lineBuf + chunk.toString()
this.lineBuf = ''

Expand Down Expand Up @@ -106,7 +106,7 @@ class LicenseTransformer extends Transform {
return updatedLineList.join('\n')
}

public _flush(done: Function) {
public _flush (done: () => void) {
if (this.lineBuf) {
this.push(this.lineBuf)
this.lineBuf = ''
Expand All @@ -115,7 +115,7 @@ class LicenseTransformer extends Transform {
}
}

async function updateLicense(file: string): Promise<void> {
async function updateLicense (file: string): Promise<void> {
const tmpFile = file + `.${process.pid}.tmp`
const readStream = createReadStream(file)
const writeStream = createWriteStream(tmpFile)
Expand All @@ -134,11 +134,11 @@ async function updateLicense(file: string): Promise<void> {
await promisify(unlinkCallback)(tmpFile)
}

async function glob(pattern: string): Promise<string[]> {
async function glob (pattern: string): Promise<string[]> {
return promisify<string, string[]>(globCallback as any)(pattern)
}

async function main(): Promise<number> {
async function main (): Promise<number> {
const pattern = '{bin/**/*.ts,examples/**/*.{js,ts},scripts/**/*.{ts,js},src/**/*.{ts,js},tests/**/*.ts}'
// const pattern = 't.ts'
const srcFileList = await glob(pattern)
Expand Down
6 changes: 4 additions & 2 deletions src/accessory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
*/
// tslint:disable:no-shadowed-variable
// tslint:disable:max-classes-per-file

import test from 'blue-tape'
// import sinon from 'sinon'

Expand All @@ -31,8 +33,8 @@ import {

import { Puppet } from 'wechaty-puppet'

const EXPECTED_PUPPET1 = {p: 1} as any as Puppet
const EXPECTED_PUPPET2 = {p: 2} as any as Puppet
const EXPECTED_PUPPET1 = { p: 1 } as any as Puppet
const EXPECTED_PUPPET2 = { p: 2 } as any as Puppet

test('Accessory smoke testing', async t => {

Expand Down
18 changes: 9 additions & 9 deletions src/accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { instanceToClass } from 'clone-class'

import { log } from './config'

import { Wechaty } from './wechaty'
import { Puppet } from 'wechaty-puppet'
import { Wechaty } from './wechaty'

// use Symbol to prevent conflicting with the child class properties
// This symbol must be exported (for now).
Expand Down Expand Up @@ -33,7 +33,7 @@ export abstract class Accessory extends EventEmitter {
/**
* @private
*/
public static set puppet(puppet: Puppet) {
public static set puppet (puppet: Puppet) {
log.silly('Accessory', '<%s> static set puppet = "%s"',
this.name,
puppet,
Expand All @@ -48,7 +48,7 @@ export abstract class Accessory extends EventEmitter {
/**
* @private
*/
public static get puppet(): Puppet {
public static get puppet (): Puppet {
// log.silly('Accessory', '<%s> static get puppet()',
// this.name,
// )
Expand All @@ -68,7 +68,7 @@ export abstract class Accessory extends EventEmitter {
/**
* @private
*/
public static set wechaty(wechaty: Wechaty) {
public static set wechaty (wechaty: Wechaty) {
log.silly('Accessory', '<%s> static set wechaty = "%s"',
this.name,
wechaty,
Expand All @@ -82,7 +82,7 @@ export abstract class Accessory extends EventEmitter {
/**
* @private
*/
public static get wechaty(): Wechaty {
public static get wechaty (): Wechaty {
// log.silly('Accessory', '<%s> static get wechaty()',
// this.name,
// )
Expand All @@ -108,7 +108,7 @@ export abstract class Accessory extends EventEmitter {
/**
* @private
*/
public set puppet(puppet: Puppet) {
public set puppet (puppet: Puppet) {
log.silly('Accessory', '<%s> set puppet = "%s"',
this[SYMBOL_NAME] || this,
puppet,
Expand All @@ -131,7 +131,7 @@ export abstract class Accessory extends EventEmitter {
* So: that's the reason that there's no `private _wechaty: Wechaty` for the instance.
*
*/
public get puppet(): Puppet {
public get puppet (): Puppet {
// log.silly('Accessory', '#%d<%s> get puppet()',
// this[SYMBOL_COUNTER],
// this[SYMBOL_NAME] || this,
Expand Down Expand Up @@ -160,7 +160,7 @@ export abstract class Accessory extends EventEmitter {
*
* So it only need one `wechaty` for all the instances
*/
public get wechaty(): Wechaty {
public get wechaty (): Wechaty {
// log.silly('Accessory', '#%d<%s> get wechaty()',
// this[SYMBOL_COUNTER],
// this[SYMBOL_NAME] || this,
Expand All @@ -174,7 +174,7 @@ export abstract class Accessory extends EventEmitter {
return instanceToClass(this, Accessory).wechaty
}

constructor(
constructor (
name?: string,
) {
super()
Expand Down
16 changes: 8 additions & 8 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import fs from 'fs'
import os from 'os'
import path from 'path'

import readPkgUp from 'read-pkg-up'
import Raven from 'raven'
import qrImage from 'qr-image'
import Raven from 'raven'
import readPkgUp from 'read-pkg-up'

import { log } from 'brolog'
import {
Expand Down Expand Up @@ -134,7 +134,7 @@ export class Config {

// private _puppetInstance: Puppet | null = null

constructor() {
constructor () {
log.verbose('Config', 'constructor()')
this.validApiHost(this.apihost)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ export class Config {

// }

public gitRevision(): string | null {
public gitRevision (): string | null {
const dotGitPath = path.join(__dirname, '..', '.git') // only for ts-node, not for dist
// const gitLogArgs = ['log', '--oneline', '-1']
// TODO: use git rev-parse HEAD ?
Expand Down Expand Up @@ -199,7 +199,7 @@ export class Config {
}
}

public validApiHost(apihost: string): boolean {
public validApiHost (apihost: string): boolean {
if (/^[a-zA-Z0-9\.\-\_]+:?[0-9]*$/.test(apihost)) {
return true
}
Expand All @@ -209,7 +209,7 @@ export class Config {

export const CHATIE_OFFICIAL_ACCOUNT_ID = 'gh_051c89260e5d'

export function qrCodeForChatie(): FileBox {
export function qrCodeForChatie (): FileBox {
const CHATIE_OFFICIAL_ACCOUNT_QRCODE = 'http://weixin.qq.com/r/qymXj7DEO_1ErfTs93y5'
const name = 'qrcode-for-chatie.png'
const type = 'png'
Expand All @@ -222,15 +222,15 @@ export function qrCodeForChatie(): FileBox {
// String.fromCharCode(8197)
export const FOUR_PER_EM_SPACE = String.fromCharCode(0x2005)

export function qrcodeValueToImageUrl(qrcodeValue: string): string {
export function qrcodeValueToImageUrl (qrcodeValue: string): string {
return [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcodeValue),
'&size=220x220&margin=20',
].join('')
}

export function isProduction(): boolean {
export function isProduction (): boolean {
return process.env.NODE_ENV === 'production'
|| process.env.NODE_ENV === 'prod'
}
Expand Down
2 changes: 1 addition & 1 deletion src/deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class MediaMessage {
constructor(..._: any[]) {
constructor (..._: any[]) {
let msg = '`MediaMessage` is deprecated. Please use `FileBox` instead. '
msg += 'See example at: https://github.com/Chatie/wechaty/blob/55a48919d472ff5c4df8987abe4de87a5a546104/examples/ding-dong-bot.ts#L138'
throw new Error(msg)
Expand Down
Loading

0 comments on commit ed48018

Please sign in to comment.