diff --git a/.csslintrc b/.csslintrc new file mode 100644 index 00000000..e777c7f3 --- /dev/null +++ b/.csslintrc @@ -0,0 +1,11 @@ +{ + "adjoining-classes": false, + "box-model": false, + "box-sizing": false, + "fallback-colors": false, + "important": false, + "outline-none": false, + "qualified-headings": false, + "universal-selector": false, + "unqualified-attributes": false +} diff --git a/.gitignore b/.gitignore index 98b092a9..25cbfdb7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *~ *.kate-swp .*.swp +node_modules diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 00000000..b1ed9882 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,97 @@ +{ + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "return", + "try", + "catch", + "function" + ], + "requireSpaceBeforeBlockStatements": true, + "requireParenthesesAroundIIFE": true, + "requireSpacesInConditionalExpression": true, + "disallowSpacesInNamedFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInFunctionDeclaration": { + "beforeOpeningRoundBrace": true + }, + "requireMultipleVarDecl": "onevar", + "requireBlocksOnNewline": 1, + "disallowEmptyBlocks": true, + "requireSpacesInsideObjectBrackets": "all", + "disallowDanglingUnderscores": true, + "disallowSpaceAfterObjectKeys": true, + "requireCommaBeforeLineBreak": true, + "disallowSpaceAfterPrefixUnaryOperators": [ + "++", + "--", + "+", + "-", + "~", + "!" + ], + "disallowSpaceBeforePostfixUnaryOperators": [ + "++", + "--" + ], + "disallowSpaceBeforeBinaryOperators": [ + "," + ], + "requireSpaceBeforeBinaryOperators": [ + "=", + "+", + "-", + "/", + "*", + "==", + "===", + "!=", + "!==", + ">", + ">=", + "<", + "<=" + ], + "requireSpaceAfterBinaryOperators": [ + "=", + "+", + "-", + "/", + "*", + "==", + "===", + "!=", + "!==", + ">", + ">=", + "<", + "<=" + ], + "requireCamelCaseOrUpperCaseIdentifiers": true, + "disallowKeywords": [ "with" ], + "disallowMultipleLineBreaks": true, + "validateLineBreaks": "LF", + "validateQuoteMarks": "'", + "disallowMixedSpacesAndTabs": true, + "disallowTrailingWhitespace": true, + "disallowTrailingComma": true, + "disallowKeywordsOnNewLine": ["else"], + "requireLineFeedAtFileEnd": true, + "requireCapitalizedConstructors": true, + "requireDotNotation": true, + "disallowYodaConditions": true +} diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +node_modules diff --git a/.jshintrc b/.jshintrc index c9e9f825..66cf8dda 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,33 +1,24 @@ { - /* Common */ - // Enforcing - "camelcase": true, - "curly": true, + "bitwise": true, "eqeqeq": true, - "immed": true, + "freeze": true, "latedef": true, - "newcap": true, "noarg": true, - "noempty": true, "nonew": true, - "quotmark": "single", - "trailing": true, "undef": true, "unused": true, - // Legacy - "onevar": true, + "strict": false, - /* Local */ + // Relaxing + "es5": false, // Environment "browser": true, - // Legacy - "nomen": true, - "predef": [ - "mediaWiki", - "jQuery", - "QUnit" - ] + "globals": { + "jQuery": false, + "QUnit": false, + "mediaWiki": false + } } diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 00000000..34b9b417 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,53 @@ +/*! + * Grunt file + * + * @package TemplateData + */ + +/*jshint node:true */ +module.exports = function ( grunt ) { + grunt.loadNpmTasks( 'grunt-contrib-csslint' ); + grunt.loadNpmTasks( 'grunt-contrib-jshint' ); + grunt.loadNpmTasks( 'grunt-contrib-watch' ); + grunt.loadNpmTasks( 'grunt-banana-checker' ); + grunt.loadNpmTasks( 'grunt-jscs-checker' ); + + grunt.initConfig( { + pkg: grunt.file.readJSON( 'package.json' ), + jshint: { + options: { + jshintrc: true + }, + all: [ + 'modules/*.js', + 'tests/*.js' + ] + }, + jscs: { + src: '<%= jshint.all %>' + }, + csslint: { + options: { + csslintrc: '.csslintrc' + }, + all: [ + 'modules/*.css', + 'resources/*.css' + ] + }, + banana: { + all: 'i18n/' + }, + watch: { + files: [ + '.{csslintrc,jscsrc,jshintignore,jshintrc}', + '<%= jshint.all %>', + '<%= csslint.all %>' + ], + tasks: 'test' + } + } ); + + grunt.registerTask( 'test', [ 'jshint', 'jscs', 'csslint', 'banana' ] ); + grunt.registerTask( 'default', 'test' ); +}; diff --git a/modules/ext.templateDataGenerator.core.js b/modules/ext.templateDataGenerator.core.js index c7ac7b16..ee3279bf 100644 --- a/modules/ext.templateDataGenerator.core.js +++ b/modules/ext.templateDataGenerator.core.js @@ -600,7 +600,7 @@ function i18nModalButtons( btnApply, btnCancel ) { var modalButtons = {}; - modalButtons[btnApply] = function() { + modalButtons[btnApply] = function () { var finalOutput, newJson = applyChangeToJSON(); @@ -811,7 +811,7 @@ * @private * @inheritDoc #parseTemplateData */ - parseTemplateData: function( wikitext ) { + parseTemplateData: function ( wikitext ) { return parseTemplateData( wikitext ); }, @@ -819,7 +819,7 @@ * @private * @inheritDoc #applyChangesToJSON */ - applyChangesToJSON: function( originalJsonObject, modalDomElements, doNotCheckForm ) { + applyChangesToJSON: function ( originalJsonObject, modalDomElements, doNotCheckForm ) { return applyChangeToJSON( originalJsonObject, modalDomElements, doNotCheckForm ); }, @@ -827,7 +827,7 @@ * @private * @inheritDoc #amendWikitext */ - amendWikitext: function( newJsonObject, originalWikitext ) { + amendWikitext: function ( newJsonObject, originalWikitext ) { return amendWikitext( newJsonObject, originalWikitext ); }, @@ -835,7 +835,7 @@ * @private * @inheritDoc #translateParamToRowDom */ - translateParamToRowDom: function( paramsJson, paramAttrObj ) { + translateParamToRowDom: function ( paramsJson, paramAttrObj ) { return translateParamToRowDom( paramsJson, paramAttrObj ); } diff --git a/modules/ext.templateDataGenerator.css b/modules/ext.templateDataGenerator.css index e3caea71..f3de9280 100644 --- a/modules/ext.templateDataGenerator.css +++ b/modules/ext.templateDataGenerator.css @@ -30,8 +30,9 @@ background: transparent; border: 1px solid #999999; padding: 5px; - box-sizing: border-box; -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; width: 100%; } diff --git a/modules/ext.templateDataGenerator.editPage.js b/modules/ext.templateDataGenerator.editPage.js index b64f874e..76329127 100644 --- a/modules/ext.templateDataGenerator.editPage.js +++ b/modules/ext.templateDataGenerator.editPage.js @@ -32,7 +32,7 @@ $modalBox.dialog( 'open' ); // respond to modal close event - $modalBox.on( 'TemplateDataGeneratorDone', function( e, output ) { + $modalBox.on( 'TemplateDataGeneratorDone', function ( e, output ) { $textbox.val( output ); } ); } ); diff --git a/package.json b/package.json new file mode 100644 index 00000000..e6f633eb --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "templatedata", + "version": "0.0.0", + "scripts": { + "test": "grunt test" + }, + "repository": { + "type": "git", + "url": "https://gerrit.wikimedia.org/r/p/mediawiki/extensions/TemplateData.git" + }, + "licenses": [ + { + "type": "GPL v2+", + "url": "https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FTemplateData.git/master/COPYING" + } + ], + "devDependencies": { + "grunt": "0.4.2", + "grunt-contrib-csslint": "0.2.0", + "grunt-contrib-jshint": "0.10.0", + "grunt-contrib-watch": "0.6.1", + "grunt-banana-checker": "0.1.0", + "grunt-jscs-checker": "0.4.4" + } +} diff --git a/tests/ext.templateData.tests.js b/tests/ext.templateData.tests.js index 59dbf69a..2ddbe926 100644 --- a/tests/ext.templateData.tests.js +++ b/tests/ext.templateData.tests.js @@ -114,7 +114,6 @@ } ); - QUnit.test( 'TemplateData JSON manipulation', 4, function ( assert ) { var $modalDomElements, parsedJson, expectedTextResult, exampleJson, changedParsedJson, reparsedJson, @@ -172,7 +171,7 @@ $modalDomElements = { 'user': { 'name': $( '' ).val( 'user' ), - 'label': $( '' ).val( 'changed to another label' ), + 'label': $( '' ).val( 'changed to another label' ) } }; @@ -191,7 +190,7 @@ $modalDomElements = { 'user': { 'name': $( '' ).val( 'anotherName' ), - 'label': $( '' ).val( 'changed to another label' ), + 'label': $( '' ).val( 'changed to another label' ) } };