Skip to content

Commit

Permalink
Move to Eslint for linting (admc#592)
Browse files Browse the repository at this point in the history
* Remove jshint

* Add eslint machinery

* Fix linting

* Lint in Travis
  • Loading branch information
imurchie authored and vrunoa committed Jan 6, 2020
1 parent 222cdf4 commit 0cf50f1
Show file tree
Hide file tree
Showing 59 changed files with 860 additions and 502 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"process": "readonly",
"Buffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-empty": ["error", { "allowEmptyCatch": true }]
}
};
16 changes: 0 additions & 16 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ env:
# - CONFIG=ipad
# - CONFIG=android_phone
script:
- npx gulp travis --config $CONFIG --sauce
- npm run lint && npx gulp travis --config $CONFIG --sauce
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WD.js
# WD.js

[![NPM version](http://img.shields.io/npm/v/wd.svg)](https://npmjs.org/package/wd)
[![NPM version](http://img.shields.io/npm/v/wd.svg)](https://npmjs.org/package/wd)
[![Downloads](http://img.shields.io/npm/dm/wd.svg)](https://npmjs.org/package/wd)
[![Dependency Status](https://david-dm.org/admc/wd.svg)](https://david-dm.org/admc/wd)
[![devDependency Status](https://david-dm.org/admc/wd/dev-status.svg)](https://david-dm.org/admc/wd#info=devDependencies)
Expand All @@ -25,7 +25,7 @@ This library is designed to be a maleable implementation of the webdriver protoc
npm install wd
```

Note: WD.js does not start the selenium server. You may use the [selenium-standalone](https://www.npmjs.com/package/selenium-standalone) package
Note: WD.js does not start the selenium server. You may use the [selenium-standalone](https://www.npmjs.com/package/selenium-standalone) package
to install and start a selenium server.

## Authors
Expand Down Expand Up @@ -84,7 +84,6 @@ browser.init({browserName:'chrome'}, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval("window.location.href", function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion browser-scripts/safe-execute-async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* jshint evil:true */
var args = Array.prototype.slice.call(arguments, 0);
var code = args[0], fargs = args[1], done = args[2];
var wrap = function() {
Expand Down
1 change: 0 additions & 1 deletion browser-scripts/safe-execute.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* jshint evil:true */
var args = Array.prototype.slice.call(arguments, 0);
var code = args[0], fargs = args[1];
var wrap = function() {
Expand Down
1 change: 0 additions & 1 deletion browser-scripts/wait-for-cond-in-browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* jshint evil:true */
var args = Array.prototype.slice.call(arguments, 0);
var condExpr = args[0], timeout = args[1],
poll = args[2], cb = args[3];
Expand Down
1 change: 0 additions & 1 deletion examples/async/browserstack.ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ browser.init(desired, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval("window.location.href", function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion examples/async/browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ browser.init(desired, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval("window.location.href", function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion examples/async/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ browser.init({browserName:'chrome'}, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval("window.location.href", function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion examples/async/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ browser.init({browserName:'firefox'}, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval("window.location.href", function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion examples/async/kobiton.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ browser.init(desired, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval('window.location.href', function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion examples/async/sauce.ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ browser.init(desired, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval("window.location.href", function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion examples/async/sauce.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ browser.init(desired, function() {
title.should.include('WD');
browser.elementById('i am a link', function(err, el) {
browser.clickElement(el, function() {
/* jshint evil: true */
browser.eval("window.location.href", function(err, href) {
href.should.include('guinea-pig2');
browser.quit();
Expand Down
1 change: 0 additions & 1 deletion examples/deprecated/deprecated.chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ browser.on('http', function(meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});

/* jshint evil: true */
browser
.chain()
.init({ browserName: 'chrome' })
Expand Down
1 change: 0 additions & 1 deletion examples/promise/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ browser.on('http', function(meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});

/* jshint evil: true */
browser
.init({browserName:'chrome'})
.get("http://admc.io/wd/test-pages/guinea-pig.html")
Expand Down
1 change: 0 additions & 1 deletion examples/promise/chromedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ browser.on('http', function(meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});

/* jshint evil: true */
browser
.status()
.init({browserName:'chrome'})
Expand Down
1 change: 0 additions & 1 deletion examples/promise/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ browser.on('http', function(meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});

/* jshint evil: true */
browser
.init({browserName:'firefox'})
.get("http://admc.io/wd/test-pages/guinea-pig.html")
Expand Down
2 changes: 0 additions & 2 deletions examples/promise/harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//
// This demos how to mix promise chain and generators

/* jshint moz: true, evil: true */

require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
Expand Down
2 changes: 0 additions & 2 deletions examples/promise/mocha-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// run with: mocha --harmony examples/promise/mocha-harmony.js

/* global describe, it, before , beforeEach, after*/
/* jshint moz: true, evil: true */

require('colors');
var chai = require("chai");
Expand Down Expand Up @@ -57,4 +56,3 @@ describe("mocha with generators", function() {
}));

});

2 changes: 0 additions & 2 deletions examples/promise/mocha-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('mocha spec examples', function() {
});

it("submit element should be clicked", function() {
/* jshint evil: true */
return browser
.elementById("submit")
.click()
Expand Down Expand Up @@ -102,7 +101,6 @@ describe('mocha spec examples', function() {
});

it("submit element should be clicked", function(done) {
/* jshint evil: true */
browser
.elementById("submit")
.click()
Expand Down
1 change: 0 additions & 1 deletion examples/promise/no-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ browser
})
.then(function (el) { return browser.clickElement(el); })
.then(function () {
/* jshint evil: true */
return browser.eval("window.location.href");
})
.then(function (href) { href.should.include('guinea-pig2'); })
Expand Down
1 change: 0 additions & 1 deletion examples/promise/sauce-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var desired = {
name: "This is an example test"
};

/* jshint evil: true */
browser
.init(desired)
.get("http://admc.io/wd/test-pages/guinea-pig.html")
Expand Down
1 change: 0 additions & 1 deletion examples/promise/sauce.ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var desired = {
name: "This is an example test"
};

/* jshint evil: true */
browser
.init(desired)
.get("http://admc.io/wd/test-pages/guinea-pig.html")
Expand Down
1 change: 0 additions & 1 deletion examples/promise/sauce.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var desired = {
name: "example test"
};

/* jshint evil: true */
browser
.init(desired)
.sauceJobUpdate({tags:['example']})
Expand Down
23 changes: 14 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
jshintStylish = require('jshint-stylish'),
Q = require('q'),
runSequence = Q.denodeify(require('run-sequence')),
path = require('path'),
Expand All @@ -11,8 +9,9 @@ var gulp = require('gulp'),
httpProxy = require('http-proxy'),
sauceConnectLauncher = require('sauce-connect-launcher'),
async = require('async'),
log = require('fancy-log')
gulpIf = require('gulp-if')
log = require('fancy-log'),
eslint = require('gulp-eslint'),
gulpIf = require('gulp-if'),
debug = require('gulp-debug');

require('./test/helpers/env');
Expand Down Expand Up @@ -80,11 +79,17 @@ function buildMochaOpts(opts) {
}

gulp.task('lint', function() {
// return gulp.src(['lib/**/*.js','test/**/*.js','browser-scripts/**/*.js'])
return gulp.src(['lib/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'));
var opts = {
fix: process.argv.indexOf('--fix') !== -1,
};
return gulp.src(['lib/**/*.js', 'test/**/*.js', '!node_modules', '!**/node_modules', '!build/**'])
.pipe(gulpIf(!!process.env.VERBOSE, debug()))
.pipe(eslint(opts))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(gulpIf(function (file) {
return file.eslint && file.eslint.fixed;
}, gulp.dest(process.cwd())));
});

gulp.task('test-unit', function () {
Expand Down
1 change: 0 additions & 1 deletion lib/asserters.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ var isHidden = new Asserter(
* @asserter
*/
function jsCondition(jsConditionExpr, safe) {
// jshint evil: true
if(safe === undefined) { safe = false; }
return new Asserter(
function(browser, cb) {
Expand Down
6 changes: 3 additions & 3 deletions lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ var net = require('net')
, assert = require('assert')
, wd = require('./main');

var connections = 0;
var connections = 0; // eslint-disable-line no-unused-vars

var startRepl = function() {
var r = repl.start('(wd): ');
r.context.assert = assert;
r.context.wd = wd;
r.context.help = function() {
console.log("WD - Shell.");
console.log("Access the webdriver object via the object: 'wd'");
console.log("WD - Shell."); // eslint-disable-line no-console
console.log("Access the webdriver object via the object: 'wd'"); // eslint-disable-line no-console
};

var server = net.createServer(function (socket) {
Expand Down
2 changes: 0 additions & 2 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ commands.safeExecute = function() {
* @jsonWire POST /session/:sessionId/execute
*/
(function() {
// jshint evil: true
commands.eval = function(code) {
var cb = findCallback(arguments);
code = codeToString(code);
Expand Down Expand Up @@ -359,7 +358,6 @@ commands.frame = function(frameRef) {
*/
commands.windowName = function() {
var cb = findCallback(arguments);
// jshint evil: true
commands.eval.apply(this, ["window.name", cb]);
};

Expand Down
4 changes: 3 additions & 1 deletion lib/deprecated-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ deprecatedChain.chain = function(obj){
this._chainOnErrorCallback = obj.onError;
} else if (!this._chainOnErrorCallback) {
this._chainOnErrorCallback = function(err) {
if (err) { console.error("a function in your .chain() failed:", err); }
if (err) {
console.error("a function in your .chain() failed:", err); // eslint-disable-line no-console
}
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/promise-webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ module.exports = function(WebDriver, Element, chainable) {
promise.printError = function(prepend) {
prepend = prepend || "";
return _this._enrich( promise.catch(function(err) {
console.log(prepend + err);
console.log(prepend + err); // eslint-disable-line no-console
throw err;
}), currentEl);
};
Expand All @@ -258,7 +258,7 @@ module.exports = function(WebDriver, Element, chainable) {
promise.print = function(prepend) {
prepend = prepend || "";
return _this._enrich( promise.then(function(val) {
console.log(prepend + val);
console.log(prepend + val); // eslint-disable-line no-console
}), currentEl);
};
}
Expand Down Expand Up @@ -319,7 +319,7 @@ module.exports = function(WebDriver, Element, chainable) {
return arg;
}
}).join(', ') + ' )';
console.log(' --> ' + status + context + " " + method + args);
console.log(' --> ' + status + context + " " + method + args); // eslint-disable-line no-console
});
};

Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ exports.deprecator = {
warn: function(cat, message) {
if(this.warnDeprecated && !this.deprecationMessageShown[cat]) {
this.deprecationMessageShown[cat] = 1;
console.warn(message);
console.warn(message); // eslint-disable-line no-console
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ Webdriver.prototype._init = function() {
err.data = data;
return cb(err);
} else {
/* eslint-disable no-console */
console.error('\x1b[31mError\x1b[0m: The environment you requested was unavailable.\n');
console.error('\x1b[33mReason\x1b[0m:\n');
console.error(data);
console.error('\nFor the available values please consult the WebDriver JSONWireProtocol,');
console.error('located at: \x1b[33mhttp://code.google.com/p/selenium/wiki/JsonWireProtocol#/session\x1b[0m');
/* eslint-enable no-console */
}
}
});
Expand Down
Loading

0 comments on commit 0cf50f1

Please sign in to comment.