Skip to content

Commit

Permalink
strict(lint): new tslint runes and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Apr 29, 2017
1 parent 096dd11 commit 0581883
Show file tree
Hide file tree
Showing 29 changed files with 81 additions and 71 deletions.
2 changes: 1 addition & 1 deletion bin/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const doctor = new Doctor()

async function main() {
let ipcTestResult: string
let chromedriverVersion = doctor.chromedriverVersion()
const chromedriverVersion = doctor.chromedriverVersion()
try {
await doctor.testTcp()
ipcTestResult = 'PASS'
Expand Down
4 changes: 2 additions & 2 deletions example/api-ai-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Loading... please wait for QrCode Image Url and then scan to login.
bot
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down Expand Up @@ -142,7 +142,7 @@ class Talker extends EventEmitter {
}

/* tslint:disable:variable-name */
let Talkers: Talker[] = []
const Talkers: Talker[] = []

function talk(m) {
const fromId = m.from().id
Expand Down
2 changes: 1 addition & 1 deletion example/contact-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bot
.on('error' , e => log.info('Bot', 'error: %s', e))
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bot
})
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/friend-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bot
.on('error' , e => log.info('Bot', 'error: %s', e))
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/gist-bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Wechaty.instance({ profile: Config.DEFAULT_PROFILE })

.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
require('qrcode-terminal').generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/media-file-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const bot = Wechaty.instance({ profile: Config.DEFAULT_PROFILE })
bot
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/roger-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const bot = Wechaty.instance(/* no profile here because roger bot is too noisy *
bot
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/room-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const bot = Wechaty.instance({ profile: Config.DEFAULT_PROFILE })
bot
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/speech-to-text-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const bot = Wechaty.instance({ profile: Config.DEFAULT_PROFILE })
bot
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
2 changes: 1 addition & 1 deletion example/tuling123-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bot
.on('logout' , e => log.info('Bot', 'bot logout.'))
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"ava": "0.18.2",
"babel-eslint": "7.2.3",
"check-node-version": "2.0.1",
"codelyzer": "^3.0.1",
"cookie-parser": "1.4.3",
"coveralls": "2.13.1",
"cross-env": "4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('puppetInstance()', t => {
const mockPuppet = EXPECTED

Config.puppetInstance(mockPuppet)
let instance = Config.puppetInstance()
const instance = Config.puppetInstance()
t.deepEqual(instance, EXPECTED, 'should equal with initialized data')

Config.puppetInstance(null)
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,21 @@ export type WatchdogFoodName = 'HEARTBEAT'
| 'POISON'
| 'SCAN'

export type WatchdogFood = {
export interface WatchdogFood {
data: any,
timeout?: number, // millisecond
type?: WatchdogFoodName,
}

export type ScanInfo = {
export interface ScanInfo {
url: string,
code: number,
}

/**
* from Message
*/
export type RecommendInfo = {
export interface RecommendInfo {
UserName: string,
NickName: string, // display_name
Content: string, // request message
Expand Down
6 changes: 3 additions & 3 deletions src/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { UtilLib } from './util-lib'
import { Wechaty } from './wechaty'
import { log } from './brolog-env'

type ContactObj = {
interface ContactObj {
address: string,
city: string,
id: string,
Expand All @@ -29,7 +29,7 @@ type ContactObj = {
special: boolean,
}

export type ContactRawObj = {
export interface ContactRawObj {
Alias: string,
City: string,
NickName: string,
Expand All @@ -56,7 +56,7 @@ export enum Gender {
Female = 2,
}

export type ContactQueryFilter = {
export interface ContactQueryFilter {
name?: string | RegExp,
alias?: string | RegExp,
// DEPRECATED
Expand Down
4 changes: 2 additions & 2 deletions src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { StateMonitor } from './state-monitor'
import { Wechaty } from './wechaty'

export type IoSetting = {
export interface IoSetting {
wechaty: Wechaty,
token: string,
apihost?: string,
Expand All @@ -39,7 +39,7 @@ type IoEventName = 'botie'
| 'sys'
| 'shutdown'

type IoEvent = {
interface IoEvent {
name: IoEventName,
payload: any,
}
Expand Down
6 changes: 3 additions & 3 deletions src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import UtilLib from './util-lib'
import PuppetWeb from './puppet-web/puppet-web'
import Bridge from './puppet-web/bridge'

export type MsgRawObj = {
export interface MsgRawObj {
MsgId: string,

MMActualSender: string, // getUserContact(message.MMActualSender,message.MMPeerUserName).isContact()
Expand Down Expand Up @@ -121,7 +121,7 @@ export type MsgRawObj = {
RecommendInfo?: RecommendInfo,
}

export type MsgObj = {
export interface MsgObj {
id: string,
type: MsgType,
from: string,
Expand All @@ -141,7 +141,7 @@ export type MsgObj = {

// export type MessageTypeValue = 1 | 3 | 34 | 37 | 40 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 62 | 9999 | 10000 | 10002

export type MsgTypeMap = {
export interface MsgTypeMap {
[index: string]: string|number,
// MessageTypeName: MessageTypeValue
// , MessageTypeValue: MessageTypeName
Expand Down
6 changes: 3 additions & 3 deletions src/puppet-web/browser-cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import BrowserDriver from './browser-driver'
* with the latest 3.0 version of selenium.
* 201610 zixia
*/
export type CookieType = {
export interface CookieType {
[index: string]: string | number | boolean,
name: string,
value: string,
Expand Down Expand Up @@ -148,7 +148,7 @@ export class BrowserCookie {

await new Promise((resolve, reject) => {
// let ps = arrify(this.add(cookies))
let ps = [].concat(this.add(cookies) as any || [])
const ps = [].concat(this.add(cookies) as any || [])

Promise.all(ps)
.then(() => {
Expand Down Expand Up @@ -222,7 +222,7 @@ export class BrowserCookie {
// if (this.browser.dead()) { return Promise.reject(new Error('addCookies() - browser dead'))}

if (Array.isArray(cookie)) {
for (let c of cookie) {
for (const c of cookie) {
await this.add(c)
}
return
Expand Down
4 changes: 2 additions & 2 deletions src/puppet-web/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from './browser-cookie'
import BrowserDriver from './browser-driver'

export type BrowserSetting = {
export interface BrowserSetting {
head: HeadName,
sessionFile?: string,
}
Expand Down Expand Up @@ -289,7 +289,7 @@ export class Browser extends EventEmitter {
throw e
}

let matchRegex = new RegExp(browserRe, 'i')
const matchRegex = new RegExp(browserRe, 'i')
const pids: number[] = children.filter(child => {
// https://github.com/indexzero/ps-tree/issues/18
if (matchRegex.test('' + child.COMMAND + child.COMM)) {
Expand Down
4 changes: 2 additions & 2 deletions src/puppet-web/firer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ async function checkRoomJoin(m: Message): Promise<void> {
await room.refresh()
let inviteeListAllDone = true

for (let i in inviteeList) {
for (const i in inviteeList) {
const loaded = inviteeContactList[i] instanceof Contact

if (!loaded) {
let c = room.member(inviteeList[i])
const c = room.member(inviteeList[i])
if (!c) {
inviteeListAllDone = false
continue
Expand Down
44 changes: 22 additions & 22 deletions src/puppet-web/puppet-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const enum UploadMediaType {
AUDIO = 3,
ATTACHMENT = 4,
}
export type PuppetWebSetting = {
export interface PuppetWebSetting {
head?: HeadName,
profile?: string,
}
Expand Down Expand Up @@ -312,8 +312,8 @@ export class PuppetWeb extends Puppet {

private async getBaseRequest(): Promise<any> {
try {
let json = await this.bridge.getBaseRequest();
let obj = JSON.parse(json)
const json = await this.bridge.getBaseRequest();
const obj = JSON.parse(json)
return obj.BaseRequest
} catch (e) {
log.error('PuppetWeb', 'send() exception: %s', e.message)
Expand All @@ -325,10 +325,10 @@ export class PuppetWeb extends Puppet {
if (!mediaMessage)
throw new Error('require mediaMessage')

let filename = mediaMessage.filename()
let ext = mediaMessage.ext()
const filename = mediaMessage.filename()
const ext = mediaMessage.ext()

let contentType = UtilLib.mime(ext)
const contentType = UtilLib.mime(ext)
let mediatype: MediaType

switch (ext) {
Expand All @@ -346,8 +346,8 @@ export class PuppetWeb extends Puppet {
mediatype = 'doc'
}

let readStream = await mediaMessage.readyStream()
let buffer = <Buffer>await new Promise((resolve, reject) => {
const readStream = await mediaMessage.readyStream()
const buffer = <Buffer>await new Promise((resolve, reject) => {
readStream.pipe(bl((err, data) => {
if (err) reject(err)
else resolve(data)
Expand All @@ -360,18 +360,18 @@ export class PuppetWeb extends Puppet {
if (mediatype === 'video' && buffer.length > videoMaxSize)
throw new Error(`Sending video files is not allowed to exceed ${videoMaxSize / 1024 / 1024}MB`)

let md5 = UtilLib.md5(buffer)
const md5 = UtilLib.md5(buffer)

let baseRequest = await this.getBaseRequest()
let passTicket = await this.bridge.getPassticket()
let uploadMediaUrl = await this.bridge.getUploadMediaUrl()
let cookie = await this.browser.readCookie()
let first = cookie.find(c => c.name === 'webwx_data_ticket')
let webwxDataTicket = first && first.value
let size = buffer.length
const baseRequest = await this.getBaseRequest()
const passTicket = await this.bridge.getPassticket()
const uploadMediaUrl = await this.bridge.getUploadMediaUrl()
const cookie = await this.browser.readCookie()
const first = cookie.find(c => c.name === 'webwx_data_ticket')
const webwxDataTicket = first && first.value
const size = buffer.length

let hostname = this.browser.hostname
let uploadMediaRequest = {
const hostname = this.browser.hostname
const uploadMediaRequest = {
BaseRequest: baseRequest,
FileMd5: md5,
FromUserName: this.self().id,
Expand All @@ -384,7 +384,7 @@ export class PuppetWeb extends Puppet {
TotalLen: size,
}

let formData = {
const formData = {
id: 'WU_FILE_1',
name: filename,
type: contentType,
Expand All @@ -404,7 +404,7 @@ export class PuppetWeb extends Puppet {
},
}

let mediaId = await new Promise((resolve, reject) => {
const mediaId = await new Promise((resolve, reject) => {
request.post({
url: uploadMediaUrl + '?f=json',
headers: {
Expand All @@ -415,7 +415,7 @@ export class PuppetWeb extends Puppet {
}, function (err, res, body) {
if (err) reject(err)
else {
let obj = JSON.parse(body)
const obj = JSON.parse(body)
resolve(obj.MediaId)
}
})
Expand All @@ -441,7 +441,7 @@ export class PuppetWeb extends Puppet {
}

const mediaId = await this.uploadMedia(message, destinationId)
let msgType = UtilLib.msgType(message.ext())
const msgType = UtilLib.msgType(message.ext())

log.silly('PuppetWeb', 'send() destination: %s, mediaId: %s)',
destinationId,
Expand Down
Loading

0 comments on commit 0581883

Please sign in to comment.