mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-21 21:35:16 +02:00
Fix all lib/ files with ESLint rules with 0 errors.
This commit is contained in:
@@ -4,13 +4,14 @@ module.exports.list = function(val) {
|
||||
|
||||
module.exports.size = function(val) {
|
||||
var match = /^(\d+)x(\d+)$/.exec(val)
|
||||
return match ? [+match[1], +match[2]] : undefined
|
||||
if (match) {
|
||||
return [Number(match[1]), Number(match[2])]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.range = function(from, to) {
|
||||
var items = []
|
||||
, i
|
||||
for (i = from; i <= to; ++i) {
|
||||
for (var i = from; i <= to; ++i) {
|
||||
items.push(i)
|
||||
}
|
||||
return items
|
||||
|
||||
@@ -70,7 +70,7 @@ devutil.listPidsByComm = function(adb, serial, comm, bin) {
|
||||
.then(function(out) {
|
||||
return new Promise(function(resolve) {
|
||||
var header = false
|
||||
, pids = []
|
||||
var pids = []
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
if (header) {
|
||||
@@ -79,7 +79,7 @@ devutil.listPidsByComm = function(adb, serial, comm, bin) {
|
||||
else {
|
||||
var cols = chunk.toString().split(/\s+/)
|
||||
if (cols.pop() === bin && users[cols[0]]) {
|
||||
pids.push(+cols[1])
|
||||
pids.push(Number(cols[1]))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -126,14 +126,14 @@ devutil.killProcsByComm = function(adb, serial, comm, bin, mode) {
|
||||
|
||||
devutil.makeIdentity = function(serial, properties) {
|
||||
var model = properties['ro.product.model']
|
||||
, brand = properties['ro.product.brand']
|
||||
, manufacturer = properties['ro.product.manufacturer']
|
||||
, operator = properties['gsm.sim.operator.alpha'] ||
|
||||
var brand = properties['ro.product.brand']
|
||||
var manufacturer = properties['ro.product.manufacturer']
|
||||
var operator = properties['gsm.sim.operator.alpha'] ||
|
||||
properties['gsm.operator.alpha']
|
||||
, version = properties['ro.build.version.release']
|
||||
, sdk = properties['ro.build.version.sdk']
|
||||
, abi = properties['ro.product.cpu.abi']
|
||||
, product = properties['ro.product.name']
|
||||
var version = properties['ro.build.version.release']
|
||||
var sdk = properties['ro.build.version.sdk']
|
||||
var abi = properties['ro.product.cpu.abi']
|
||||
var product = properties['ro.product.name']
|
||||
|
||||
// Remove brand prefix for consistency
|
||||
if (model.substr(0, brand.length) === brand) {
|
||||
|
||||
@@ -29,7 +29,7 @@ module.exports.decode = function(payload, secret) {
|
||||
var decoded = jws.decode(payload, {
|
||||
json: true
|
||||
})
|
||||
, exp = decoded.header.exp
|
||||
var exp = decoded.header.exp
|
||||
|
||||
if (exp && exp <= Date.now()) {
|
||||
return null
|
||||
|
||||
@@ -7,15 +7,12 @@ var keyutil = module.exports = Object.create(null)
|
||||
|
||||
keyutil.parseKeyCharacterMap = function(stream) {
|
||||
var resolver = Promise.defer()
|
||||
, state = 'type_t'
|
||||
, keymap = {
|
||||
var state = 'type_t'
|
||||
var keymap = {
|
||||
type: null
|
||||
, keys: []
|
||||
}
|
||||
, lastKey
|
||||
, lastRule
|
||||
, lastModifier
|
||||
, lastBehavior
|
||||
var lastKey, lastRule, lastModifier, lastBehavior
|
||||
|
||||
function fail(char, state) {
|
||||
throw new Error(util.format(
|
||||
@@ -431,8 +428,8 @@ keyutil.parseKeyCharacterMap = function(stream) {
|
||||
|
||||
function readableListener() {
|
||||
var chunk = stream.read()
|
||||
, i = 0
|
||||
, l = chunk.length
|
||||
var i = 0
|
||||
var l = chunk.length
|
||||
|
||||
try {
|
||||
while (i < l) {
|
||||
@@ -461,7 +458,7 @@ keyutil.parseKeyCharacterMap = function(stream) {
|
||||
|
||||
keyutil.namedKey = function(name) {
|
||||
var key = adb.Keycode['KEYCODE_' + name.toUpperCase()]
|
||||
if (key === void 0) {
|
||||
if (typeof key === 'undefined') {
|
||||
throw new Error(util.format('Unknown key "%s"', name))
|
||||
}
|
||||
return key
|
||||
|
||||
@@ -19,7 +19,7 @@ module.exports.InvalidCredentialsError = InvalidCredentialsError
|
||||
module.exports.login = function(options, username, password) {
|
||||
function tryConnect() {
|
||||
var resolver = Promise.defer()
|
||||
, client = ldap.createClient({
|
||||
var client = ldap.createClient({
|
||||
url: options.url
|
||||
, timeout: options.timeout
|
||||
, maxConnections: 1
|
||||
@@ -44,7 +44,7 @@ module.exports.login = function(options, username, password) {
|
||||
|
||||
function tryFind(client) {
|
||||
var resolver = Promise.defer()
|
||||
, query = {
|
||||
var query = {
|
||||
scope: options.search.scope
|
||||
, filter: new ldap.AndFilter({
|
||||
filters: [
|
||||
|
||||
@@ -28,6 +28,32 @@ Logger.LevelLabel = {
|
||||
|
||||
Logger.globalIdentifier = '*'
|
||||
|
||||
function Log(tag) {
|
||||
this.tag = tag
|
||||
this.names = {
|
||||
1: 'DBG'
|
||||
, 2: 'VRB'
|
||||
, 3: 'INF'
|
||||
, 4: 'IMP'
|
||||
, 5: 'WRN'
|
||||
, 6: 'ERR'
|
||||
, 7: 'FTL'
|
||||
}
|
||||
this.styles = {
|
||||
1: 'grey'
|
||||
, 2: 'cyan'
|
||||
, 3: 'green'
|
||||
, 4: 'magenta'
|
||||
, 5: 'yellow'
|
||||
, 6: 'red'
|
||||
, 7: 'red'
|
||||
}
|
||||
this.localIdentifier = null
|
||||
events.EventEmitter.call(this)
|
||||
}
|
||||
|
||||
util.inherits(Log, events.EventEmitter)
|
||||
|
||||
Logger.createLogger = function(tag) {
|
||||
return new Log(tag)
|
||||
}
|
||||
@@ -37,32 +63,6 @@ Logger.setGlobalIdentifier = function(identifier) {
|
||||
return Logger
|
||||
}
|
||||
|
||||
function Log(tag) {
|
||||
this.tag = tag
|
||||
this.names = {
|
||||
1: 'DBG'
|
||||
, 2: 'VRB'
|
||||
, 3: 'INF'
|
||||
, 4: 'IMP'
|
||||
, 5: 'WRN'
|
||||
, 6: 'ERR'
|
||||
, 7: 'FTL'
|
||||
}
|
||||
this.styles = {
|
||||
1: 'grey'
|
||||
, 2: 'cyan'
|
||||
, 3: 'green'
|
||||
, 4: 'magenta'
|
||||
, 5: 'yellow'
|
||||
, 6: 'red'
|
||||
, 7: 'red'
|
||||
}
|
||||
this.localIdentifier = null
|
||||
events.EventEmitter.call(this)
|
||||
}
|
||||
|
||||
util.inherits(Log, events.EventEmitter)
|
||||
|
||||
Log.Entry = function(timestamp, priority, tag, pid, identifier, message) {
|
||||
this.timestamp = timestamp
|
||||
this.priority = priority
|
||||
@@ -129,6 +129,7 @@ Log.prototype._name = function(priority) {
|
||||
return chalk[this.styles[priority]](this.names[priority])
|
||||
}
|
||||
|
||||
/* eslint no-console: 0 */
|
||||
Log.prototype._write = function(entry) {
|
||||
console.error(this._format(entry))
|
||||
this.emit('entry', entry)
|
||||
|
||||
@@ -2,12 +2,13 @@ var Promise = require('bluebird')
|
||||
|
||||
module.exports.periodicNotify = function(promise, interval) {
|
||||
var resolver = Promise.defer()
|
||||
, timer = setInterval(notify, interval)
|
||||
|
||||
function notify() {
|
||||
resolver.progress()
|
||||
}
|
||||
|
||||
var timer = setInterval(notify, interval)
|
||||
|
||||
function resolve(value) {
|
||||
resolver.resolve(value)
|
||||
}
|
||||
|
||||
@@ -31,11 +31,7 @@ module.exports.limit = function(limit, handler) {
|
||||
var queue = []
|
||||
var running = 0
|
||||
|
||||
function done() {
|
||||
running -= 1
|
||||
maybeNext()
|
||||
}
|
||||
|
||||
/* eslint no-use-before-define: 0 */
|
||||
function maybeNext() {
|
||||
while (running < limit && queue.length) {
|
||||
running += 1
|
||||
@@ -43,6 +39,11 @@ module.exports.limit = function(limit, handler) {
|
||||
}
|
||||
}
|
||||
|
||||
function done() {
|
||||
running -= 1
|
||||
maybeNext()
|
||||
}
|
||||
|
||||
return function() {
|
||||
queue.push(arguments)
|
||||
maybeNext()
|
||||
|
||||
@@ -37,11 +37,11 @@ RiskyStream.prototype.expectEnd = function() {
|
||||
|
||||
RiskyStream.prototype.waitForEnd = function() {
|
||||
var stream = this.stream
|
||||
, endListener
|
||||
var endListener
|
||||
|
||||
this.expectEnd()
|
||||
|
||||
return new Promise(function(resolve/*, reject*/) {
|
||||
return new Promise(function(resolve) {
|
||||
if (stream.ended) {
|
||||
return resolve(true)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ function shuffleWeighted(records) {
|
||||
|
||||
function pick(records, sum) {
|
||||
var rand = Math.random() * sum
|
||||
, counter = 0
|
||||
var counter = 0
|
||||
|
||||
for (var i = 0, l = records.length; i < l; ++i) {
|
||||
counter += records[i].weight
|
||||
@@ -117,7 +117,7 @@ srv.attempt = function(records, fn) {
|
||||
}
|
||||
|
||||
return fn(records[i]).catch(srv.NEXT, function() {
|
||||
return next(++i)
|
||||
return next(i + 1)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ Storage.prototype.check = function() {
|
||||
|
||||
Object.keys(this.files).forEach(function(id) {
|
||||
var file = this.files[id]
|
||||
, inactivePeriod = now - file.lastActivity
|
||||
var inactivePeriod = now - file.lastActivity
|
||||
|
||||
if (inactivePeriod >= file.timeout) {
|
||||
this.remove(id)
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports.NoSuchLineError = NoSuchLineError
|
||||
|
||||
module.exports.readAll = function(stream) {
|
||||
var resolver = Promise.defer()
|
||||
, collected = new Buffer(0)
|
||||
var collected = new Buffer(0)
|
||||
|
||||
function errorListener(err) {
|
||||
resolver.reject(err)
|
||||
@@ -45,7 +45,7 @@ module.exports.readAll = function(stream) {
|
||||
|
||||
module.exports.findLine = function(stream, re) {
|
||||
var resolver = Promise.defer()
|
||||
, piped = stream.pipe(split())
|
||||
var piped = stream.pipe(split())
|
||||
|
||||
function errorListener(err) {
|
||||
resolver.reject(err)
|
||||
|
||||
@@ -3,8 +3,11 @@ var url = require('url')
|
||||
module.exports.addParams = function(originalUrl, params) {
|
||||
var parsed = url.parse(originalUrl, true)
|
||||
parsed.search = null
|
||||
// TODO: change to ES6 loop
|
||||
for (var key in params) {
|
||||
parsed.query[key] = params[key]
|
||||
if (params.dict.hasOwnProperty(key)) {
|
||||
parsed.query[key] = params[key]
|
||||
}
|
||||
}
|
||||
return url.format(parsed)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function normalizePassword(password) {
|
||||
|
||||
function encrypt(challenge, password) {
|
||||
var key = normalizePassword(password)
|
||||
, iv = new Buffer(0).fill(0)
|
||||
var iv = new Buffer(0).fill(0)
|
||||
|
||||
// Note: do not call .final(), .update() is the one that gives us the
|
||||
// desired result.
|
||||
|
||||
@@ -14,7 +14,7 @@ module.exports.socket = function() {
|
||||
;['ZMQ_TCP_KEEPALIVE', 'ZMQ_TCP_KEEPALIVE_IDLE'].forEach(function(opt) {
|
||||
if (process.env[opt]) {
|
||||
try {
|
||||
sock.setsockopt(zmq[opt], +process.env[opt])
|
||||
sock.setsockopt(zmq[opt], Number(process.env[opt]))
|
||||
}
|
||||
catch (err) {
|
||||
log.warn('ZeroMQ library too old, no support for %s', opt)
|
||||
|
||||
Reference in New Issue
Block a user