From 0770aef4bfb4009f8bfa23f891db28321ea82004 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 4 May 2016 11:59:56 +0200 Subject: [PATCH] chore(package): update standard to version 7.0.0 --- gulpfile.js | 6 ++++-- package.json | 2 +- src/api-errors.js | 2 +- src/api/pool.js | 2 +- src/collection.js | 4 ---- src/index.js | 5 +++-- src/job-executor.spec.js | 6 ++++-- src/utils.js | 8 ++++---- src/vhd-merge.js | 6 +++--- src/xapi-object-to-xo.js | 2 +- src/xapi-stats.js | 6 +----- src/xapi.js | 23 ++++++----------------- src/xo-mixins/authentication.js | 2 +- src/xo-mixins/backups.js | 2 +- src/xo-mixins/subjects.js | 4 ++-- src/xo-mixins/xen-servers.js | 2 +- 16 files changed, 34 insertions(+), 48 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 08654290f..0015aaa60 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,10 +10,12 @@ var plumber = require('gulp-plumber') var sourceMaps = require('gulp-sourcemaps') var watch = require('gulp-watch') +var join = require('path').join + // =================================================================== -var SRC_DIR = __dirname + '/src' -var DIST_DIR = __dirname + '/dist' +var SRC_DIR = join(__dirname, 'src') +var DIST_DIR = join(__dirname, 'dist') var PRODUCTION = process.argv.indexOf('--production') !== -1 diff --git a/package.json b/package.json index 6c0446afc..3383e78fd 100644 --- a/package.json +++ b/package.json @@ -149,7 +149,7 @@ "mocha": "^2.2.1", "must": "^0.13.1", "sinon": "^1.14.1", - "standard": "^5.2.1" + "standard": "^7.0.0" }, "scripts": { "build": "npm run build-indexes && gulp build --production", diff --git a/src/api-errors.js b/src/api-errors.js index d626d00a7..b3d892cc6 100644 --- a/src/api-errors.js +++ b/src/api-errors.js @@ -3,7 +3,7 @@ import {JsonRpcError} from 'json-rpc-peer' // =================================================================== // Export standard JSON-RPC errors. -export { +export { // eslint-disable-line no-duplicate-imports InvalidJson, InvalidParameters, InvalidRequest, diff --git a/src/api/pool.js b/src/api/pool.js index 2bcacb2c4..b373e9cc8 100644 --- a/src/api/pool.js +++ b/src/api/pool.js @@ -74,7 +74,7 @@ installPatch.resolve = { // ------------------------------------------------------------------- async function handlePatchUpload (req, res, {pool}) { - const {headers: {['content-length']: contentLength}} = req + const contentLength = req.headers['content-length'] if (!contentLength) { res.writeHead(411) res.end('Content length is mandatory') diff --git a/src/collection.js b/src/collection.js index 22661823c..1333f6a7b 100644 --- a/src/collection.js +++ b/src/collection.js @@ -33,10 +33,6 @@ export default class Collection extends EventEmitter { }) } - constructor () { - super() - } - async add (models, opts) { const array = isArray(models) if (!array) { diff --git a/src/index.js b/src/index.js index 1f4b53919..4ae32067e 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ import serveStatic from 'serve-static' import startsWith from 'lodash.startswith' import WebSocket from 'ws' import { createServer as createProxyServer } from 'http-proxy' +import { join as joinPath } from 'path' import {compile as compileJade} from 'jade' import { @@ -129,7 +130,7 @@ async function setUpPassport (express, xo) { // Registers the sign in form. const signInPage = compileJade( - await readFile(__dirname + '/../signin.jade') + await readFile(joinPath(__dirname, '..', 'signin.jade')) ) express.get('/signin', (req, res, next) => { res.send(signInPage({ @@ -515,7 +516,7 @@ const setUpConsoleProxy = (webServer, xo) => { const { token } = parseCookies(req.headers.cookie) const user = await xo.authenticateUser({ token }) - if (!await xo.hasPermissions(user.id, [ [ id, 'operate' ] ])) { // eslint-disable-line space-before-keywords + if (!await xo.hasPermissions(user.id, [ [ id, 'operate' ] ])) { throw new InvalidCredential() } diff --git a/src/job-executor.spec.js b/src/job-executor.spec.js index b88e1558f..81bfe86b2 100644 --- a/src/job-executor.spec.js +++ b/src/job-executor.spec.js @@ -3,8 +3,10 @@ import {expect} from 'chai' import leche from 'leche' -import {productParams} from './job-executor' -import {_computeCrossProduct} from './job-executor' +import { + _computeCrossProduct, + productParams +} from './job-executor' describe('productParams', function () { leche.withData({ diff --git a/src/utils.js b/src/utils.js index 8dc4c532b..66fcc4f62 100644 --- a/src/utils.js +++ b/src/utils.js @@ -297,7 +297,7 @@ export function pSettle (promises) { // ------------------------------------------------------------------- -export { +export { // eslint-disable-line no-duplicate-imports all as pAll, catchPlus as pCatch, delay as pDelay, @@ -351,14 +351,14 @@ export const safeDateFormat = d3TimeFormat('%Y%m%dT%H%M%SZ') // This functions are often used throughout xo-server. // // Exports them from here to avoid direct dependencies on lodash. -export { default as forEach } from 'lodash.foreach' -export { default as isArray } from 'lodash.isarray' +export { default as forEach } from 'lodash.foreach' // eslint-disable-line no-duplicate-imports +export { default as isArray } from 'lodash.isarray' // eslint-disable-line no-duplicate-imports export { default as isBoolean } from 'lodash.isboolean' export { default as isEmpty } from 'lodash.isempty' export { default as isFunction } from 'lodash.isfunction' export { default as isInteger } from 'lodash.isinteger' export { default as isObject } from 'lodash.isobject' -export { default as isString } from 'lodash.isstring' +export { default as isString } from 'lodash.isstring' // eslint-disable-line no-duplicate-imports export { default as mapToArray } from 'lodash.map' // ------------------------------------------------------------------- diff --git a/src/vhd-merge.js b/src/vhd-merge.js index cae17cca4..8398938d0 100644 --- a/src/vhd-merge.js +++ b/src/vhd-merge.js @@ -528,12 +528,12 @@ export default async function vhdMerge ( // Child must be a delta. if (childVhd.footer.diskType !== HARD_DISK_TYPE_DIFFERENCING) { - throw new Error(`Unable to merge, child is not a delta backup.`) + throw new Error('Unable to merge, child is not a delta backup.') } // Merging in differencing disk is prohibited in our case. if (parentVhd.footer.diskType !== HARD_DISK_TYPE_DYNAMIC) { - throw new Error(`Unable to merge, parent is not a full backup.`) + throw new Error('Unable to merge, parent is not a full backup.') } // Allocation table map is not yet implemented. @@ -541,7 +541,7 @@ export default async function vhdMerge ( parentVhd.hasBlockAllocationTableMap() || childVhd.hasBlockAllocationTableMap() ) { - throw new Error(`Unsupported allocation table map.`) + throw new Error('Unsupported allocation table map.') } // Read allocation table of child/parent. diff --git a/src/xapi-object-to-xo.js b/src/xapi-object-to-xo.js index b72dba1d0..79d491bd8 100644 --- a/src/xapi-object-to-xo.js +++ b/src/xapi-object-to-xo.js @@ -322,7 +322,7 @@ const TRANSFORMS = { return disks })(), install_methods: (function () { - const {['install-methods']: methods} = otherConfig + const methods = otherConfig['install-methods'] return methods ? methods.split(',') : [] })(), diff --git a/src/xapi-stats.js b/src/xapi-stats.js index 68c60aeb6..a6403f03b 100644 --- a/src/xapi-stats.js +++ b/src/xapi-stats.js @@ -32,11 +32,7 @@ export class UnknownLegendFormat extends XapiStatsError { } } -export class FaultyGranularity extends XapiStatsError { - constructor (msg) { - super(msg) - } -} +export class FaultyGranularity extends XapiStatsError {} // ------------------------------------------------------------------- // Utils diff --git a/src/xapi.js b/src/xapi.js index 405fb9f7c..912d015cc 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -1,3 +1,5 @@ +/* eslint-disable camelcase */ + import createDebug from 'debug' import every from 'lodash.every' import fatfs from 'fatfs' @@ -8,6 +10,7 @@ import includes from 'lodash.includes' import pickBy from 'lodash.pickby' import sortBy from 'lodash.sortby' import unzip from 'julien-f-unzip' +import { defer } from 'promise-toolbox' import { utcFormat, utcParse } from 'd3-time-format' import { wrapError as wrapXapiError, @@ -274,8 +277,7 @@ export default class Xapi extends XapiBase { // TODO: implements a timeout. _waitObject (predicate) { if (isFunction(predicate)) { - let resolve - const promise = new Promise(resolve_ => resolve = resolve_) + const { promise, resolve } = defer() const unregister = this._registerGenericWatcher(obj => { if (predicate(obj)) { @@ -290,10 +292,7 @@ export default class Xapi extends XapiBase { let watcher = this._objectWatchers[predicate] if (!watcher) { - let resolve - const promise = new Promise(resolve_ => { - resolve = resolve_ - }) + const { promise, resolve } = defer() // Register the watcher. watcher = this._objectWatchers[predicate] = { @@ -352,18 +351,8 @@ export default class Xapi extends XapiBase { let watcher = this._taskWatchers[ref] if (!watcher) { - let resolve, reject - const promise = new Promise((resolve_, reject_) => { - resolve = resolve_ - reject = reject_ - }) - // Register the watcher. - watcher = this._taskWatchers[ref] = { - promise, - resolve, - reject - } + watcher = this._taskWatchers[ref] = defer() } return watcher.promise diff --git a/src/xo-mixins/authentication.js b/src/xo-mixins/authentication.js index 3f9087e43..258ee5d15 100644 --- a/src/xo-mixins/authentication.js +++ b/src/xo-mixins/authentication.js @@ -151,7 +151,7 @@ export default class { } async deleteAuthenticationToken (id) { - if (!await this._tokens.remove(id)) { // eslint-disable-line space-before-keywords + if (!await this._tokens.remove(id)) { throw new NoSuchAuthenticationToken(id) } } diff --git a/src/xo-mixins/backups.js b/src/xo-mixins/backups.js index caf0754ac..0f28f8cfb 100644 --- a/src/xo-mixins/backups.js +++ b/src/xo-mixins/backups.js @@ -545,7 +545,7 @@ export default class { $onFailure(() => handler.unlink(infoPath)::pCatch(noop)) - const { streams, + const { ...infos } = delta diff --git a/src/xo-mixins/subjects.js b/src/xo-mixins/subjects.js index 217e3dfa3..34a5909f5 100644 --- a/src/xo-mixins/subjects.js +++ b/src/xo-mixins/subjects.js @@ -57,7 +57,7 @@ export default class { }) xo.on('start', async () => { - if (!(await users.exists())) { + if (!await users.exists()) { const email = 'admin@admin.net' const password = 'admin' @@ -246,7 +246,7 @@ export default class { } async getGroup (id) { - const group = (await this._groups.first(id)) + const group = await this._groups.first(id) if (!group) { throw new NoSuchGroup(id) } diff --git a/src/xo-mixins/xen-servers.js b/src/xo-mixins/xen-servers.js index 8ce4546c5..8c88f66c9 100644 --- a/src/xo-mixins/xen-servers.js +++ b/src/xo-mixins/xen-servers.js @@ -78,7 +78,7 @@ export default class { async unregisterXenServer (id) { this.disconnectXenServer(id)::pCatch(noop) - if (!await this._servers.remove(id)) { // eslint-disable-line space-before-keywords + if (!await this._servers.remove(id)) { throw new NoSuchXenServer(id) } }