Permalink
Browse files

Add eslint and pre-commit hooks

  • Loading branch information...
1 parent 068c4e5 commit 50725af0593633a5eeeb56f40e2e8d2463b50311 @imurchie imurchie committed Aug 3, 2016
Showing with 53 additions and 29 deletions.
  1. +1 −0 .eslintignore
  2. +3 −0 .eslintrc
  3. +3 −1 .travis.yml
  4. +3 −1 bin/ios-webkit-debug-proxy-launcher.js
  5. +4 −3 gulpfile.js
  6. +4 −4 lib/appium.js
  7. +4 −4 lib/config.js
  8. +12 −11 lib/logsink.js
  9. +2 −2 lib/parser.js
  10. +15 −1 package.json
  11. +2 −2 test/config-specs.js
View
@@ -0,0 +1 @@
+sample-code
View
@@ -0,0 +1,3 @@
+{
+ "extends": "appium"
+}
View
@@ -3,6 +3,8 @@ sudo: false
node_js:
- "stable"
- "4"
- - "0.12"
+script:
+ - npm run lint
+ - npm run test
after_success:
- gulp coveralls
@@ -1,5 +1,7 @@
#!/usr/bin/env node
+/* eslint no-console:0 */
+
/*
* Small tool, launching and monitoring ios-web-kit-proxy, and relauching
* on predefined errors.
@@ -48,7 +50,7 @@ var startProxy = function () {
proxy.stderr.on('data', function (data) {
console.log('stderr: ' + data);
var restartMessage = _(RESTART_ON_MESSAGES).find(function (message) {
- return ('' + data).indexOf(message) >= 0;
+ return ('' + data).indexOf(message) >= 0;
});
if (restartMessage) {
console.log('Detected error message:', restartMessage);
View
@@ -1,3 +1,4 @@
+/* eslint no-console:0 */
"use strict";
// turn all logging on since we have tests that rely on npmlog logs actually
@@ -43,8 +44,8 @@ gulp.task('docs', ['transpile'], function () {
var appiumArguments = parser.getParser().rawArgs;
var docFile = path.resolve(__dirname, "docs/en/writing-running-appium/server-args.md");
var md = "# Appium server arguments\n\n";
- md += "Many Appium 1.5 server arguments have been deprecated in favor of the "
- md += "[--default-capabilities flag](/docs/en/writing-running-appium/default-capabilities-arg.md)."
+ md += "Many Appium 1.5 server arguments have been deprecated in favor of the ";
+ md += "[--default-capabilities flag](/docs/en/writing-running-appium/default-capabilities-arg.md).";
md += "\n\nUsage: `node . [flags]`\n\n";
md += "## Server flags\n";
md += "All flags are optional, but some are required in conjunction with " +
@@ -61,7 +62,7 @@ gulp.task('docs', ['transpile'], function () {
// let's replace it with <user>/...
if (arg[0][0] === '--keystore-path') {
var userPath = process.env.HOME || process.env.USERPROFILE;
- argOpts.defaultValue = argOpts.defaultValue.replace(userPath, '&lt;user&gt;')
+ argOpts.defaultValue = argOpts.defaultValue.replace(userPath, '&lt;user&gt;');
}
// handle empty objects
View
@@ -90,7 +90,7 @@ class AppiumDriver extends BaseDriver {
async getSessions () {
let sessions = [];
for (let [id, driver] of _.toPairs(this.sessions)) {
- sessions.push({id: id, capabilities: driver.caps});
+ sessions.push({id, capabilities: driver.caps});
}
return sessions;
}
@@ -155,8 +155,8 @@ class AppiumDriver extends BaseDriver {
curSessionDataForDriver (InnerDriver) {
let data = _.values(this.sessions)
- .filter(s => s.constructor.name === InnerDriver.name)
- .map(s => s.driverData);
+ .filter((s) => s.constructor.name === InnerDriver.name)
+ .map((s) => s.driverData);
for (let datum of data) {
if (!datum) {
throw new Error(`Problem getting session data for driver type ` +
@@ -165,7 +165,7 @@ class AppiumDriver extends BaseDriver {
}
}
return data;
- }
+ }
async deleteSession (sessionId) {
try {
View
@@ -3,7 +3,7 @@ import path from 'path';
import { mkdirp, fs } from 'appium-support';
import { exec } from 'teen_process';
import logger from './logger';
-import pkgObj from '../../package.json';
+import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved
const APPIUM_VER = pkgObj.version;
@@ -30,8 +30,8 @@ async function getAppiumConfig () {
let built = stat.mtime.getTime();
let config = {
'git-sha': await getGitRev(),
- 'built': built,
- 'version': APPIUM_VER,
+ built,
+ version: APPIUM_VER,
};
return config;
}
@@ -55,7 +55,7 @@ function warnNodeDeprecations () {
async function showConfig () {
let config = await getAppiumConfig();
- console.log(JSON.stringify(config));
+ console.log(JSON.stringify(config)); // eslint-disable-line no-console
}
function getNonDefaultArgs (parser, args) {
View
@@ -69,7 +69,7 @@ function _createConsoleTransport (args, logLvl) {
exitOnError: false,
json: false,
level: logLvl,
- formatter: function (options) {
+ formatter (options) {
let meta = options.meta && Object.keys(options.meta).length ? `\n\t${JSON.stringify(options.meta)}` : '';
let timestampPrefix = '';
if (options.timestamp) {
@@ -87,16 +87,15 @@ function _createConsoleTransport (args, logLvl) {
function _createFileTransport (args, logLvl) {
let transport = new (winston.transports.File)({
- name: "file",
- timestamp: timestamp,
- filename: args.log,
- maxFiles: 1,
- handleExceptions: true,
- exitOnError: false,
- json: false,
- level: logLvl,
- }
- );
+ name: "file",
+ timestamp,
+ filename: args.log,
+ maxFiles: 1,
+ handleExceptions: true,
+ exitOnError: false,
+ json: false,
+ level: logLvl,
+ });
applyStripColorPatch(transport);
return transport;
}
@@ -152,6 +151,7 @@ async function _createTransports (args) {
transports.push(_createFileTransport(args, fileLogLevel));
} catch (e) {
+ // eslint-disable-next-line no-console
console.log(`Tried to attach logging to file ${args.log} but an error ` +
`occurred: ${e.message}`);
}
@@ -161,6 +161,7 @@ async function _createTransports (args) {
try {
transports.push(_createHttpTransport(args, fileLogLevel));
} catch (e) {
+ // eslint-disable-next-line no-console
console.log(`Tried to attach logging to Http at ${args.webhook} but ` +
`an error occurred: ${e.message}`);
}
View
@@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import _ from 'lodash';
import { ArgumentParser } from 'argparse';
-import pkgObj from '../../package.json';
+import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved
const args = [
@@ -778,7 +778,7 @@ function getParser () {
function getDefaultArgs () {
let defaults = {};
- for (let [,arg] of args) {
+ for (let [, arg] of args) {
defaults[arg.dest] = arg.defaultValue;
}
return defaults;
View
@@ -61,14 +61,28 @@
"scripts": {
"prepublish": "gulp prepublish",
"test": "gulp once",
- "watch": "gulp"
+ "watch": "gulp",
+ "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
+ "lint": "gulp eslint"
},
+ "pre-commit": [
+ "precommit-msg",
+ "lint",
+ "test"
+ ],
"devDependencies": {
"appium-gulp-plugins": "^1.4.5",
+ "babel-eslint": "^6.1.0",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
+ "eslint": "^2.13.1",
+ "eslint-config-appium": "0.0.6",
+ "eslint-plugin-babel": "^3.3.0",
+ "eslint-plugin-import": "^1.9.2",
+ "eslint-plugin-mocha": "^3.0.0",
"gulp": "^3.9.1",
"mocha": "^2.5.3",
+ "pre-commit": "^1.1.3",
"sinon": "^1.17.4",
"wd": "~0.4.0"
},
@@ -42,8 +42,8 @@ describe('Config', () => {
it('should log the config to console', async () => {
let config = await getAppiumConfig();
await showConfig();
- console.log.calledOnce.should.be.true;
- console.log.getCall(0).args[0].should.contain(JSON.stringify(config));
+ console.log.calledOnce.should.be.true; // eslint-disable-line no-console
+ console.log.getCall(0).args[0].should.contain(JSON.stringify(config)); // eslint-disable-line no-console
});
});
});

0 comments on commit 50725af

Please sign in to comment.