From fe3165faff156f9699847aa831cfbe9515f75d29 Mon Sep 17 00:00:00 2001 From: Thalia Date: Mon, 14 Sep 2015 19:46:13 +0100 Subject: [PATCH] build: Add csshint, jshint and jscs to math extension Also adds the corrections made to various js files when jscs was run, and removes an old version of .jshintrc. Only VisualEditor files are checked by csshint due to clashes with an upstream bug in the csslint parser. This could be looked into in the future. Bug: T112576 Change-Id: I611901040d3b38ae3ef707deb8d25771f043b1d8 --- .csslintrc | 13 ++++++ .jscsrc | 21 ++++++++++ .jshintrc | 25 ++++++++++++ Gruntfile.js | 40 ++++++++++++++++++- modules/.jshintrc | 31 -------------- modules/VisualEditor/ve.ce.MWMathNode.js | 2 +- modules/VisualEditor/ve.ui.MWMathInspector.js | 32 ++++++++------- .../VisualEditor/ve.ui.MWMathInspectorTool.js | 2 +- modules/ext.math.editbutton.js | 3 +- modules/ext.math.js | 16 ++++---- package.json | 6 ++- 11 files changed, 133 insertions(+), 58 deletions(-) create mode 100644 .csslintrc create mode 100644 .jscsrc create mode 100644 .jshintrc delete mode 100644 modules/.jshintrc diff --git a/.csslintrc b/.csslintrc new file mode 100644 index 0000000..68d60d2 --- /dev/null +++ b/.csslintrc @@ -0,0 +1,13 @@ +{ + "adjoining-classes": false, + "box-model": false, + "box-sizing": false, + "fallback-colors": false, + "important": false, + "outline-none": false, + "qualified-headings": false, + "unique-headings": false, + "universal-selector": false, + "unqualified-attributes": false, + "gradients": false +} diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..1959eea --- /dev/null +++ b/.jscsrc @@ -0,0 +1,21 @@ +{ + "preset": "wikimedia", + + "jsDoc": { + "checkAnnotations": { + "preset": "jsduck5", + "extra": { + "this": true, + "source": true, + "see": true + } + }, + "checkTypes": "strictNativeCase", + "checkParamNames": true, + "checkRedundantAccess": true, + "checkRedundantReturns": true, + "requireNewlineAfterDescription": true, + "requireParamTypes": true, + "requireReturnTypes": true + } +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..b0a9b23 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,25 @@ +{ + // Enforcing + "bitwise": true, + "eqeqeq": true, + "freeze": true, + "latedef": true, + "noarg": true, + "nonew": true, + "undef": true, + "unused": true, + "strict": false, + + // Relaxing + "es5": false, + + // Environment + "browser": true, + "jquery": true, + + "globals": { + "mediaWiki": false, + "OO": false, + "ve": false + } +} diff --git a/Gruntfile.js b/Gruntfile.js index 9c56558..efe32d6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,6 +2,10 @@ module.exports = function ( grunt ) { grunt.loadNpmTasks( 'grunt-banana-checker' ); grunt.loadNpmTasks( 'grunt-jsonlint' ); + grunt.loadNpmTasks( 'grunt-contrib-csslint' ); + grunt.loadNpmTasks( 'grunt-contrib-jshint' ); + grunt.loadNpmTasks( 'grunt-contrib-watch' ); + grunt.loadNpmTasks( 'grunt-jscs' ); grunt.initConfig( { banana: { @@ -12,9 +16,43 @@ module.exports = function ( grunt ) { '**/*.json', '!node_modules/**' ] + }, + csslint: { + options: { + csslintrc: '.csslintrc' + }, + all: 'modules/VisualEditor/*.css' + }, + jshint: { + options: { + jshintrc: true + }, + all: [ + '*.js', + 'modules/**/*.js' + ] + }, + watch: { + files: [ + '.{csslintrc,jscsrc,jshintignore,jshintrc}', + '<%= jshint.all %>', + '<%= csslint.all %>' + ], + tasks: 'test' + }, + jscs: { + fix: { + options: { + fix: true + }, + src: '<%= jshint.all %>' + }, + main: { + src: '<%= jshint.all %>' + } } } ); - grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] ); + grunt.registerTask( 'test', [ 'jshint', 'jscs:main', 'csslint', 'jsonlint', 'banana' ] ); grunt.registerTask( 'default', 'test' ); }; diff --git a/modules/.jshintrc b/modules/.jshintrc deleted file mode 100644 index df12825..0000000 --- a/modules/.jshintrc +++ /dev/null @@ -1,31 +0,0 @@ -{ - "predef": [ - "mediaWiki", - "jQuery" - ], - - "bitwise": true, - "camelcase": true, - "curly": true, - "eqeqeq": true, - "forin": false, - "immed": true, - "latedef": true, - "newcap": true, - "noarg": true, - "noempty": true, - "nonew": true, - "quotmark": "single", - "regexp": false, - "undef": true, - "unused": true, - "strict": false, - "trailing": true, - - "smarttabs": true, - - "browser": true, - - "nomen": true, - "onevar": true -} diff --git a/modules/VisualEditor/ve.ce.MWMathNode.js b/modules/VisualEditor/ve.ce.MWMathNode.js index aa523a9..bf62660 100644 --- a/modules/VisualEditor/ve.ce.MWMathNode.js +++ b/modules/VisualEditor/ve.ce.MWMathNode.js @@ -53,7 +53,7 @@ ve.ce.MWMathNode.prototype.afterRender = function () { if ( this.$element.is( 'span.tex' ) ) { // MathJax MathJax.Hub.Queue( - [ 'Typeset', MathJax.Hub, this.$element[0] ], + [ 'Typeset', MathJax.Hub, this.$element[ 0 ] ], [ this, this.emit, 'rerender' ] ); } else { diff --git a/modules/VisualEditor/ve.ui.MWMathInspector.js b/modules/VisualEditor/ve.ui.MWMathInspector.js index d00644e..12d1ec0 100644 --- a/modules/VisualEditor/ve.ui.MWMathInspector.js +++ b/modules/VisualEditor/ve.ui.MWMathInspector.js @@ -45,6 +45,8 @@ ve.ui.MWMathInspector.static.dir = 'ltr'; * @inheritdoc */ ve.ui.MWMathInspector.prototype.initialize = function () { + var inputField, displayField, idField; + // Parent method ve.ui.MWMathInspector.super.prototype.initialize.call( this ); @@ -71,18 +73,18 @@ ve.ui.MWMathInspector.prototype.initialize = function () { this.idInput = new OO.ui.TextInputWidget(); - var inputField = new OO.ui.FieldLayout( this.input, { - align: 'top', - label: ve.msg( 'math-visualeditor-mwmathinspector-title' ) - } ), - displayField = new OO.ui.FieldLayout( this.displaySelect, { - align: 'top', - label: ve.msg( 'math-visualeditor-mwmathinspector-display' ) - } ), - idField = new OO.ui.FieldLayout( this.idInput, { - align: 'top', - label: ve.msg( 'math-visualeditor-mwmathinspector-id' ) - } ); + inputField = new OO.ui.FieldLayout( this.input, { + align: 'top', + label: ve.msg( 'math-visualeditor-mwmathinspector-title' ) + } ); + displayField = new OO.ui.FieldLayout( this.displaySelect, { + align: 'top', + label: ve.msg( 'math-visualeditor-mwmathinspector-display' ) + } ); + idField = new OO.ui.FieldLayout( this.idInput, { + align: 'top', + label: ve.msg( 'math-visualeditor-mwmathinspector-id' ) + } ); // Initialization this.$content.addClass( 've-ui-mwMathInspector-content' ); @@ -117,11 +119,13 @@ ve.ui.MWMathInspector.prototype.getTeardownProcess = function ( data ) { * @inheritdoc */ ve.ui.MWMathInspector.prototype.updateMwData = function ( mwData ) { + var display, id; + // Parent method ve.ui.MWMathInspector.super.prototype.updateMwData.call( this, mwData ); - var display = this.displaySelect.getSelectedItem().getData(), - id = this.idInput.getValue(); + display = this.displaySelect.getSelectedItem().getData(); + id = this.idInput.getValue(); mwData.attrs.display = display !== 'default' ? display : undefined; mwData.attrs.id = id || undefined; diff --git a/modules/VisualEditor/ve.ui.MWMathInspectorTool.js b/modules/VisualEditor/ve.ui.MWMathInspectorTool.js index 0280fe7..f70ec7d 100644 --- a/modules/VisualEditor/ve.ui.MWMathInspectorTool.js +++ b/modules/VisualEditor/ve.ui.MWMathInspectorTool.js @@ -32,6 +32,6 @@ ve.ui.toolFactory.register( ve.ui.MWMathInspectorTool ); ve.ui.commandRegistry.register( new ve.ui.Command( 'math', 'window', 'open', - { args: ['math'], supportedSelections: ['linear'] } + { args: [ 'math' ], supportedSelections: [ 'linear' ] } ) ); diff --git a/modules/ext.math.editbutton.js b/modules/ext.math.editbutton.js index c2742d5..2db5b38 100644 --- a/modules/ext.math.editbutton.js +++ b/modules/ext.math.editbutton.js @@ -1,6 +1,7 @@ ( function ( mw ) { + var iconPath; if ( mw.toolbar ) { - var iconPath = mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/images/'; + iconPath = mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/images/'; mw.toolbar.addButton( { imageFile: iconPath + 'button_math.png', speedTip: mw.msg( 'math_tip' ), diff --git a/modules/ext.math.js b/modules/ext.math.js index bf4b326..085260d 100644 --- a/modules/ext.math.js +++ b/modules/ext.math.js @@ -3,7 +3,7 @@ var img, url; // If MathPlayer is installed we show the MathML rendering. - if (navigator.userAgent.indexOf('MathPlayer') > -1) { + if ( navigator.userAgent.indexOf( 'MathPlayer' ) > -1 ) { $( '.mwe-math-mathml-a11y' ).removeClass( 'mwe-math-mathml-a11y' ); $( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).css( 'display', 'none' ); return; @@ -11,18 +11,18 @@ // We verify whether SVG as is supported and otherwise use the // PNG fallback. See https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js - if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1')) { - $( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).each(function() { + if ( !document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) { + $( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).each( function () { // Create a new PNG image to use as the fallback. - img = document.createElement('img'); - url = this.style.backgroundImage.match(/url\('?([^']*)'?\)/)[1]; - img.setAttribute( 'src', url.replace('mode=' + 'mathml', 'mode=' + 'png') ); - img.setAttribute( 'class', 'tex mwe-math-fallback-image-' + ($( this ).hasClass('mwe-math-fallback-image-inline') ? 'inline' : 'display') ); + img = document.createElement( 'img' ); + url = this.style.backgroundImage.match( /url\('?([^']*)'?\)/ )[ 1 ]; + img.setAttribute( 'src', url.replace( 'mode=' + 'mathml', 'mode=' + 'png' ) ); + img.setAttribute( 'class', 'tex mwe-math-fallback-image-' + ( $( this ).hasClass( 'mwe-math-fallback-image-inline' ) ? 'inline' : 'display' ) ); img.setAttribute( 'aria-hidden', 'true' ); this.parentNode.insertBefore( img, this ); // Hide the SVG fallback. $( this ).css( 'display', 'none' ); - }); + } ); } }( jQuery ) ); diff --git a/package.json b/package.json index 76e8a82..a01e7aa 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,10 @@ "grunt": "0.4.5", "grunt-cli": "0.1.13", "grunt-banana-checker": "0.2.2", - "grunt-jsonlint": "1.0.4" + "grunt-jsonlint": "1.0.4", + "grunt-contrib-csslint": "0.5.0", + "grunt-contrib-jshint": "0.11.3", + "grunt-contrib-watch": "0.6.1", + "grunt-jscs": "2.1.0" } }