Update standard to 5.2 and fix coding style.

This commit is contained in:
Julien Fontanet
2015-09-04 11:00:36 +02:00
parent edabc17ac9
commit 4ddbefb147
11 changed files with 59 additions and 57 deletions

View File

@@ -20,12 +20,12 @@ var PRODUCTION = process.argv.indexOf('--production') !== -1
// ===================================================================
function src (patterns) {
return PRODUCTION ?
gulp.src(patterns, {
return PRODUCTION
? gulp.src(patterns, {
base: SRC_DIR,
cwd: SRC_DIR
}) :
watch(patterns, {
})
: watch(patterns, {
base: SRC_DIR,
cwd: SRC_DIR,
ignoreInitial: false,

View File

@@ -113,7 +113,7 @@
"must": "^0.12.0",
"node-inspector": "^0.12.2",
"sinon": "^1.14.1",
"standard": "^5.1.0"
"standard": "^5.2.1"
},
"scripts": {
"build": "gulp build --production",

View File

@@ -53,9 +53,9 @@ signOut.permission = ''
export async function getUser () {
const userId = this.session.get('user_id')
return userId === undefined ?
null :
this.getUserPublicProperties(await this.getUser(userId))
return userId === undefined
? null
: this.getUserPublicProperties(await this.getUser(userId))
}
getUser.description = 'return the currently connected user'

View File

@@ -39,7 +39,6 @@ export default class Collection extends EventEmitter {
const array = isArray(models)
if (!array) {
models = [models]
}
const {Model} = this
@@ -60,16 +59,16 @@ export default class Collection extends EventEmitter {
models = await this._add(models, opts)
this.emit('add', models)
return array ?
models :
new this.Model(models[0])
return array
? models
: new this.Model(models[0])
}
async first (properties) {
if (!isObject(properties)) {
properties = (properties !== undefined) ?
{ id: properties } :
{}
properties = (properties !== undefined)
? { id: properties }
: {}
}
const model = await this._first(properties)
@@ -78,9 +77,9 @@ export default class Collection extends EventEmitter {
async get (properties) {
if (!isObject(properties)) {
properties = (properties !== undefined) ?
{ id: properties } :
{}
properties = (properties !== undefined)
? { id: properties }
: {}
}
return await this._get(properties)
@@ -131,9 +130,9 @@ export default class Collection extends EventEmitter {
models = await this._update(models)
this.emit('update', models)
return array ?
models :
new this.Model(models[0])
return array
? models
: new this.Model(models[0])
}
// Methods to override in implementations.
@@ -168,8 +167,8 @@ export default class Collection extends EventEmitter {
async _first (properties) {
const models = await this.get(properties)
return models.length ?
models[0] :
null
return models.length
? models[0]
: null
}
}

View File

@@ -123,10 +123,9 @@ export default class Redis extends Collection {
if (id !== undefined) {
delete properties.id
return this._extract([id]).then(models => {
return (models.length && !isEmpty(properties)) ?
filter(models) :
models
return (models.length && !isEmpty(properties))
? filter(models)
: models
})
}

View File

@@ -402,7 +402,6 @@ const setUpApi = (webSocketServer, xo) => {
socket.send(data, onSend)
}
})
})
return api

View File

@@ -30,7 +30,9 @@ export class Remotes extends Collection {
async get (properties) {
const remotes = await super.get(properties)
forEach(remotes, remote => {remote.enabled = (remote.enabled === 'true')})
forEach(remotes, remote => {
remote.enabled = (remote.enabled === 'true')
})
return remotes
}
}

View File

@@ -30,7 +30,9 @@ export class Schedules extends Collection {
async get (properties) {
const schedules = await super.get(properties)
forEach(schedules, schedule => {schedule.enabled = (schedule.enabled === 'true')})
forEach(schedules, schedule => {
schedule.enabled = (schedule.enabled === 'true')
})
return schedules
}
}

View File

@@ -155,9 +155,9 @@ export function vm (obj) {
CPUs: {
max: +obj.VCPUs_max,
number: (
isRunning && metrics ?
+metrics.VCPUs_number :
+obj.VCPUs_at_startup
isRunning && metrics
? +metrics.VCPUs_number
: +obj.VCPUs_at_startup
)
},
current_operations: obj.current_operations,
@@ -228,9 +228,9 @@ export function vm (obj) {
VIFs: link(obj, 'VIFs'),
$container: (
isRunning ?
link(obj, 'resident_on') :
link(obj, 'pool') // TODO: handle local VMs (`VM.get_possible_hosts()`).
isRunning
? link(obj, 'resident_on')
: link(obj, 'pool') // TODO: handle local VMs (`VM.get_possible_hosts()`).
),
$VBDs: link(obj, 'VBDs'),
@@ -294,9 +294,9 @@ export function sr (obj) {
VDIs: link(obj, 'VDIs'),
$container: (
obj.shared ?
link(obj, 'pool') :
obj.$PBDs[0] && link(obj.$PBDs[0], 'host')
obj.shared
? link(obj, 'pool')
: obj.$PBDs[0] && link(obj.$PBDs[0], 'host')
),
$PBDs: link(obj, 'PBDs')
}

View File

@@ -416,7 +416,6 @@ export default class Xapi extends XapiBase {
async _cloneVm (vm, nameLabel = vm.name_label) {
return await this.call('VM.clone', vm.$ref, nameLabel)
}
async _snapshotVm (vm, nameLabel = vm.name_label) {
@@ -436,9 +435,9 @@ export default class Xapi extends XapiBase {
async copyVm (vmId, srId = null, nameLabel = undefined) {
const vm = this.getObject(vmId)
const srRef = (srId == null) ?
'' :
this.getObject(srId).$ref
const srRef = (srId == null)
? ''
: this.getObject(srId).$ref
return await this._getOrWaitObject(
await this.call('VM.copy', vm.$ref, nameLabel || vm.nameLabel, srRef)
@@ -681,9 +680,9 @@ export default class Xapi extends XapiBase {
if (type === 'CD') {
// Choose position 3 if allowed.
position = includes(allowed, '3') ?
'3' :
allowed[0]
position = includes(allowed, '3')
? '3'
: allowed[0]
} else {
position = allowed[0]

View File

@@ -634,7 +634,9 @@ export default class Xo extends EventEmitter {
async syncAllRemotes () {
const remotes = await this.getAllRemotes()
forEach(remotes, remote => {this.updateRemote(remote.id, {})})
forEach(remotes, remote => {
this.updateRemote(remote.id, {})
})
}
async disableAllRemotes () {
@@ -968,9 +970,9 @@ export default class Xo extends EventEmitter {
return generateToken().then(token => {
const url = `/api/${token}`
return url in watchers ?
generateUniqueUrl() :
url
return url in watchers
? generateUniqueUrl()
: url
})
})()
@@ -1048,13 +1050,13 @@ export default class Xo extends EventEmitter {
if (isString(opts)) {
opts = parseUrl(opts)
} else {
opts.method = opts.method != null ?
opts.method.toUpperCase() :
'GET'
opts.method = opts.method != null
? opts.method.toUpperCase()
: 'GET'
opts.proxyMethod = opts.proxyMethod != null ?
opts.proxyMethod.toUpperCase() :
opts.method
opts.proxyMethod = opts.proxyMethod != null
? opts.proxyMethod.toUpperCase()
: opts.method
}
opts.createdAt = Date.now()