jenkins-bot has submitted this change and it was merged. Change subject: Add jshint and jscs to npm, Also add composer.json ......................................................................
Add jshint and jscs to npm, Also add composer.json Instead of running the jshint test through jenkins, Run it through npm instead. Also add composer.json for running php code sniffer and phplint instead of running phplint through jenkins. Also update grunt-jsonlint to 1.0.6 Change-Id: Icd9aa1b1c7213d056aa5294a804341053141b0bd --- M .gitignore A .jscsrc M .jshintignore M .jshintrc M CodeEditor.hooks.php M CodeEditor.php M Gruntfile.js A composer.json M modules/ext.codeEditor.geshi.js M modules/jquery.codeEditor.js M package.json A phpcs.xml 12 files changed, 111 insertions(+), 60 deletions(-) Approvals: TheDJ: Looks good to me, approved jenkins-bot: Verified diff --git a/.gitignore b/.gitignore index 4bf4869..a8e1003 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -.svn *~ *.kate-swp .*.swp node_modules/ +vendor/ +ace-git/ diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..9d22e3f --- /dev/null +++ b/.jscsrc @@ -0,0 +1,3 @@ +{ + "preset": "wikimedia" +} diff --git a/.jshintignore b/.jshintignore index 5852122..a2a8282 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1,2 +1,5 @@ +node_modules/ +vendor/ + # 3rd party lib modules/ace/ diff --git a/.jshintrc b/.jshintrc index ea82e8f..14b3446 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,25 +1,30 @@ { -/* Common */ + // Enforcing + "bitwise": true, + "curly": true, + "eqeqeq": true, + "freeze": true, + "latedef": true, + "immed": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonew": true, + "quotmark": "single", + "strict": false, + "trailing": true, + "undef": true, + "unused": true, -// Enforcing -"camelcase": true, -"curly": true, -"eqeqeq": true, -"immed": true, -"latedef": true, -"newcap": true, -"noarg": true, -"noempty": true, -"nonew": true, -"quotmark": "single", -"trailing": true, -"undef": true, -"unused": true, + // Relaxing + "es5": false, -"jquery": true, -"browser": true, + // Environment + "browser": true, + "jquery": true, -"predef": [ - "mediaWiki" -] + "globals": { + "mediaWiki": false, + "OO": false + } } diff --git a/CodeEditor.hooks.php b/CodeEditor.hooks.php index 6efb998..d535be2 100644 --- a/CodeEditor.hooks.php +++ b/CodeEditor.hooks.php @@ -14,10 +14,12 @@ } } elseif ( $wgCodeEditorEnableCore && ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) ) { // This block is deprecated. Remove after 1.23 release - if( preg_match( '/\.js$/', $title->getText() ) ) + if ( preg_match( '/\.js$/', $title->getText() ) ) { return 'javascript'; - if( preg_match( '/\.css$/', $title->getText() ) ) + } + if ( preg_match( '/\.css$/', $title->getText() ) ) { return 'css'; + } } // Give extensions a chance @@ -46,7 +48,7 @@ public static function onMakeGlobalVariablesScript( &$vars, $output ) { $lang = self::getPageLanguage( $output->getTitle() ); - if( $lang ) { + if ( $lang ) { $vars['wgCodeEditorCurrentLanguage'] = $lang; } return true; diff --git a/CodeEditor.php b/CodeEditor.php index ea9a1f9..3cbcc1d 100644 --- a/CodeEditor.php +++ b/CodeEditor.php @@ -11,7 +11,8 @@ */ /** - * This PHP entry point is deprecated. Please use wfLoadExtension() and the extension.json file instead. + * This PHP entry point is deprecated. + * Please use wfLoadExtension() and the extension.json file instead. * See https://www.mediawiki.org/wiki/Manual:Extension_registration for more details. */ @@ -20,7 +21,8 @@ // Keep i18n globals so mergeMessageFileList.php doesn't break $wgMessagesDirs['CodeEditor'] = __DIR__ . '/i18n'; /* wfWarn( - 'Deprecated PHP entry point used for CodeEditor extension. Please use wfLoadExtension instead, ' . + 'Deprecated PHP entry point used for CodeEditor extension. ' . + 'Please use wfLoadExtension instead, ' . 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' ); */ return; diff --git a/Gruntfile.js b/Gruntfile.js index 29dd566..fa82e5d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -6,11 +6,26 @@ /*jshint node:true */ module.exports = function ( grunt ) { - grunt.loadNpmTasks( 'grunt-banana-checker' ); - grunt.loadNpmTasks( 'grunt-jsonlint' ); - var conf = grunt.file.readJSON( 'extension.json' ); + grunt.loadNpmTasks( 'grunt-contrib-jshint' ); + grunt.loadNpmTasks( 'grunt-jsonlint' ); + grunt.loadNpmTasks( 'grunt-banana-checker' ); + grunt.loadNpmTasks( 'grunt-jscs' ); + grunt.initConfig( { + jshint: { + options: { + jshintrc: true + }, + all: [ + '**/*.js', + '!node_modules/**', + '!modules/ace/**' + ] + }, + jscs: { + src: '<%= jshint.all %>' + }, banana: conf.MessagesDirs, jsonlint: { all: [ @@ -20,6 +35,6 @@ } } ); - grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] ); + grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'banana' ] ); grunt.registerTask( 'default', 'test' ); }; diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..99741dd --- /dev/null +++ b/composer.json @@ -0,0 +1,12 @@ +{ + "require-dev": { + "jakub-onderka/php-parallel-lint": "0.9", + "mediawiki/mediawiki-codesniffer": "0.5.0" + }, + "scripts": { + "test": [ + "parallel-lint . --exclude vendor", + "phpcs -p -s" + ] + } +} diff --git a/modules/ext.codeEditor.geshi.js b/modules/ext.codeEditor.geshi.js index 86a4884..fbd1346 100644 --- a/modules/ext.codeEditor.geshi.js +++ b/modules/ext.codeEditor.geshi.js @@ -39,7 +39,7 @@ matches = /(?:^| )source-([a-z0-9_-]+)/.exec( $main.attr( 'class' ) ); if ( matches ) { - geshiLang = matches[1]; + geshiLang = matches[ 1 ]; } mw.loader.using( 'ext.codeEditor.ace.modes', function () { var map, $container, $save, $cancel, $controls, setLanguage, closeEditor; @@ -125,12 +125,12 @@ $div.hide(); $xcontainer.insertAfter( $div ); - codeEditor = ace.edit( $container[0] ); + codeEditor = ace.edit( $container[ 0 ] ); setLanguage = function ( lang ) { - geshiLang = lang; - var aceLang = map[geshiLang], + var aceLang = map[ lang ], AceLangMode = require( 'ace/mode/' + aceLang ).Mode; + geshiLang = lang; codeEditor.getSession().setMode( new AceLangMode() ); }; setLanguage( geshiLang ); diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js index 0ee5c3f..1e2054d 100644 --- a/modules/jquery.codeEditor.js +++ b/modules/jquery.codeEditor.js @@ -10,10 +10,10 @@ * Compatability map */ browsers: { - msie: [['>=', 8]], - ipod: [['>=', 6]], - iphone: [['>=', 6]], - android: [['>=', 4]] + msie: [ [ '>=', 8 ] ], + ipod: [ [ '>=', 6 ] ], + iphone: [ [ '>=', 6 ] ], + android: [ [ '>=', 4 ] ] }, /** * Configuration @@ -84,7 +84,7 @@ var i, annotations = context.codeEditor.getSession().getAnnotations(); for ( i = 0; i < annotations.length; i++ ) { - if ( annotations[i].type === 'error' ) { + if ( annotations[ i ].type === 'error' ) { hasErrorsOnSave = true; break; } @@ -124,11 +124,11 @@ column = 0; if ( matches.length > 0 ) { - line = parseInt( matches[0], 10 ) || 0; + line = parseInt( matches[ 0 ], 10 ) || 0; line--; } if ( matches.length > 1 ) { - column = parseInt( matches[1], 10 ) || 0; + column = parseInt( matches[ 1 ], 10 ) || 0; column--; } context.codeEditor.navigateTo( line, column ); @@ -341,7 +341,7 @@ ace.require( 'ace/ext/language_tools' ); // Load the editor now - context.codeEditor = ace.edit( editdiv[0] ); + context.codeEditor = ace.edit( editdiv[ 0 ] ); context.codeEditor.getSession().setValue( box.val() ); box.textSelection( 'register', textSelectionFn ); @@ -453,7 +453,7 @@ return; } - selectedLine = parseInt( result[1], 10 ); + selectedLine = parseInt( result[ 1 ], 10 ); if ( context.codeEditor && selectedLine > 0 ) { // Line numbers in CodeEditor are zero-based context.codeEditor.navigateTo( selectedLine - 1, 0 ); @@ -524,7 +524,7 @@ nextAnnotation = null; for ( i = 0; i < annotations.length; i++ ) { - annotation = annotations[i]; + annotation = annotations[ i ]; distance = Math.abs( currentLine - annotation.row ); if ( distance < shortestDistance ) { @@ -535,7 +535,7 @@ nextAnnotation = annotation; } - switch ( annotations[i].type ) { + switch ( annotations[ i ].type ) { case 'error': errors++; break; @@ -549,7 +549,7 @@ } // Wrap around to the beginning for nextAnnotation if ( nextAnnotation === null && annotations.length > 0 ) { - nextAnnotation = annotations[0]; + nextAnnotation = annotations[ 0 ]; } // Update the annotation counts if ( shouldUpdateAnnotations ) { @@ -660,14 +660,15 @@ for ( key in extended ) { if ( obj.hasOwnProperty( key ) ) { - callback( obj[key], key ); + callback( obj[ key ], key ); } } }; map( extended, function ( func, name ) { + var orig; if ( name in base ) { - var orig = base[name]; - base[name] = function () { + orig = base[ name ]; + base[ name ] = function () { if ( context.codeEditorActive ) { return func.apply( this, arguments ); } @@ -677,7 +678,7 @@ throw new Error( 'CodeEditor: no original function to call for ' + name ); }; } else { - base[name] = func; + base[ name ] = func; } } ); }; @@ -700,9 +701,6 @@ /** * Scroll an element to the top of the iframe - * - * @param $element jQuery object containing an element in the iframe - * @param force If true, scroll the element even if it's already visible */ scrollToTop: function () { mw.log( 'codeEditor stub function scrollToTop called' ); @@ -731,6 +729,7 @@ getSelection: function () { return context.codeEditor.getCopyText(); }, + /** * Inserts text at the begining and end of a text selection, optionally inserting text at the caret when * selection is empty. @@ -764,6 +763,7 @@ } return context.$textarea; }, + /** * Gets the position (in resolution of bytes not nessecarily characters) in a textarea * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead @@ -771,14 +771,12 @@ getCaretPosition: function () { mw.log( 'codeEditor stub function getCaretPosition called' ); }, + /** * Sets the selection of the content * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead * - * @param start Character offset of selection start - * @param end Character offset of selection end - * @param startContainer Element in iframe to start selection in. If not set, start is a character offset - * @param endContainer Element in iframe to end selection in. If not set, end is a character offset + * @param {Object} options */ setSelection: function ( options ) { var doc, lines, offsetToPos, start, end, sel, range; @@ -795,8 +793,8 @@ col = 0; pos = 0; - while ( row < lines.length && pos + lines[row].length < offset ) { - pos += lines[row].length; + while ( row < lines.length && pos + lines[ row ].length < offset ) { + pos += lines[ row ].length; pos++; // for the newline row++; } diff --git a/package.json b/package.json index 7729fa3..642e7a3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,9 @@ "devDependencies": { "grunt": "0.4.5", "grunt-cli": "0.1.13", + "grunt-contrib-jshint": "0.11.3", "grunt-banana-checker": "0.4.0", - "grunt-jsonlint": "1.0.4" + "grunt-jscs": "2.3.0", + "grunt-jsonlint": "1.0.6" } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..d81a292 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<ruleset> + <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/> + <file>.</file> + <arg name="extensions" value="php,php5,inc"/> + <arg name="encoding" value="utf8"/> + <exclude-pattern>vendor</exclude-pattern> +</ruleset> -- To view, visit https://gerrit.wikimedia.org/r/248684 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icd9aa1b1c7213d056aa5294a804341053141b0bd Gerrit-PatchSet: 18 Gerrit-Project: mediawiki/extensions/CodeEditor Gerrit-Branch: master Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Fomafix Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: TheDJ <hartman.w...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits