jenkins-bot has submitted this change and it was merged.
Change subject: Replace jshint, jscs, jsbeautify with eslint
......................................................................
Replace jshint, jscs, jsbeautify with eslint
Bug: T151741
Change-Id: I55051ff2d4e5d64a8cb5e8c8e2fd1e3e67a4a841
---
A .eslintrc.json
D .jsbeautifyrc
D .jscsrc
D .jshintignore
D .jshintrc
M app.js
M dictionary/dict/DictClient.js
M lineardoc/Doc.js
M lineardoc/Normalizer.js
M lineardoc/Parser.js
M lineardoc/TextBlock.js
M lineardoc/Utils.js
M lineardoc/index.js
M mt/Yandex.js
M mt/Youdao.js
M mt/annotationmapper/SubsequenceMatcher.js
M mt/index.js
M package.json
M pageloader/PageLoader.js
M routes/doc.js
M routes/info.js
M routes/root.js
M routes/v1.js
M segmentation/languages/index.js
M test/index.js
M utils/api-util.js
M utils/util.js
27 files changed, 84 insertions(+), 87 deletions(-)
Approvals:
Santhosh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..1cc15b0
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,16 @@
+{
+ "extends": "wikimedia",
+ "env": {
+ "browser": true,
+ "jquery": true,
+ "qunit": true,
+ "node": true
+ },
+ "globals": {
+ "require": false
+ },
+ "rules": {
+ "dot-notation": 0,
+ "wrap-iife": 0
+ }
+}
diff --git a/.jsbeautifyrc b/.jsbeautifyrc
deleted file mode 100644
index 0631808..0000000
--- a/.jsbeautifyrc
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "preserve_newlines": true,
- "jslint_happy": true,
- "keep_array_indentation": true,
- "space_before_conditional": true,
- "max_preserve_newlines": 10,
- "brace_style": "collapse",
- "keep_function_indentation": false,
- "break_chained_methods": false,
- "eval_code": false,
- "unescape_strings": false,
- "wrap_line_length": 0,
- "space_in_paren": true,
- "space_in_square_bracket": true,
- "git_happy": true,
- "indent_with_tabs": true
-}
diff --git a/.jscsrc b/.jscsrc
deleted file mode 100644
index 9b13945..0000000
--- a/.jscsrc
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "preset": "wikimedia",
- "requireVarDeclFirst": false,
- "requireCamelCaseOrUpperCaseIdentifiers": {
- "ignoreProperties": true
- }
-}
diff --git a/.jshintignore b/.jshintignore
deleted file mode 100644
index e3bef7f..0000000
--- a/.jshintignore
+++ /dev/null
@@ -1,2 +0,0 @@
-doc/
-node_modules
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 6245cdd..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- // Enforcing
- "bitwise": true,
- "eqeqeq": true,
- "freeze": true,
- "latedef": true,
- "noarg": true,
- "nonew": true,
- "undef": true,
- "unused": true,
- "strict": true,
-
- // Environment
- "node": true,
- "jasmine": true,
-
- "globals": {
- "CX": false,
- "QUnit": false,
- "before": false,
- "beforeEach": false,
- "after": false,
- "afterEach": false
- }
-}
diff --git a/app.js b/app.js
index 816eba9..f6ddda8 100644
--- a/app.js
+++ b/app.js
@@ -1,7 +1,5 @@
'use strict';
-require( 'core-js/shim' );
-
var http = require( 'http' ),
BBPromise = require( 'bluebird' ),
express = require( 'express' ),
@@ -13,6 +11,8 @@
packageInfo = require( './package.json' ),
path = require( 'path' ),
yaml = require( 'js-yaml' );
+
+require( 'core-js/shim' );
/**
* Creates an express app and initialises it
@@ -36,6 +36,7 @@
app.conf.interface = '0.0.0.0';
}
if ( app.conf.compression_level === undefined ) {
+ /* eslint camelcase:off */
app.conf.compression_level = 3;
}
if ( app.conf.cors === undefined ) {
@@ -232,6 +233,9 @@
* options and the logger and metrics-reporting objects from
* service-runner and starts an HTTP server, attaching the application
* object to it.
+ *
+ * @param {Object} options
+ * @return {Promise} a promise for an http server.
*/
module.exports = function ( options ) {
return initApp( options )
diff --git a/dictionary/dict/DictClient.js b/dictionary/dict/DictClient.js
index 4f569f2..be40e48 100644
--- a/dictionary/dict/DictClient.js
+++ b/dictionary/dict/DictClient.js
@@ -39,6 +39,7 @@
* Sanitize the words
*
* @param {Object} words
+ * @return {Object} result
*/
function parseWords( words ) {
var i, word, db, nDb, dbIdx,
@@ -235,7 +236,7 @@
nextResponse();
}
// Continuing previous data
-
+ /* eslint no-fallthrough:off */
switch ( status ) {
// greetings
case '220':
@@ -418,7 +419,7 @@
* @param {Object} options
*/
function lookup( word, options ) {
- var defs, words, wordList = [],
+ var words, wordList = [],
action = options.action || 'def';
switch ( action ) {
@@ -441,7 +442,7 @@
// Sanitize the wordList
words = parseWords( wordList );
if ( words.count ) {
- defs = getDefs( words, {
+ getDefs( words, {
action: options.action,
suggestions: !!options.suggestions,
error: options.error,
diff --git a/lineardoc/Doc.js b/lineardoc/Doc.js
index 5639f4d..126e3f1 100644
--- a/lineardoc/Doc.js
+++ b/lineardoc/Doc.js
@@ -21,6 +21,8 @@
* @class
*
* @constructor
+ *
+ * @param {string} wrapperTag open/close tags
*/
function Doc( wrapperTag ) {
this.items = [];
@@ -51,6 +53,7 @@
* @method
* @param {string} type Type of item: open|close|blockspace|textblock
* @param {Object|string|TextBlock} item Open/close tag, space or text block
+ * @return {Object}
* @chainable
*/
Doc.prototype.addItem = function ( type, item ) {
@@ -150,7 +153,6 @@
// textblock html list may be quite long, so
concatenate now
html.push( textblock.getHtml() );
} else {
- console.error( 'Unknown item type at ' + i );
throw new Error( 'Unknown item type: ' + type );
}
}
@@ -164,6 +166,7 @@
* Dump an XML Array version of the linear representation, for debugging
*
* @method
+ * @param {string} pad
* @return {string[]} Array that will concatenate to an XML string
representation
*/
Doc.prototype.dumpXmlArray = function ( pad ) {
@@ -199,7 +202,6 @@
dump.push.apply( dump, textBlock.dumpXmlArray( pad + '
' ) );
dump.push( pad + '</cxtextblock>' );
} else {
- console.error( 'Unknown item type: ', this.items[ i ] );
throw new Error( 'Unknown item type: ' + type );
}
}
diff --git a/lineardoc/Normalizer.js b/lineardoc/Normalizer.js
index 77601a2..4725c62 100644
--- a/lineardoc/Normalizer.js
+++ b/lineardoc/Normalizer.js
@@ -2,7 +2,7 @@
var SAXParser = require( 'sax' ).SAXParser,
util = require( 'util' ),
- Utils = require( './Utils.js' );
+ Utils = require( './Utils.js' );
/**
* Escape text for inclusion in HTML, not inside a tag.
diff --git a/lineardoc/Parser.js b/lineardoc/Parser.js
index 911ffc0..beb4c80 100644
--- a/lineardoc/Parser.js
+++ b/lineardoc/Parser.js
@@ -60,7 +60,7 @@
this.builder.pushBlockTag( {
name: 'div',
attributes: {
- class: 'cx-segment-block'
+ 'class': 'cx-segment-block'
}
} );
}
diff --git a/lineardoc/TextBlock.js b/lineardoc/TextBlock.js
index f173efa..0845095 100644
--- a/lineardoc/TextBlock.js
+++ b/lineardoc/TextBlock.js
@@ -8,6 +8,8 @@
* @class
*
* @constructor
+ *
+ * @param {string} textChunks annotated inline text
*/
function TextBlock( textChunks ) {
var i, len, cursor;
@@ -323,7 +325,7 @@
currentTextChunks, {
name: 'span',
attributes: {
- class: 'cx-segment',
+ 'class': 'cx-segment',
'data-segmentid': getNextId( 'segment' )
}
}
diff --git a/lineardoc/Utils.js b/lineardoc/Utils.js
index a704927..54255c9 100644
--- a/lineardoc/Utils.js
+++ b/lineardoc/Utils.js
@@ -86,10 +86,11 @@
* @return {Object} Cloned tag
*/
function cloneOpenTag( tag ) {
- var attr, newTag = {
- name: tag.name,
- attributes: {}
- };
+ var attr,
+ newTag = {
+ name: tag.name,
+ attributes: {}
+ };
for ( attr in tag.attributes ) {
newTag.attributes[ attr ] = tag.attributes[ attr ];
}
diff --git a/lineardoc/index.js b/lineardoc/index.js
index e0d8b65..f54438b 100644
--- a/lineardoc/index.js
+++ b/lineardoc/index.js
@@ -2,7 +2,7 @@
module.exports = {
Utils: require( './Utils.js' ),
- Doc: require( './Doc.js' ),
+ Doc: require( './Doc.js' ),
TextBlock: require( './TextBlock.js' ),
TextChunk: require( './TextChunk.js' ),
Builder: require( './Builder.js' ),
diff --git a/mt/Yandex.js b/mt/Yandex.js
index f8f68de..26ce137 100644
--- a/mt/Yandex.js
+++ b/mt/Yandex.js
@@ -70,6 +70,7 @@
/**
* Returns error name from error code.
*
+ * @param {number} code Error code
* @return {string}
*/
Yandex.prototype.getErrorName = function ( code ) {
diff --git a/mt/Youdao.js b/mt/Youdao.js
index 3b18fa4..0f14506 100644
--- a/mt/Youdao.js
+++ b/mt/Youdao.js
@@ -130,6 +130,7 @@
/**
* Returns error name from error code.
*
+ * @param {number} code Error code
* @return {string}
*/
Youdao.prototype.getErrorName = function ( code ) {
diff --git a/mt/annotationmapper/SubsequenceMatcher.js
b/mt/annotationmapper/SubsequenceMatcher.js
index c8f1640..1766197 100644
--- a/mt/annotationmapper/SubsequenceMatcher.js
+++ b/mt/annotationmapper/SubsequenceMatcher.js
@@ -132,6 +132,10 @@
/**
* Sort function for maching positions based on length.
+ *
+ * @param {number} positionA
+ * @param {number} positionB
+ * @return {number}
*/
function comparePositions( positionA, positionB ) {
if ( positionA.length < positionB.length ) {
diff --git a/mt/index.js b/mt/index.js
index 14ca54c..b6b20d6 100644
--- a/mt/index.js
+++ b/mt/index.js
@@ -1,5 +1,5 @@
module.exports = {
Apertium: require( './Apertium.js' ),
Yandex: require( './Yandex.js' ),
- Youdao: require( './Youdao.js' )
+ Youdao: require( './Youdao.js' )
};
diff --git a/package.json b/package.json
index 0725671..5ae3fc1 100644
--- a/package.json
+++ b/package.json
@@ -37,11 +37,11 @@
"check-dependencies": "^0.12.0",
"extend": "^3.0.0",
"mocha": "^2.5.3",
- "mocha-jscs": "^5.0.0",
- "mocha-jshint": "^2.3.1",
+ "mocha-eslint": "^3.0.1",
"mocha-lcov-reporter": "^1.2.0",
"node-inspector": "^0.12.6",
- "nsp": "^2.6.1"
+ "nsp": "^2.6.1",
+ "eslint-config-wikimedia": "0.3.0"
},
"scripts": {
"start": "service-runner",
diff --git a/pageloader/PageLoader.js b/pageloader/PageLoader.js
index 8a4ea22..a5fb761 100644
--- a/pageloader/PageLoader.js
+++ b/pageloader/PageLoader.js
@@ -23,10 +23,6 @@
}
}
-/**
- * @class PageLoader
- *
- */
function PageLoader( app ) {
this.app = app;
this.log = app.logger.log || function () {};
diff --git a/routes/doc.js b/routes/doc.js
index 756abe8..a10b25f 100644
--- a/routes/doc.js
+++ b/routes/doc.js
@@ -85,6 +85,7 @@
app = appObj;
return {
path: '/v1',
+ /* eslint camelcase:off */
skip_domain: true,
router: router
};
diff --git a/routes/info.js b/routes/info.js
index 9bcaaee..dd25d46 100644
--- a/routes/info.js
+++ b/routes/info.js
@@ -71,6 +71,7 @@
return {
path: '/_info',
+ /* eslint camelcase:off */
skip_domain: true,
router: router
};
diff --git a/routes/root.js b/routes/root.js
index d6533c9..291131c 100644
--- a/routes/root.js
+++ b/routes/root.js
@@ -36,6 +36,7 @@
app = appObj;
return {
path: '/',
+ /* eslint camelcase:off */
skip_domain: true,
router: router
};
diff --git a/routes/v1.js b/routes/v1.js
index baf1ace..2113d63 100644
--- a/routes/v1.js
+++ b/routes/v1.js
@@ -1,12 +1,9 @@
'use strict';
-var app, HTTPError, router,
+var app, router,
sUtil = require( '../utils/util' ),
jwt = require( 'jsonwebtoken' ),
registry;
-
-// shortcut
-HTTPError = sUtil.HTTPError;
/**
* The main router object
@@ -61,7 +58,7 @@
router.post( '/mt/:from/:to/:provider?', function ( req, res ) {
var mtClients, mtClient, provider,
- authzToken, authz, jwtConfig, sourceHtml,
+ authzToken, jwtConfig, sourceHtml,
from = req.params.from,
to = req.params.to;
@@ -91,7 +88,7 @@
jwtConfig = app.conf.jwt;
try {
- authz = jwt.verify( authzToken, jwtConfig.secret, {
+ jwt.verify( authzToken, jwtConfig.secret, {
algorithms: jwtConfig.algorithms
} );
} catch ( err ) {
@@ -178,6 +175,7 @@
app = appObj;
return {
path: '/v1/',
+ /* eslint camelcase:off */
api_version: 1,
router: router,
skip_domain: true
diff --git a/segmentation/languages/index.js b/segmentation/languages/index.js
index 7a0efb2..09ef3a4 100644
--- a/segmentation/languages/index.js
+++ b/segmentation/languages/index.js
@@ -9,5 +9,5 @@
sa: require( __dirname + '/SegmenterHi.js' ),
ti: require( __dirname + '/SegmenterAm.js' ),
zh: require( __dirname + '/SegmenterZh.js' ),
- default: require( __dirname + '/SegmenterDefault.js' )
+ 'default': require( __dirname + '/SegmenterDefault.js' )
};
diff --git a/test/index.js b/test/index.js
index fc606a4..35aeba4 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,6 +1,21 @@
'use strict';
-// Run jshint as part of normal testing
-require( 'mocha-jshint' )();
-// Run jscs as part of normal testing
-require( 'mocha-jscs' )();
+// Run eslint as part of normal testing
+var paths,
+ lint = require( 'mocha-eslint' );
+
+paths = [
+ 'dictionary',
+ 'mt',
+ 'lineardoc',
+ 'pageloader',
+ 'registry',
+ 'routes',
+ 'segmentation',
+ 'utils',
+ 'tests/**/*.js',
+ '*.js'
+];
+
+// Run the tests
+lint( paths );
diff --git a/utils/api-util.js b/utils/api-util.js
index a13879f..68183f6 100644
--- a/utils/api-util.js
+++ b/utils/api-util.js
@@ -102,6 +102,7 @@
// set up the RESTBase request template
if ( !app.conf.restbase_req ) {
+ /* eslint camelcase:off */
app.conf.restbase_req = {
method: '{{request.method}}',
uri: 'http://{{domain}}/api/rest_v1/{+path}',
diff --git a/utils/util.js b/utils/util.js
index fa727d3..f6a348f 100644
--- a/utils/util.js
+++ b/utils/util.js
@@ -10,6 +10,8 @@
* Error instance wrapping HTTP error responses
* for automatic error detection, logging and information leakage
* in route handlers.
+ *
+ * @param {Response} response HTTP error response
*/
function HTTPError( response ) {
var msg, key;
@@ -112,8 +114,8 @@
layer.handle = function ( req, res, next ) {
var startTime = Date.now();
BBPromise.try( function () {
- return origHandler( req, res,
next );
- } )
+ return origHandler( req, res, next );
+ } )
.catch( next )
.finally( function () {
var statusCode, statusClass,
stat;
@@ -255,6 +257,7 @@
req.headers = req.headers || {};
req.headers[ 'x-request-id' ] = req.headers[ 'x-request-id' ] ||
generateRequestId();
req.logger = app.logger.child( {
+ /* eslint camelcase:off */
request_id: req.headers[ 'x-request-id' ],
request: reqForLog( req, app.conf.log_header_whitelist )
} );
--
To view, visit https://gerrit.wikimedia.org/r/323793
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I55051ff2d4e5d64a8cb5e8c8e2fd1e3e67a4a841
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: KartikMistry <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits