Skip to content

Commit 0cf50f1

Browse files
imurchievrunoa
authored andcommitted
Move to Eslint for linting (admc#592)
* Remove jshint * Add eslint machinery * Fix linting * Lint in Travis
1 parent 222cdf4 commit 0cf50f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+860
-502
lines changed

.eslintrc.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es6": true
6+
},
7+
"extends": "eslint:recommended",
8+
"globals": {
9+
"Atomics": "readonly",
10+
"SharedArrayBuffer": "readonly",
11+
"process": "readonly",
12+
"Buffer": "readonly"
13+
},
14+
"parserOptions": {
15+
"ecmaVersion": 2018
16+
},
17+
"rules": {
18+
"no-empty": ["error", { "allowEmptyCatch": true }]
19+
}
20+
};

.jshintrc

-16
This file was deleted.

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ env:
2121
# - CONFIG=ipad
2222
# - CONFIG=android_phone
2323
script:
24-
- npx gulp travis --config $CONFIG --sauce
24+
- npm run lint && npx gulp travis --config $CONFIG --sauce

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# WD.js
1+
# WD.js
22

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

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

3131
## Authors
@@ -84,7 +84,6 @@ browser.init({browserName:'chrome'}, function() {
8484
title.should.include('WD');
8585
browser.elementById('i am a link', function(err, el) {
8686
browser.clickElement(el, function() {
87-
/* jshint evil: true */
8887
browser.eval("window.location.href", function(err, href) {
8988
href.should.include('guinea-pig2');
9089
browser.quit();

browser-scripts/safe-execute-async.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* jshint evil:true */
21
var args = Array.prototype.slice.call(arguments, 0);
32
var code = args[0], fargs = args[1], done = args[2];
43
var wrap = function() {

browser-scripts/safe-execute.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* jshint evil:true */
21
var args = Array.prototype.slice.call(arguments, 0);
32
var code = args[0], fargs = args[1];
43
var wrap = function() {

browser-scripts/wait-for-cond-in-browser.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* jshint evil:true */
21
var args = Array.prototype.slice.call(arguments, 0);
32
var condExpr = args[0], timeout = args[1],
43
poll = args[2], cb = args[3];

examples/async/browserstack.ie.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ browser.init(desired, function() {
4141
title.should.include('WD');
4242
browser.elementById('i am a link', function(err, el) {
4343
browser.clickElement(el, function() {
44-
/* jshint evil: true */
4544
browser.eval("window.location.href", function(err, href) {
4645
href.should.include('guinea-pig2');
4746
browser.quit();

examples/async/browserstack.js

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ browser.init(desired, function() {
3838
title.should.include('WD');
3939
browser.elementById('i am a link', function(err, el) {
4040
browser.clickElement(el, function() {
41-
/* jshint evil: true */
4241
browser.eval("window.location.href", function(err, href) {
4342
href.should.include('guinea-pig2');
4443
browser.quit();

examples/async/chrome.js

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ browser.init({browserName:'chrome'}, function() {
2828
title.should.include('WD');
2929
browser.elementById('i am a link', function(err, el) {
3030
browser.clickElement(el, function() {
31-
/* jshint evil: true */
3231
browser.eval("window.location.href", function(err, href) {
3332
href.should.include('guinea-pig2');
3433
browser.quit();

examples/async/firefox.js

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ browser.init({browserName:'firefox'}, function() {
2828
title.should.include('WD');
2929
browser.elementById('i am a link', function(err, el) {
3030
browser.clickElement(el, function() {
31-
/* jshint evil: true */
3231
browser.eval("window.location.href", function(err, href) {
3332
href.should.include('guinea-pig2');
3433
browser.quit();

examples/async/kobiton.js

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ browser.init(desired, function() {
4949
title.should.include('WD');
5050
browser.elementById('i am a link', function(err, el) {
5151
browser.clickElement(el, function() {
52-
/* jshint evil: true */
5352
browser.eval('window.location.href', function(err, href) {
5453
href.should.include('guinea-pig2');
5554
browser.quit();

examples/async/sauce.ie.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ browser.init(desired, function() {
3939
title.should.include('WD');
4040
browser.elementById('i am a link', function(err, el) {
4141
browser.clickElement(el, function() {
42-
/* jshint evil: true */
4342
browser.eval("window.location.href", function(err, href) {
4443
href.should.include('guinea-pig2');
4544
browser.quit();

examples/async/sauce.js

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ browser.init(desired, function() {
3737
title.should.include('WD');
3838
browser.elementById('i am a link', function(err, el) {
3939
browser.clickElement(el, function() {
40-
/* jshint evil: true */
4140
browser.eval("window.location.href", function(err, href) {
4241
href.should.include('guinea-pig2');
4342
browser.quit();

examples/deprecated/deprecated.chain.js

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ browser.on('http', function(meth, path, data) {
2222
console.log(' > ' + meth.magenta, path, (data || '').grey);
2323
});
2424

25-
/* jshint evil: true */
2625
browser
2726
.chain()
2827
.init({ browserName: 'chrome' })

examples/promise/chrome.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ browser.on('http', function(meth, path, data) {
2727
console.log(' > ' + meth.magenta, path, (data || '').grey);
2828
});
2929

30-
/* jshint evil: true */
3130
browser
3231
.init({browserName:'chrome'})
3332
.get("http://admc.io/wd/test-pages/guinea-pig.html")

examples/promise/chromedriver.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ browser.on('http', function(meth, path, data) {
2727
console.log(' > ' + meth.magenta, path, (data || '').grey);
2828
});
2929

30-
/* jshint evil: true */
3130
browser
3231
.status()
3332
.init({browserName:'chrome'})

examples/promise/firefox.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ browser.on('http', function(meth, path, data) {
2727
console.log(' > ' + meth.magenta, path, (data || '').grey);
2828
});
2929

30-
/* jshint evil: true */
3130
browser
3231
.init({browserName:'firefox'})
3332
.get("http://admc.io/wd/test-pages/guinea-pig.html")

examples/promise/harmony.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//
44
// This demos how to mix promise chain and generators
55

6-
/* jshint moz: true, evil: true */
7-
86
require('colors');
97
var chai = require("chai");
108
var chaiAsPromised = require("chai-as-promised");

examples/promise/mocha-harmony.js

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// run with: mocha --harmony examples/promise/mocha-harmony.js
33

44
/* global describe, it, before , beforeEach, after*/
5-
/* jshint moz: true, evil: true */
65

76
require('colors');
87
var chai = require("chai");
@@ -57,4 +56,3 @@ describe("mocha with generators", function() {
5756
}));
5857

5958
});
60-

examples/promise/mocha-specs.js

-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ describe('mocha spec examples', function() {
5454
});
5555

5656
it("submit element should be clicked", function() {
57-
/* jshint evil: true */
5857
return browser
5958
.elementById("submit")
6059
.click()
@@ -102,7 +101,6 @@ describe('mocha spec examples', function() {
102101
});
103102

104103
it("submit element should be clicked", function(done) {
105-
/* jshint evil: true */
106104
browser
107105
.elementById("submit")
108106
.click()

examples/promise/no-chain.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ browser
3434
})
3535
.then(function (el) { return browser.clickElement(el); })
3636
.then(function () {
37-
/* jshint evil: true */
3837
return browser.eval("window.location.href");
3938
})
4039
.then(function (href) { href.should.include('guinea-pig2'); })

examples/promise/sauce-connect.js

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ var desired = {
3838
name: "This is an example test"
3939
};
4040

41-
/* jshint evil: true */
4241
browser
4342
.init(desired)
4443
.get("http://admc.io/wd/test-pages/guinea-pig.html")

examples/promise/sauce.ie.js

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ var desired = {
3838
name: "This is an example test"
3939
};
4040

41-
/* jshint evil: true */
4241
browser
4342
.init(desired)
4443
.get("http://admc.io/wd/test-pages/guinea-pig.html")

examples/promise/sauce.js

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ var desired = {
3535
name: "example test"
3636
};
3737

38-
/* jshint evil: true */
3938
browser
4039
.init(desired)
4140
.sauceJobUpdate({tags:['example']})

gulpfile.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
var gulp = require('gulp'),
2-
jshint = require('gulp-jshint'),
3-
jshintStylish = require('jshint-stylish'),
42
Q = require('q'),
53
runSequence = Q.denodeify(require('run-sequence')),
64
path = require('path'),
@@ -11,8 +9,9 @@ var gulp = require('gulp'),
119
httpProxy = require('http-proxy'),
1210
sauceConnectLauncher = require('sauce-connect-launcher'),
1311
async = require('async'),
14-
log = require('fancy-log')
15-
gulpIf = require('gulp-if')
12+
log = require('fancy-log'),
13+
eslint = require('gulp-eslint'),
14+
gulpIf = require('gulp-if'),
1615
debug = require('gulp-debug');
1716

1817
require('./test/helpers/env');
@@ -80,11 +79,17 @@ function buildMochaOpts(opts) {
8079
}
8180

8281
gulp.task('lint', function() {
83-
// return gulp.src(['lib/**/*.js','test/**/*.js','browser-scripts/**/*.js'])
84-
return gulp.src(['lib/**/*.js'])
85-
.pipe(jshint())
86-
.pipe(jshint.reporter(jshintStylish))
87-
.pipe(jshint.reporter('fail'));
82+
var opts = {
83+
fix: process.argv.indexOf('--fix') !== -1,
84+
};
85+
return gulp.src(['lib/**/*.js', 'test/**/*.js', '!node_modules', '!**/node_modules', '!build/**'])
86+
.pipe(gulpIf(!!process.env.VERBOSE, debug()))
87+
.pipe(eslint(opts))
88+
.pipe(eslint.format())
89+
.pipe(eslint.failAfterError())
90+
.pipe(gulpIf(function (file) {
91+
return file.eslint && file.eslint.fixed;
92+
}, gulp.dest(process.cwd())));
8893
});
8994

9095
gulp.task('test-unit', function () {

lib/asserters.js

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ var isHidden = new Asserter(
8888
* @asserter
8989
*/
9090
function jsCondition(jsConditionExpr, safe) {
91-
// jshint evil: true
9291
if(safe === undefined) { safe = false; }
9392
return new Asserter(
9493
function(browser, cb) {

lib/bin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ var net = require('net')
55
, assert = require('assert')
66
, wd = require('./main');
77

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

1010
var startRepl = function() {
1111
var r = repl.start('(wd): ');
1212
r.context.assert = assert;
1313
r.context.wd = wd;
1414
r.context.help = function() {
15-
console.log("WD - Shell.");
16-
console.log("Access the webdriver object via the object: 'wd'");
15+
console.log("WD - Shell."); // eslint-disable-line no-console
16+
console.log("Access the webdriver object via the object: 'wd'"); // eslint-disable-line no-console
1717
};
1818

1919
var server = net.createServer(function (socket) {

lib/commands.js

-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ commands.safeExecute = function() {
130130
* @jsonWire POST /session/:sessionId/execute
131131
*/
132132
(function() {
133-
// jshint evil: true
134133
commands.eval = function(code) {
135134
var cb = findCallback(arguments);
136135
code = codeToString(code);
@@ -359,7 +358,6 @@ commands.frame = function(frameRef) {
359358
*/
360359
commands.windowName = function() {
361360
var cb = findCallback(arguments);
362-
// jshint evil: true
363361
commands.eval.apply(this, ["window.name", cb]);
364362
};
365363

lib/deprecated-chain.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ deprecatedChain.chain = function(obj){
1313
this._chainOnErrorCallback = obj.onError;
1414
} else if (!this._chainOnErrorCallback) {
1515
this._chainOnErrorCallback = function(err) {
16-
if (err) { console.error("a function in your .chain() failed:", err); }
16+
if (err) {
17+
console.error("a function in your .chain() failed:", err); // eslint-disable-line no-console
18+
}
1719
};
1820
}
1921

lib/promise-webdriver.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ module.exports = function(WebDriver, Element, chainable) {
249249
promise.printError = function(prepend) {
250250
prepend = prepend || "";
251251
return _this._enrich( promise.catch(function(err) {
252-
console.log(prepend + err);
252+
console.log(prepend + err); // eslint-disable-line no-console
253253
throw err;
254254
}), currentEl);
255255
};
@@ -258,7 +258,7 @@ module.exports = function(WebDriver, Element, chainable) {
258258
promise.print = function(prepend) {
259259
prepend = prepend || "";
260260
return _this._enrich( promise.then(function(val) {
261-
console.log(prepend + val);
261+
console.log(prepend + val); // eslint-disable-line no-console
262262
}), currentEl);
263263
};
264264
}
@@ -319,7 +319,7 @@ module.exports = function(WebDriver, Element, chainable) {
319319
return arg;
320320
}
321321
}).join(', ') + ' )';
322-
console.log(' --> ' + status + context + " " + method + args);
322+
console.log(' --> ' + status + context + " " + method + args); // eslint-disable-line no-console
323323
});
324324
};
325325

lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ exports.deprecator = {
9090
warn: function(cat, message) {
9191
if(this.warnDeprecated && !this.deprecationMessageShown[cat]) {
9292
this.deprecationMessageShown[cat] = 1;
93-
console.warn(message);
93+
console.warn(message); // eslint-disable-line no-console
9494
}
9595
}
9696
};

lib/webdriver.js

+2
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ Webdriver.prototype._init = function() {
150150
err.data = data;
151151
return cb(err);
152152
} else {
153+
/* eslint-disable no-console */
153154
console.error('\x1b[31mError\x1b[0m: The environment you requested was unavailable.\n');
154155
console.error('\x1b[33mReason\x1b[0m:\n');
155156
console.error(data);
156157
console.error('\nFor the available values please consult the WebDriver JSONWireProtocol,');
157158
console.error('located at: \x1b[33mhttp://code.google.com/p/selenium/wiki/JsonWireProtocol#/session\x1b[0m');
159+
/* eslint-enable no-console */
158160
}
159161
}
160162
});

0 commit comments

Comments
 (0)