Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/320802
Change subject: Enforce coding conventions using jscs ...................................................................... Enforce coding conventions using jscs Life is too short to worry about coding conventions when Grunt can fix them for you (Note we're still transitioning to eslint in our projects and since the mediawiki services code conventions differ from the rest of MediaWiki's JS code and mobileapps already have this quite nicely captured, we can transition to eslint later when we have more time) Captured in: https://www.mediawiki.org/wiki/Topic:Tf3bj28q4wm87clx Changes: * Coding style conventions are applied to all files Change-Id: I49d9236a14f81b40e06c6260216dc97149ca20e2 --- A .jscsrc A Gruntfile.js M package.json M routes/trending-v1.js M test/utils/logStream.js 5 files changed, 115 insertions(+), 59 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/trending-edits refs/changes/02/320802/1 diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..6fce672 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,34 @@ +{ + "preset": "wikimedia", + + "requireSpaceAfterLineComment": null, + "requireSpacesInsideParentheses": false, + "requireSpacesInsideBrackets": false, + "requireSpaceAfterKeywords": false, + "requireMultipleVarDecl": null, + "requireLineBreakAfterVariableAssignment": null, + "requireSpaceAfterBinaryOperators": null, + "validateQuoteMarks": null, + "disallowTrailingComma": null, + "disallowQuotedKeysInObjects": null, + "requireSpaceBeforeObjectValues": null, + "disallowDanglingUnderscores": null, + "disallowImplicitTypeConversion": null, + "requireCamelCaseOrUpperCaseIdentifiers": null, + "disallowSpaceAfterObjectKeys": null, + "requireSpaceBeforeBinaryOperators": null, + "disallowMultipleLineBreaks": null, + "requireDotNotation": null, + "disallowSpacesInsideParentheses": null, + "validateIndentation": 4, + "requireSpaceBeforeKeywords": null, + "disallowMixedSpacesAndTabs": null, + "requireLineFeedAtFileEnd": null, + "requireSpacesInsideObjectBrackets": null, + "requireSpaceBetweenArguments": null, + "requireVarDeclFirst": null, + "jsDoc": null, + "excludeFiles": [ + "node_modules/**" + ] +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..cf46990 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,20 @@ +"use strict"; + +module.exports = function ( grunt ) { + grunt.loadNpmTasks("grunt-jscs"); + + grunt.initConfig( { + jscs: { + src: ['lib/**/*.js', 'routes/*.js', 'test/**/*.js' ], + options: { + config: ".jscsrc", + fix: true, // Autofix code style violations when possible. + requireCurlyBraces: [ "if" ] + } + } + } ); + + grunt.registerTask( 'test', [ 'jscs' ] ); + + grunt.registerTask( 'default', [ 'test' ] ); +}; diff --git a/package.json b/package.json index ce1e8e0..dc6e75e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "./app.js", "scripts": { "start": "service-runner", - "test": "mocha && nsp check", + "test": "grunt test && mocha && nsp check", "docker-start": "service-runner docker-start", "docker-test": "service-runner docker-test", "coverage": "istanbul cover _mocha -- -R spec" @@ -35,6 +35,8 @@ }, "devDependencies": { "extend": "^3.0.0", + "grunt": "^1.0.1", + "grunt-jscs": "^3.0.1", "istanbul": "^0.4.4", "mocha": "^2.5.3", "mocha-jshint": "^2.3.1", diff --git a/routes/trending-v1.js b/routes/trending-v1.js index 5159834..3b8b8c7 100644 --- a/routes/trending-v1.js +++ b/routes/trending-v1.js @@ -35,21 +35,21 @@ router.get('/trending-edits', function(req, res) { var domain = req.params.domain; var data = { - timestamp: new Date(), - pages: [] + timestamp: new Date(), + pages: [] }; if ( domain === 'en.wikipedia.org' ) { - res.status(200).type('application/json').end(JSON.stringify(data)); + res.status(200).type('application/json').end(JSON.stringify(data)); } else { - // These are not implemented yet. The hope is to be able to trend - // the language equivalent of the english article. - throw new HTTPError({ - status: 501, - type: 'not_implemented', - title: 'Not implemented', - detail: ERROR_UNAVAILABLE - }); + // These are not implemented yet. The hope is to be able to trend + // the language equivalent of the english article. + throw new HTTPError({ + status: 501, + type: 'not_implemented', + title: 'Not implemented', + detail: ERROR_UNAVAILABLE + }); } }); diff --git a/test/utils/logStream.js b/test/utils/logStream.js index f8e292d..842df59 100644 --- a/test/utils/logStream.js +++ b/test/utils/logStream.js @@ -4,65 +4,65 @@ function logStream(logStdout) { - var log = []; - var parrot = bunyan.createLogger({ - name: 'test-logger', - level: 'warn' - }); + var log = []; + var parrot = bunyan.createLogger({ + name: 'test-logger', + level: 'warn' + }); - function write(chunk, encoding, callback) { - try { - var entry = JSON.parse(chunk); - var levelMatch = /^(\w+)/.exec(entry.levelPath); - if (logStdout && levelMatch) { - var level = levelMatch[1]; - if (parrot[level]) { - parrot[level](entry); + function write(chunk, encoding, callback) { + try { + var entry = JSON.parse(chunk); + var levelMatch = /^(\w+)/.exec(entry.levelPath); + if (logStdout && levelMatch) { + var level = levelMatch[1]; + if (parrot[level]) { + parrot[level](entry); + } } + } catch (e) { + console.error('something went wrong trying to parrot a log entry', e, chunk); } - } catch (e) { - console.error('something went wrong trying to parrot a log entry', e, chunk); + + log.push(chunk); } - log.push(chunk); - } - - // to implement the stream writer interface - function end(chunk, encoding, callback) { - } - - function get() { - return log; - } - - function slice() { - - var begin = log.length; - var end = null; - - function halt() { - if (end === null) { - end = log.length; - } + // to implement the stream writer interface + function end(chunk, encoding, callback) { } function get() { - return log.slice(begin, end); + return log; + } + + function slice() { + + var begin = log.length; + var end = null; + + function halt() { + if (end === null) { + end = log.length; + } + } + + function get() { + return log.slice(begin, end); + } + + return { + halt: halt, + get: get + }; + } return { - halt: halt, - get: get + write: write, + end: end, + slice: slice, + get: get }; - - } - - return { - write: write, - end: end, - slice: slice, - get: get - }; } module.exports = logStream; -- To view, visit https://gerrit.wikimedia.org/r/320802 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I49d9236a14f81b40e06c6260216dc97149ca20e2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/trending-edits Gerrit-Branch: master Gerrit-Owner: Jdlrobson <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
