fix lint warnings and use reduce
MODIFY
.gitignore
.gitignore
@@ -53,4 +53,3 @@ sample-code/csharp/test/obj
sample-code/csharp/test/bin
sample-code/csharp/packages
appium.zip
-.drivers.json

MODIFY
lib/appium.js
lib/appium.js
@@ -80,9 +80,7 @@ class AppiumDriver extends BaseDriver {
async getSessions () {
const sessions = await sessionsListGuard.acquire(AppiumDriver.name, () => this.sessions);
return _.toPairs(sessions)
- .map(([id, driver]) => {
- return {id, capabilities: driver.caps};
- });
+ .map(([id, driver]) => ({id, capabilities: driver.caps}));
}
printNewSessionAnnouncement (driverName, driverVersion) {

MODIFY
lib/cli-utils.js
lib/cli-utils.js
function errAndQuit (json, msg) {
if (json) {
- console.log(JSON.stringify({error: msg.toString()}));
+ console.log(JSON.stringify({error: `${msg}`}));
} else {
- console.error(msg.toString().red);
+ console.error(`${msg}`.red);
}
process.exit(1);
}

MODIFY
lib/config.js
lib/config.js
@@ -182,7 +182,7 @@ function validateServerArgs (parser, args) {
bootstrapPort: checkValidPort,
chromedriverPort: checkValidPort,
robotPort: checkValidPort,
- backendRetries: (r) => { return r >= 0; }
+ backendRetries: (r) => r >= 0
};
const nonDefaultArgs = getNonDefaultArgs(parser, args);

MODIFY
lib/driver-cli.js
lib/driver-cli.js
@@ -123,9 +123,9 @@ async function install ({appiumHome, json, driver, installType}) {
if (installType === INSTALL_TYPE_LOCAL) {
const msg = 'Linking driver from local path';
- const pkgJsonData = await spinWith(json, msg, async () => {
- return await linkPackage(appiumHome, installSpec);
- });
+ const pkgJsonData = await spinWith(json, msg, async () => (
+ await linkPackage(appiumHome, installSpec))
+ );
driverData = getDriverFields(pkgJsonData);
} else if (installType === INSTALL_TYPE_GITHUB) {
if (installSpec.split('/').length !== 2) {
@@ -198,9 +198,9 @@ async function installViaNpm ({appiumHome, json, driver, pkgName, pkgVer}) {
const specMsg = npmSpec === driver ? '' : ` using NPM install spec '${npmSpec}'`;
const msg = `Installing '${driver}'${specMsg}`;
try {
- const pkgJsonData = await spinWith(json, msg, async () => {
- return await installPackage(appiumHome, pkgName, pkgVer);
- });
+ const pkgJsonData = await spinWith(json, msg, async () => (
+ await installPackage(appiumHome, pkgName, pkgVer)
+ ));
return getDriverFields(pkgJsonData);
} catch (err) {
throw new Error(`Encountered an error when installing package: ${err.message}`);
@@ -217,12 +217,9 @@ function getDriverFields (pkgJsonData) {
const {driverName, automationName, platformNames, mainClass} = appium;
const reqFields = ['driverName', 'automationName', 'platformNames', 'mainClass'];
- const missingFields = [];
- for (const reqField of reqFields) {
- if (!appium[reqField]) {
- missingFields.push(reqField);
- }
- }
+ const missingFields = reqFields.reduce((acc, field) => (
+ appium[field] ? acc : acc.concat(field)
+ ), []);
if (!_.isEmpty(missingFields)) {
throw new Error(`Installed driver did not expose correct fields for compability ` +

MODIFY
lib/npm.js
lib/npm.js
@@ -58,7 +58,7 @@ async function installPackage (appiumHome, pkg, ver) {
// if we tried to install a package via git/github, we might not have been
// certain of the package name, so if we can retrieve it unambiguously from
// the json report of the install, do so
- const names = _.uniq([...res.json.added, ...res.json.updated].map(x => x.name));
+ const names = _.uniq([...res.json.added, ...res.json.updated].map((x) => x.name));
if (names.length === 1) {
pkgName = names[0];
}

MODIFY
lib/server-parser.js
lib/server-parser.js
@@ -302,7 +302,7 @@ const serverArgs = [
];
function parseSecurityFeatures (features) {
- const splitter = (splitOn, str) => `${str}`.split(splitOn).map(s => s.trim()).filter(Boolean);
+ const splitter = (splitOn, str) => `${str}`.split(splitOn).map((s) => s.trim()).filter(Boolean);
let parsedFeatures;
try {
parsedFeatures = splitter(',', features);

MODIFY
test/driver-specs.js
test/driver-specs.js
@@ -79,7 +79,7 @@ describe('AppiumDriver', function () {
new FakeDriver(),
new FakeDriver(),
];
- let mockFakeDrivers = _.map(fakeDrivers, (fd) => {return sinon.mock(fd);});
+ let mockFakeDrivers = _.map(fakeDrivers, (fd) => sinon.mock(fd));
mockFakeDrivers[0].expects('deleteSession')
.once();
mockFakeDrivers[1].expects('deleteSession')

fix lint warnings and use reduce