Skip to content

Commit 50725af

Browse files
committed
Add eslint and pre-commit hooks
1 parent 068c4e5 commit 50725af

11 files changed

+53
-29
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sample-code

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "appium"
3+
}

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ sudo: false
33
node_js:
44
- "stable"
55
- "4"
6-
- "0.12"
6+
script:
7+
- npm run lint
8+
- npm run test
79
after_success:
810
- gulp coveralls

bin/ios-webkit-debug-proxy-launcher.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
22

3+
/* eslint no-console:0 */
4+
35
/*
46
* Small tool, launching and monitoring ios-web-kit-proxy, and relauching
57
* on predefined errors.
@@ -48,7 +50,7 @@ var startProxy = function () {
4850
proxy.stderr.on('data', function (data) {
4951
console.log('stderr: ' + data);
5052
var restartMessage = _(RESTART_ON_MESSAGES).find(function (message) {
51-
return ('' + data).indexOf(message) >= 0;
53+
return ('' + data).indexOf(message) >= 0;
5254
});
5355
if (restartMessage) {
5456
console.log('Detected error message:', restartMessage);

gulpfile.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint no-console:0 */
12
"use strict";
23

34
// turn all logging on since we have tests that rely on npmlog logs actually
@@ -43,8 +44,8 @@ gulp.task('docs', ['transpile'], function () {
4344
var appiumArguments = parser.getParser().rawArgs;
4445
var docFile = path.resolve(__dirname, "docs/en/writing-running-appium/server-args.md");
4546
var md = "# Appium server arguments\n\n";
46-
md += "Many Appium 1.5 server arguments have been deprecated in favor of the "
47-
md += "[--default-capabilities flag](/docs/en/writing-running-appium/default-capabilities-arg.md)."
47+
md += "Many Appium 1.5 server arguments have been deprecated in favor of the ";
48+
md += "[--default-capabilities flag](/docs/en/writing-running-appium/default-capabilities-arg.md).";
4849
md += "\n\nUsage: `node . [flags]`\n\n";
4950
md += "## Server flags\n";
5051
md += "All flags are optional, but some are required in conjunction with " +
@@ -61,7 +62,7 @@ gulp.task('docs', ['transpile'], function () {
6162
// let's replace it with <user>/...
6263
if (arg[0][0] === '--keystore-path') {
6364
var userPath = process.env.HOME || process.env.USERPROFILE;
64-
argOpts.defaultValue = argOpts.defaultValue.replace(userPath, '&lt;user&gt;')
65+
argOpts.defaultValue = argOpts.defaultValue.replace(userPath, '&lt;user&gt;');
6566
}
6667

6768
// handle empty objects

lib/appium.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class AppiumDriver extends BaseDriver {
9090
async getSessions () {
9191
let sessions = [];
9292
for (let [id, driver] of _.toPairs(this.sessions)) {
93-
sessions.push({id: id, capabilities: driver.caps});
93+
sessions.push({id, capabilities: driver.caps});
9494
}
9595
return sessions;
9696
}
@@ -155,8 +155,8 @@ class AppiumDriver extends BaseDriver {
155155

156156
curSessionDataForDriver (InnerDriver) {
157157
let data = _.values(this.sessions)
158-
.filter(s => s.constructor.name === InnerDriver.name)
159-
.map(s => s.driverData);
158+
.filter((s) => s.constructor.name === InnerDriver.name)
159+
.map((s) => s.driverData);
160160
for (let datum of data) {
161161
if (!datum) {
162162
throw new Error(`Problem getting session data for driver type ` +
@@ -165,7 +165,7 @@ class AppiumDriver extends BaseDriver {
165165
}
166166
}
167167
return data;
168-
}
168+
}
169169

170170
async deleteSession (sessionId) {
171171
try {

lib/config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
import { mkdirp, fs } from 'appium-support';
44
import { exec } from 'teen_process';
55
import logger from './logger';
6-
import pkgObj from '../../package.json';
6+
import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved
77

88

99
const APPIUM_VER = pkgObj.version;
@@ -30,8 +30,8 @@ async function getAppiumConfig () {
3030
let built = stat.mtime.getTime();
3131
let config = {
3232
'git-sha': await getGitRev(),
33-
'built': built,
34-
'version': APPIUM_VER,
33+
built,
34+
version: APPIUM_VER,
3535
};
3636
return config;
3737
}
@@ -55,7 +55,7 @@ function warnNodeDeprecations () {
5555

5656
async function showConfig () {
5757
let config = await getAppiumConfig();
58-
console.log(JSON.stringify(config));
58+
console.log(JSON.stringify(config)); // eslint-disable-line no-console
5959
}
6060

6161
function getNonDefaultArgs (parser, args) {

lib/logsink.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _createConsoleTransport (args, logLvl) {
6969
exitOnError: false,
7070
json: false,
7171
level: logLvl,
72-
formatter: function (options) {
72+
formatter (options) {
7373
let meta = options.meta && Object.keys(options.meta).length ? `\n\t${JSON.stringify(options.meta)}` : '';
7474
let timestampPrefix = '';
7575
if (options.timestamp) {
@@ -87,16 +87,15 @@ function _createConsoleTransport (args, logLvl) {
8787

8888
function _createFileTransport (args, logLvl) {
8989
let transport = new (winston.transports.File)({
90-
name: "file",
91-
timestamp: timestamp,
92-
filename: args.log,
93-
maxFiles: 1,
94-
handleExceptions: true,
95-
exitOnError: false,
96-
json: false,
97-
level: logLvl,
98-
}
99-
);
90+
name: "file",
91+
timestamp,
92+
filename: args.log,
93+
maxFiles: 1,
94+
handleExceptions: true,
95+
exitOnError: false,
96+
json: false,
97+
level: logLvl,
98+
});
10099
applyStripColorPatch(transport);
101100
return transport;
102101
}
@@ -152,6 +151,7 @@ async function _createTransports (args) {
152151

153152
transports.push(_createFileTransport(args, fileLogLevel));
154153
} catch (e) {
154+
// eslint-disable-next-line no-console
155155
console.log(`Tried to attach logging to file ${args.log} but an error ` +
156156
`occurred: ${e.message}`);
157157
}
@@ -161,6 +161,7 @@ async function _createTransports (args) {
161161
try {
162162
transports.push(_createHttpTransport(args, fileLogLevel));
163163
} catch (e) {
164+
// eslint-disable-next-line no-console
164165
console.log(`Tried to attach logging to Http at ${args.webhook} but ` +
165166
`an error occurred: ${e.message}`);
166167
}

lib/parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import _ from 'lodash';
44
import { ArgumentParser } from 'argparse';
5-
import pkgObj from '../../package.json';
5+
import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved
66

77

88
const args = [
@@ -778,7 +778,7 @@ function getParser () {
778778

779779
function getDefaultArgs () {
780780
let defaults = {};
781-
for (let [,arg] of args) {
781+
for (let [, arg] of args) {
782782
defaults[arg.dest] = arg.defaultValue;
783783
}
784784
return defaults;

package.json

+15-1
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,28 @@
6161
"scripts": {
6262
"prepublish": "gulp prepublish",
6363
"test": "gulp once",
64-
"watch": "gulp"
64+
"watch": "gulp",
65+
"precommit-msg": "echo 'Pre-commit checks...' && exit 0",
66+
"lint": "gulp eslint"
6567
},
68+
"pre-commit": [
69+
"precommit-msg",
70+
"lint",
71+
"test"
72+
],
6673
"devDependencies": {
6774
"appium-gulp-plugins": "^1.4.5",
75+
"babel-eslint": "^6.1.0",
6876
"chai": "^3.5.0",
6977
"chai-as-promised": "^5.3.0",
78+
"eslint": "^2.13.1",
79+
"eslint-config-appium": "0.0.6",
80+
"eslint-plugin-babel": "^3.3.0",
81+
"eslint-plugin-import": "^1.9.2",
82+
"eslint-plugin-mocha": "^3.0.0",
7083
"gulp": "^3.9.1",
7184
"mocha": "^2.5.3",
85+
"pre-commit": "^1.1.3",
7286
"sinon": "^1.17.4",
7387
"wd": "~0.4.0"
7488
},

test/config-specs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ describe('Config', () => {
4242
it('should log the config to console', async () => {
4343
let config = await getAppiumConfig();
4444
await showConfig();
45-
console.log.calledOnce.should.be.true;
46-
console.log.getCall(0).args[0].should.contain(JSON.stringify(config));
45+
console.log.calledOnce.should.be.true; // eslint-disable-line no-console
46+
console.log.getCall(0).args[0].should.contain(JSON.stringify(config)); // eslint-disable-line no-console
4747
});
4848
});
4949
});

0 commit comments

Comments
 (0)