Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/236836
Change subject: build: Enforce jshint and jscs test ...................................................................... build: Enforce jshint and jscs test * Reduce jshint settings to those relevant in curent versions of JSHint (coding style is now checked by JSCS). * Add JSCS build step (with Wikimedia preset). Also: * Change file header to use "/*!" instead of "/**" since this comment does not validate as a valid JSDuck comment block (errors on unknown @see and @license) * Remove type check for window.Geo. If it's truthy, then the next will work fine. (Property access works on all truthy values). And we don't actually need it to be a plain object, upstream could turn it into an instance of something that provides compatible properties. * After the check, use Geo without "window." prefix. Similar to what the code does for 'performance' and 'chrome' and justifies the entry for "Geo" in jshint-predef (which was previously unused). * Enforce ES3 syntax compatibility. * Minor fixes to satisfy Wikimedia coding style as enforced by JSCS. Change-Id: I721864fb6b50cc0fe0752da561950d03c2c77ae1 (cherry picked from commit 61505a1623d2bae2d4bec6a020464708d7b0795a) --- A .jscsrc M .jshintrc M Gruntfile.js M modules/ext.navigationTiming.js M package.json 5 files changed, 50 insertions(+), 43 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NavigationTiming refs/changes/36/236836/1 diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..fcf4a3e --- /dev/null +++ b/.jscsrc @@ -0,0 +1,7 @@ +{ + "preset": "wikimedia", + + "excludeFiles": [ + "{node_modules}/**" + ] +} diff --git a/.jshintrc b/.jshintrc index ee816f7..94545ab 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,7 +1,6 @@ { "predef": [ "Geo", - "QUnit", "jQuery", "mediaWiki", "mediaWikiLoadStart", @@ -9,30 +8,17 @@ "chrome" ], + // Enforcing "bitwise": true, - "camelcase": true, - "curly": true, "eqeqeq": true, - "forin": false, - "immed": true, + "es3": true, + "freeze": true, "latedef": true, - "newcap": true, "noarg": true, - "noempty": true, "nonew": true, - "quotmark": "single", - "regexp": false, "undef": true, "unused": true, - "strict": false, - "trailing": true, - "laxbreak": true, - "smarttabs": true, - "multistr": true, - - "browser": true, - - "nomen": true, - "onevar": true + // Environment + "browser": true } diff --git a/Gruntfile.js b/Gruntfile.js index 9c56558..5784898 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,9 +1,20 @@ /*jshint node:true */ module.exports = function ( grunt ) { grunt.loadNpmTasks( 'grunt-banana-checker' ); + grunt.loadNpmTasks( 'grunt-contrib-jshint' ); + grunt.loadNpmTasks( 'grunt-jscs' ); grunt.loadNpmTasks( 'grunt-jsonlint' ); grunt.initConfig( { + jshint: { + options: { + jshintrc: true + }, + all: [ '*.js', 'modules/**/*.js' ] + }, + jscs: { + all: [ '*.js', 'modules/**/*.js' ] + }, banana: { all: 'i18n/' }, @@ -15,6 +26,6 @@ } } ); - grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] ); + grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'banana' ] ); grunt.registerTask( 'default', 'test' ); }; diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js index 0c4c1eb..ba30dab 100644 --- a/modules/ext.navigationTiming.js +++ b/modules/ext.navigationTiming.js @@ -1,4 +1,4 @@ -/** +/*! * JavaScript module for logging client-side latency measurements. * @see https://mediawiki.org/wiki/Extension:NavigationTiming * @@ -27,18 +27,20 @@ function isCompliant() { // Tests derived from <http://w3c-test.org/web-platform-tests/ // master/navigation-timing/test_timing_attributes_order.html> - var attr, current, last = 0, order = [ - 'loadEventEnd', - 'loadEventStart', - 'domContentLoadedEventEnd', - 'domContentLoadedEventStart', - 'domInteractive', - 'responseEnd', - 'responseStart', - 'requestStart', - 'connectEnd', - 'connectStart' - ]; + var attr, current, + last = 0, + order = [ + 'loadEventEnd', + 'loadEventStart', + 'domContentLoadedEventEnd', + 'domContentLoadedEventStart', + 'domInteractive', + 'responseEnd', + 'responseStart', + 'requestStart', + 'connectEnd', + 'connectStart' + ]; if ( !timing || !performance ) { // Browser does not implement the Navigation Timing API. @@ -52,7 +54,7 @@ } while ( ( attr = order.pop() ) !== undefined ) { - current = timing[attr]; + current = timing[ attr ]; if ( current < 0 || current < last ) { return false; } @@ -64,7 +66,7 @@ function getPaintTiming() { var firstPaint, relativeTo; - if ( $.isPlainObject( window.chrome ) && $.isFunction( chrome.loadTimes ) ) { + if ( window.chrome && $.isFunction( chrome.loadTimes ) ) { // Chrome firstPaint = chrome.loadTimes().firstPaintTime * 1000; relativeTo = chrome.loadTimes().startLoadTime * 1000; @@ -106,7 +108,7 @@ 'responseStart', 'secureConnectionStart' ], function ( i, marker ) { - var measure = timing[marker] - navStart; + var measure = timing[ marker ] - navStart; if ( $.isNumeric( measure ) && measure > 0 ) { timingData[ marker ] = measure; } @@ -125,7 +127,6 @@ return timingData; } - function emitNavigationTiming() { var mediaWikiLoadEnd = mw.now ? mw.now() : new Date().getTime(), @@ -147,12 +148,12 @@ } if ( window.Geo ) { - if ( typeof window.Geo.country === 'string' ) { - event.originCountry = window.Geo.country; + if ( typeof Geo.country === 'string' ) { + event.originCountry = Geo.country; } - if ( typeof window.Geo.region === 'string' ) { - event.originRegion = window.Geo.region; + if ( typeof Geo.region === 'string' ) { + event.originRegion = Geo.region; } } @@ -196,4 +197,4 @@ } ); } ); -} ( mediaWiki, jQuery ) ); +}( mediaWiki, jQuery ) ); diff --git a/package.json b/package.json index 76e8a82..1fe6198 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ }, "devDependencies": { "grunt": "0.4.5", - "grunt-cli": "0.1.13", "grunt-banana-checker": "0.2.2", + "grunt-cli": "0.1.13", + "grunt-contrib-jshint": "0.11.2", + "grunt-jscs": "2.1.0", "grunt-jsonlint": "1.0.4" } } -- To view, visit https://gerrit.wikimedia.org/r/236836 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I721864fb6b50cc0fe0752da561950d03c2c77ae1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/NavigationTiming Gerrit-Branch: wmf/1.26wmf21 Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits