Skip to content

Commit

Permalink
Merge pull request #1177 from apiaryio/honzajavorek/eslint
Browse files Browse the repository at this point in the history
Use the latest linter rules
  • Loading branch information
honzajavorek committed Jan 2, 2019
2 parents 7222070 + e09d161 commit 47affc8
Show file tree
Hide file tree
Showing 58 changed files with 2,754 additions and 3,525 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: 'airbnb/base',
extends: 'airbnb-base',
env: {
'mocha': true,
'node': true
Expand Down Expand Up @@ -38,6 +38,7 @@ module.exports = {
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-restricted-syntax': 'off',
'no-use-before-define': 'off'
'no-use-before-define': 'off',
'prefer-destructuring': 'off',
}
};
4 changes: 2 additions & 2 deletions lib/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ ${packageData.name} v${packageData.version} \

this.wait = setTimeout(() => {
this.runDredd(this.dreddInstance);
}
, waitMilis);
},
waitMilis);
}
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Dredd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const fs = require('fs');
const request = require('request');
const url = require('url');

const configureReporters = require('./configureReporters');
const dreddTransactions = require('dredd-transactions');
const configureReporters = require('./configureReporters');
const handleRuntimeProblems = require('./handleRuntimeProblems');
const logger = require('./logger');
const Runner = require('./TransactionRunner');
Expand Down Expand Up @@ -154,8 +154,8 @@ https://dredd.org/en/latest/how-it-works/#using-https-proxy
}
globCallback();
});
}
, (err) => {
},
(err) => {
if (err) { return callback(err, this.stats); }

if (this.configDataIsEmpty && this.configuration.files.length === 0) {
Expand Down Expand Up @@ -184,8 +184,8 @@ API description document (or documents) not found on path:
} else {
this.readLocalFile(fileUrlOrPath, loadCallback);
}
}
, callback);
},
callback);
}

downloadFile(fileUrl, callback) {
Expand Down Expand Up @@ -247,8 +247,8 @@ Is the provided path correct?
this.transactions = this.transactions.concat(compilationResult.transactions);
next();
});
}
, (runtimeError) => {
},
(runtimeError) => {
if (!runtimeError) { runtimeError = handleRuntimeProblems(this.configuration.data); }
callback(runtimeError, this.stats);
});
Expand Down
4 changes: 2 additions & 2 deletions lib/HooksWorkerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ $ go get github.com/snikch/goodman/cmd/goodman
clearTimeout(timeout);
if (!this.clientConnected) {
if (this.handlerClient) { this.handlerClient.destroy(); }
const msg = `Connection timeout ${this.connectTimeout / 1000}s to hooks handler ` +
`on ${this.handlerHost}:${this.handlerPort} exceeded. Try increasing the limit.`;
const msg = `Connection timeout ${this.connectTimeout / 1000}s to hooks handler `
+ `on ${this.handlerHost}:${this.handlerPort} exceeded. Try increasing the limit.`;
callback(new Error(msg));
}
}
Expand Down
24 changes: 12 additions & 12 deletions lib/TransactionRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class TransactionRunner {
});
});
});
}
, (iterationError) => {
},
(iterationError) => {
if (iterationError) { return callback(iterationError); }

logger.verbose('Running \'afterAll\' hooks');
Expand Down Expand Up @@ -268,8 +268,8 @@ output;\
libraries: {
_log: sandboxedLogLibraryPath,
},
}
, (err, result = {}) => {
},
(err, result = {}) => {
sandbox.kill();
this.sandboxedHookResultsHandler(err, data, result, callback);
});
Expand Down Expand Up @@ -339,9 +339,9 @@ Interface of the hooks functions will be unified soon across all hook functions:

const { origin, request, response } = transaction;
const mediaType = (
configuration.data[origin.filename] ?
configuration.data[origin.filename].mediaType :
undefined
configuration.data[origin.filename]
? configuration.data[origin.filename].mediaType
: undefined
) || 'text/vnd.apiblueprint';

// Parse the server URL (just once, caching it in @parsedUrl)
Expand Down Expand Up @@ -568,22 +568,22 @@ Interface of the hooks functions will be unified soon across all hook functions:
transaction.test = test;
this.skipTransaction(transaction, 'Skipped in before hook');
return callback();
} else if (transaction.fail) {
} if (transaction.fail) {
logger.verbose('HTTP transaction was marked in hooks as to be failed. Reporting as failed');
transaction.test = test;
this.failTransaction(transaction, `Failed in before hook: ${transaction.fail}`);
return callback();
} else if (this.configuration.options['dry-run']) {
} if (this.configuration.options['dry-run']) {
logger.info('Dry run. Not performing HTTP request');
transaction.test = test;
this.skipTransaction(transaction);
return callback();
} else if (this.configuration.options.names) {
} if (this.configuration.options.names) {
logger.info(transaction.name);
transaction.test = test;
this.skipTransaction(transaction);
return callback();
} else if ((this.configuration.options.method.length > 0) && !(Array.from(this.configuration.options.method).includes(transaction.request.method))) {
} if ((this.configuration.options.method.length > 0) && !(Array.from(this.configuration.options.method).includes(transaction.request.method))) {
logger.info(`\
Only ${(Array.from(this.configuration.options.method).map(m => m.toUpperCase())).join(', ')}\
requests are set to be executed. \
Expand All @@ -592,7 +592,7 @@ Not performing HTTP ${transaction.request.method.toUpperCase()} request.\
transaction.test = test;
this.skipTransaction(transaction);
return callback();
} else if ((this.configuration.options.only.length > 0) && !(Array.from(this.configuration.options.only).includes(transaction.name))) {
} if ((this.configuration.options.only.length > 0) && !(Array.from(this.configuration.options.only).includes(transaction.name))) {
logger.info(`\
Only '${this.configuration.options.only}' transaction is set to be executed. \
Not performing HTTP request for '${transaction.name}'.\
Expand Down
27 changes: 13 additions & 14 deletions lib/addHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ function addHooks(runner, transactions, callback) {
if (transactionName.match(pattern)) {
const newTransactionName = transactionName.replace(pattern, '');
if (hooks[hookType][newTransactionName]) {
hooks[hookType][newTransactionName] =
transactionHooks.concat(hooks[hookType][newTransactionName]);
hooks[hookType][newTransactionName] = transactionHooks.concat(hooks[hookType][newTransactionName]);
} else {
hooks[hookType][newTransactionName] = transactionHooks;
}
Expand Down Expand Up @@ -53,8 +52,8 @@ Stack: ${error.stack}

function loadSandboxHooksFromStrings(next) {
const isHooksDataCorrect = (
typeof runner.configuration.hooksData === 'object' ||
!Array.isArray(runner.configuration.hooksData)
typeof runner.configuration.hooksData === 'object'
|| !Array.isArray(runner.configuration.hooksData)
);

if (!isHooksDataCorrect) {
Expand All @@ -79,8 +78,8 @@ Stack: ${error.stack}

nextHook();
});
}
, next);
},
next);
}

if (!runner.logs) { runner.logs = []; }
Expand All @@ -93,8 +92,8 @@ Stack: ${error.stack}
});

// Loading hooks from string, sandbox mode must be enabled
if (!(runner && runner.configuration && runner.configuration.options &&
runner.configuration.options.hookfiles)) {
if (!(runner && runner.configuration && runner.configuration.options
&& runner.configuration.options.hookfiles)) {
if (runner.configuration.hooksData) {
if (runner.configuration.options.sandbox === true) {
return loadSandboxHooksFromStrings(callback);
Expand Down Expand Up @@ -132,8 +131,8 @@ Stack: ${error.stack}
// Loading files in non sandboxed nodejs
if (!runner.configuration.options.sandbox === true) {
// If the language is empty or it is nodejs
if (!runner.configuration.options.language ||
runner.configuration.options.language === 'nodejs') {
if (!runner.configuration.options.language
|| runner.configuration.options.language === 'nodejs') {
// Load regular files from fs
for (const file of files) {
loadHookFile(file);
Expand All @@ -153,7 +152,7 @@ Stack: ${error.stack}
// Load sandbox files from fs
logger.info('Loading hook files in sandboxed context:', files);

return async.eachSeries(files, (resolvedPath, nextFile) =>
async.eachSeries(files, (resolvedPath, nextFile) => {
// Load hook file content
fs.readFile(resolvedPath, 'utf8', (readingError, data) => {
if (readingError) { return nextFile(readingError); }
Expand All @@ -165,10 +164,10 @@ Stack: ${error.stack}
// Fixing #168 issue
fixLegacyTransactionNames(runner.hooks);

return nextFile();
nextFile();
});
})
, callback);
});
}, callback);
}

module.exports = addHooks;
4 changes: 2 additions & 2 deletions lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const logger = require('./logger');
function coerceToArray(value) {
if (Array.isArray(value)) {
return value;
} else if (typeof value === 'string') {
} if (typeof value === 'string') {
return [value];
} else if ((value == null)) {
} if ((value == null)) {
return [];
}
return value;
Expand Down
8 changes: 2 additions & 6 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,10 @@ function detectApiDescription(files) {
const apib = files.filter(f => f.match(/\.apib$/i));
if (apib.length) { return apib[0]; }

const openapi2 = files.filter(f =>
f.match(/\.ya?ml$/i) && f.match(/swagger/)
);
const openapi2 = files.filter(f => f.match(/\.ya?ml$/i) && f.match(/swagger/));
if (openapi2.length) { return openapi2[0]; }

const openapi = files.filter(f =>
f.match(/\.ya?ml$/i) && f.match(/api/)
);
const openapi = files.filter(f => f.match(/\.ya?ml$/i) && f.match(/api/));
if (openapi.length) { return openapi[0]; }

return 'apiary.apib';
Expand Down
11 changes: 5 additions & 6 deletions lib/reporters/CLIReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ CLIReporter.prototype.configureEmitter = function configureEmitter(emitter) {
}

if (this.stats.tests > 0) {
logger.complete(`${this.stats.passes} passing, ` +
`${this.stats.failures} failing, ` +
`${this.stats.errors} errors, ` +
`${this.stats.skipped} skipped, ` +
`${this.stats.tests} total`
);
logger.complete(`${this.stats.passes} passing, `
+ `${this.stats.failures} failing, `
+ `${this.stats.errors} errors, `
+ `${this.stats.skipped} skipped, `
+ `${this.stats.tests} total`);
}

logger.complete(`Tests took ${this.stats.duration}ms`);
Expand Down
4 changes: 2 additions & 2 deletions lib/reporters/NyanReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ NyanCatReporter.prototype.drawNyanCat = function drawNyanCat() {
NyanCatReporter.prototype.face = function face() {
if (this.stats.failures) {
return '( x .x)';
} else if (this.stats.skipped) {
} if (this.stats.skipped) {
return '( o .o)';
} else if (this.stats.passes) {
} if (this.stats.passes) {
return '( ^ .^)';
}
return '( - .-)';
Expand Down
3 changes: 1 addition & 2 deletions lib/reporters/XUnitReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ XUnitReporter.prototype.configureEmitter = function configureEmitter(emitter) {
skip: this.stats.skipped,
timestamp: (new Date()).toUTCString(),
time: this.stats.duration / 1000,
}, false)
);
}, false));
callback();
} else {
logger.error(err);
Expand Down
8 changes: 5 additions & 3 deletions lib/sandboxHooksCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ output\
`;

const sandbox = new Pitboss(wrappedCode);
sandbox.run({ libraries: {
_Hooks: '../../../lib/Hooks', console: 'console',
} }, (err, result) => {
sandbox.run({
libraries: {
_Hooks: '../../../lib/Hooks', console: 'console',
},
}, (err, result) => {
sandbox.kill();
if (err) { return callback(err); }
callback(undefined, result);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
"@commitlint/travis-cli": "7.2.1",
"body-parser": "1.18.3",
"coveralls": "3.0.2",
"eslint": "4.4.1",
"eslint-config-airbnb": "15.1.0",
"eslint-plugin-import": "2.7.0",
"eslint": "5.11.1",
"eslint-config-airbnb-base": "13.1.0",
"eslint-plugin-import": "2.14.0",
"express": "4.16.3",
"istanbul": "0.4.5",
"lcov-result-merger": "1.2.0",
Expand Down
Loading

0 comments on commit 47affc8

Please sign in to comment.