Niedzielski has uploaded a new change for review.
https://gerrit.wikimedia.org/r/325709
Change subject: Hygiene: improve ESLint configuration
......................................................................
Hygiene: improve ESLint configuration
• Lint everything not in .eslintignore
• Lint JSON files too (forbid invalid JSON files)
• Fix offenders
• Lint before running tests, not after, and remove mocha-eslint
• Forbid warnings
• Expose lint command
• Enable caching
Change-Id: I1f9c51ed6810a85245005f59aac08acf0edda39e
---
M .eslintrc.yml
M .gitignore
M app.js
M package.json
M test/index.js
M test/utils/assert.js
M test/utils/headers.js
M test/utils/logStream.js
M test/utils/server.js
9 files changed, 50 insertions(+), 49 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps
refs/changes/09/325709/1
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 9e2c225..a372143 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -1 +1,2 @@
-extends: 'eslint-config-node-services'
\ No newline at end of file
+extends: 'eslint-config-node-services'
+plugins: ['json']
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 77ec4b4..df3a503 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@
.DS_Store
tmp/
fixtures/
+/.eslintcache
diff --git a/app.js b/app.js
index d23eba6..17327f2 100644
--- a/app.js
+++ b/app.js
@@ -37,8 +37,8 @@
if (app.conf.compression_level === undefined) { app.conf.compression_level
= 3; }
if (app.conf.cors === undefined) { app.conf.cors = '*'; }
if (app.conf.csp === undefined) {
- app.conf.csp =
- "default-src 'self'; object-src 'none'; media-src *; img-src *;
style-src *; frame-ancestors 'self'";
+ // eslint-disable-next-line max-len
+ app.conf.csp = "default-src 'self'; object-src 'none'; media-src *;
img-src *; style-src *; frame-ancestors 'self'";
}
// set outgoing proxy
@@ -157,7 +157,8 @@
return undefined;
}
// check that the route exports the object we need
- if (route.constructor !== Object || !route.path || !route.router
|| !(route.api_version || route.skip_domain)) {
+ if (route.constructor !== Object || !route.path || !route.router
+ || !(route.api_version || route.skip_domain)) {
throw new TypeError(`routes/${fname} does not export the
correct object!`);
}
// normalise the path to be used as the mount point
diff --git a/package.json b/package.json
index 4b30e76..bc59b6a 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,8 @@
"main": "./app.js",
"scripts": {
"start": "service-runner",
- "test": "mocha && nsp check",
+ "lint": "eslint --cache --max-warnings 0 --ext .js --ext .json .",
+ "test": "npm run -s lint && mocha && nsp check",
"docker-start": "service-runner docker-start",
"docker-test": "service-runner docker-test",
"coverage": "istanbul cover _mocha -- -R spec"
@@ -58,15 +59,16 @@
"devDependencies": {
"ajv": "^4.7.7",
"csv-parse": "^1.1.7",
+ "eslint": "^3.11.0",
+ "eslint-config-node-services": "^1.0.6",
+ "eslint-plugin-json": "^1.2.0",
"extend": "^3.0.0",
"istanbul": "^0.4.5",
"mocha": "^3.1.2",
"mocha-jshint": "^2.3.1",
"mocha-lcov-reporter": "^1.2.0",
"nsp": "^2.6.2",
- "sepia": "^2.0.1",
- "mocha-eslint": "^3.0.1",
- "eslint-config-node-services": "^1.0.6"
+ "sepia": "^2.0.1"
},
"deploy": {
"target": "debian",
diff --git a/test/index.js b/test/index.js
index 44a808a..a8c4173 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,14 +1,4 @@
'use strict';
-
// Run jshint as part of normal testing
require('mocha-jshint')();
-require('mocha-eslint')([
- 'etc',
- 'lib',
- 'routes',
- 'test/features',
- 'test/lib'
-], {
- timeout: 10000
-});
diff --git a/test/utils/assert.js b/test/utils/assert.js
index 86b277a..3490e49 100644
--- a/test/utils/assert.js
+++ b/test/utils/assert.js
@@ -1,7 +1,25 @@
+/* eslint-disable no-console */
+
'use strict';
-
const assert = require('assert');
+
+
+function deepEqual(result, expected, message) {
+
+ try {
+ if (typeof expected === 'string') {
+ assert.ok(result === expected || (new
RegExp(expected).test(result)));
+ } else {
+ assert.deepEqual(result, expected, message);
+ }
+ } catch (e) {
+ console.log(`Expected:\n${JSON.stringify(expected, null, 2)}`);
+ console.log(`Result:\n${JSON.stringify(result, null, 2)}`);
+ throw e;
+ }
+
+}
/**
@@ -43,23 +61,6 @@
}
-function deepEqual(result, expected, message) {
-
- try {
- if (typeof expected === 'string') {
- assert.ok(result === expected || (new
RegExp(expected).test(result)));
- } else {
- assert.deepEqual(result, expected, message);
- }
- } catch (e) {
- console.log(`Expected:\n${JSON.stringify(expected, null, 2)}`);
- console.log(`Result:\n${JSON.stringify(result, null, 2)}`);
- throw e;
- }
-
-}
-
-
function notDeepEqual(result, expected, message) {
try {
@@ -76,12 +77,12 @@
function property(object, property) {
const msg = `expected property="${property}"`;
assert.ok(object, msg);
- assert.ok(object.hasOwnProperty(property), msg);
+ assert.ok({}.hasOwnProperty.call(object, property), msg);
}
function notProperty(object, property) {
- assert.ok(!object || !object.hasOwnProperty(property),
+ assert.ok(!object || !{}.hasOwnProperty.call(object, property),
`unexpected property="${property}"`);
}
diff --git a/test/utils/headers.js b/test/utils/headers.js
index f208dcd..0ca97e2 100644
--- a/test/utils/headers.js
+++ b/test/utils/headers.js
@@ -13,12 +13,16 @@
+
'profile="https://www.mediawiki.org/wiki/Specs/[a-z-]+/\\d+\\.\\d+\\.\\d+"$';
assert.contentType(res, expContentType);
assert.deepEqual(!!res.headers.etag, true, 'No ETag header
present');
- assert.deepEqual(res.headers.etag.indexOf('undefined'), -1, 'etag
should not contain "undefined"');
+ assert.deepEqual(res.headers.etag.indexOf('undefined'), -1,
+ 'etag should not contain "undefined"');
assert.deepEqual(res.headers['access-control-allow-origin'], '*');
- assert.deepEqual(res.headers['access-control-allow-headers'],
'accept, x-requested-with, content-type');
+ assert.deepEqual(res.headers['access-control-allow-headers'],
+ 'accept, x-requested-with, content-type');
assert.deepEqual(res.headers['content-security-policy'],
+ // eslint-disable-next-line max-len
"default-src 'self'; object-src 'none'; media-src *; img-src
*; style-src *; frame-ancestors 'self'");
assert.deepEqual(res.headers['x-content-security-policy'],
+ // eslint-disable-next-line max-len
"default-src 'self'; object-src 'none'; media-src *; img-src
*; style-src *; frame-ancestors 'self'");
assert.deepEqual(res.headers['x-frame-options'], 'SAMEORIGIN');
});
diff --git a/test/utils/logStream.js b/test/utils/logStream.js
index f4663c2..1fd6a38 100644
--- a/test/utils/logStream.js
+++ b/test/utils/logStream.js
@@ -21,6 +21,7 @@
}
}
} catch (e) {
+ // eslint-disable-next-line no-console
console.error('something went wrong trying to parrot a log entry',
e, chunk);
}
@@ -51,17 +52,17 @@
}
return {
- halt: halt,
- get: get
+ halt,
+ get
};
}
return {
- write: write,
- end: end,
- slice: slice,
- get: get
+ write,
+ end,
+ slice,
+ get
};
}
diff --git a/test/utils/server.js b/test/utils/server.js
index 122c843..b4d0982 100644
--- a/test/utils/server.js
+++ b/test/utils/server.js
@@ -39,7 +39,7 @@
// make a deep copy of it for later reference
const origConfig = extend(true, {}, config);
-let stop = function() { return BBPromise.resolve(); };
+let stop = () => { return BBPromise.resolve(); };
let options = null;
const runner = new ServiceRunner();
@@ -49,7 +49,7 @@
_options = _options || {};
if (!assert.isDeepEqual(options, _options)) {
- console.log('server options changed; restarting');
+ console.log('server options changed; restarting'); //
eslint-disable-line no-console
return stop().then(() => {
options = _options;
// set up the config
@@ -58,7 +58,7 @@
return runner.start(config.conf)
.then(() => {
stop = function() {
- console.log('stopping test server');
+ console.log('stopping test server'); //
eslint-disable-line no-console
return runner.stop().then(() => {
stop = function() { return BBPromise.resolve(); };
});
--
To view, visit https://gerrit.wikimedia.org/r/325709
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f9c51ed6810a85245005f59aac08acf0edda39e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits