Add a grunt checker for jshint, jscs, csslint, and banana and pass them

There was a pre-existing jshint config (.jshintrc) file that this upgrades based
on the equivalent files for VisualEditor and OOjs UI.

Change-Id: I3ecb0e65cc7ff090b7457be895917fbd8b8afd18
This commit is contained in:
James D. Forrester 2014-06-03 19:34:04 -07:00
parent 13095937af
commit 64a39ae460
11 changed files with 208 additions and 29 deletions

11
.csslintrc Normal file
View file

@ -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
}

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
*~
*.kate-swp
.*.swp
node_modules

97
.jscsrc Normal file
View file

@ -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
}

1
.jshintignore Normal file
View file

@ -0,0 +1 @@
node_modules

View file

@ -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
}
}

53
Gruntfile.js Normal file
View file

@ -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' );
};

View file

@ -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 );
}

View file

@ -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%;
}

View file

@ -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 );
} );
} );

25
package.json Normal file
View file

@ -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"
}
}

View file

@ -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': $( '<input>' ).val( 'user' ),
'label': $( '<input>' ).val( 'changed to another label' ),
'label': $( '<input>' ).val( 'changed to another label' )
}
};
@ -191,7 +190,7 @@
$modalDomElements = {
'user': {
'name': $( '<input>' ).val( 'anotherName' ),
'label': $( '<input>' ).val( 'changed to another label' ),
'label': $( '<input>' ).val( 'changed to another label' )
}
};