Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/323793

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/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
24 files changed, 65 insertions(+), 84 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver 
refs/changes/93/323793/1

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..e1f4aef 100644
--- a/app.js
+++ b/app.js
@@ -1,6 +1,5 @@
 'use strict';
 
-require( 'core-js/shim' );
 
 var http = require( 'http' ),
        BBPromise = require( 'bluebird' ),
@@ -13,6 +12,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 +37,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 ) {
diff --git a/dictionary/dict/DictClient.js b/dictionary/dict/DictClient.js
index 4f569f2..9a228f4 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,
@@ -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..e40807a 100644
--- a/lineardoc/Doc.js
+++ b/lineardoc/Doc.js
@@ -150,7 +150,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 );
                }
        }
@@ -199,7 +198,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..ee00c88 100644
--- a/lineardoc/TextBlock.js
+++ b/lineardoc/TextBlock.js
@@ -323,7 +323,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..3137a2b 100644
--- a/lineardoc/Utils.js
+++ b/lineardoc/Utils.js
@@ -87,9 +87,9 @@
  */
 function cloneOpenTag( tag ) {
        var attr, newTag = {
-               name: tag.name,
-               attributes: {}
-       };
+                       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/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..1e920df 100644
--- a/segmentation/languages/index.js
+++ b/segmentation/languages/index.js
@@ -9,5 +9,6 @@
        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..629bb6b 100644
--- a/utils/util.js
+++ b/utils/util.js
@@ -112,8 +112,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 +255,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: newchange
Gerrit-Change-Id: I55051ff2d4e5d64a8cb5e8c8e2fd1e3e67a4a841
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to