diff --git a/Gruntfile.js b/Gruntfile.js index fe47eae3..d90effbe 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,6 +16,9 @@ module.exports = function ( grunt ) { grunt.initConfig( { eslint: { + options: { + reportUnusedDisableDirectives: true + }, all: [ 'modules/**/*.js', 'tests/**/*.js' diff --git a/modules/ext.templateDataGenerator.data.js b/modules/ext.templateDataGenerator.data.js index a564ec36..1a22f201 100644 --- a/modules/ext.templateDataGenerator.data.js +++ b/modules/ext.templateDataGenerator.data.js @@ -72,7 +72,7 @@ mw.TemplateData.Model.static.compare = function ( obj1, obj2, allowSubset ) { } // Make sure the objects are of the same type - if ( $.type( obj1 ) !== $.type( obj2 ) ) { + if ( typeof obj1 !== typeof obj2 ) { return false; } @@ -153,9 +153,9 @@ mw.TemplateData.Model.static.getAllProperties = function ( getFullData ) { 'url', 'wiki-user-name' ], - 'default': 'unknown' + default: 'unknown' }, - 'default': { + default: { type: 'string', multiline: true, allowLanguages: true @@ -351,20 +351,13 @@ mw.TemplateData.Model.prototype.importSourceCodeParameters = function () { * @return {string[]} Language codes in use */ mw.TemplateData.Model.prototype.getExistingLanguageCodes = function () { - var param, prop, lang, + var param, prop, result = [], languageProps = this.constructor.static.getPropertiesWithLanguage(); // Take languages from the template description if ( $.isPlainObject( this.description ) ) { - result.concat( Object.keys( this.description ) ); - } - - // Go over description - if ( $.type( this.description ) ) { - for ( lang in this.description ) { - result.push( lang ); - } + result = Object.keys( this.description ); } // Go over the parameters @@ -422,7 +415,7 @@ mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) { } // Get the deprecated value - if ( $.type( data.deprecated ) === 'string' ) { + if ( typeof data.deprecated === 'string' ) { this.params[ key ].deprecatedValue = data.deprecated; } @@ -442,7 +435,7 @@ mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) { propToSet = allProps[ prop ].textValue; // Set the boolean value in the current property this.setParamProperty( key, prop, !!data[ prop ], language ); - if ( $.type( data[ prop ] ) === 'boolean' ) { + if ( typeof data[ prop ] === 'boolean' ) { // Only set the value of the dependent if the value is a string or // language. Otherwise, if the value is boolean, keep the dependent // empty. @@ -496,7 +489,7 @@ mw.TemplateData.Model.prototype.getAllParamNames = function () { /** * Set the template description * - * @param {string} desc New template description + * @param {string|Object} desc New template description * @param {Object} [language] Description language, if supplied. If not given, * will default to the wiki language. * @fires change-description @@ -506,7 +499,7 @@ mw.TemplateData.Model.prototype.setTemplateDescription = function ( desc, langua language = language || this.getDefaultLanguage(); if ( !this.constructor.static.compare( this.description[ language ], desc ) ) { - if ( $.type( desc ) === 'object' ) { + if ( typeof desc === 'object' ) { $.extend( this.description, desc ); this.emit( 'change-description', desc[ language ], language ); } else { @@ -678,7 +671,7 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va return status; } - if ( allProps[ prop ].type === 'array' && $.type( value ) === 'string' ) { + if ( allProps[ prop ].type === 'array' && typeof value === 'string' ) { // When we split the string, we want to use a trimmed delimiter value = this.constructor.static.splitAndTrimArray( value, allProps[ prop ].delimiter.trim() ); } @@ -1007,7 +1000,7 @@ mw.TemplateData.Model.prototype.outputTemplateData = function () { // Only update the aliases in if the new templatedata has an // aliases array that isn't empty if ( - $.type( this.params[ key ][ prop ] ) === 'array' && + Array.isArray( this.params[ key ][ prop ] ) && this.params[ key ][ prop ].length > 0 ) { result.params[ name ][ prop ] = this.params[ key ][ prop ]; @@ -1081,21 +1074,21 @@ mw.TemplateData.Model.prototype.propRemoveUnusedLanguages = function ( propData * Check whether the output of the current parameter property should be * outputted in full language mode (object) or a simple string. * - * @param {string} originalPropValue Original property value - * @param {string} newPropValue New property value + * @param {string|Object} originalPropValue Original property value + * @param {string|Object} newPropValue New property value * @return {boolean} Output should be a full language object */ mw.TemplateData.Model.prototype.isOutputInLanguageObject = function ( originalPropValue, newPropValue ) { if ( ( // The original was already split to languages - $.type( originalPropValue ) === 'object' && + typeof originalPropValue === 'object' && // Original was not an empty object !$.isEmptyObject( originalPropValue ) ) || ( // The new value is split to languages - $.type( newPropValue ) === 'object' && + typeof newPropValue === 'object' && // New object is not empty !$.isEmptyObject( newPropValue ) && ( diff --git a/modules/ext.templateDataGenerator.editTemplatePage.js b/modules/ext.templateDataGenerator.editTemplatePage.js index 244e896d..f5e09626 100644 --- a/modules/ext.templateDataGenerator.editTemplatePage.js +++ b/modules/ext.templateDataGenerator.editTemplatePage.js @@ -6,6 +6,7 @@ */ /* global ve */ +/* eslint-disable jquery/no-global-selector */ $( function () { 'use strict'; diff --git a/modules/ext.templateDataGenerator.target.js b/modules/ext.templateDataGenerator.target.js index b1007825..9d28ecd7 100644 --- a/modules/ext.templateDataGenerator.target.js +++ b/modules/ext.templateDataGenerator.target.js @@ -44,7 +44,7 @@ mw.TemplateData.Target = function mwTemplateDataTarget( $textarea, config ) { .text( mw.msg( 'templatedata-helplink' ) ); this.windowManager = new OO.ui.WindowManager(); - $( 'body' ).append( this.windowManager.$element ); + $( document.body ).append( this.windowManager.$element ); // Dialog this.tdgDialog = new mw.TemplateData.Dialog( config ); diff --git a/modules/ext.templateDataGenerator.ui.tdDialog.js b/modules/ext.templateDataGenerator.ui.tdDialog.js index 27159809..4bdda454 100644 --- a/modules/ext.templateDataGenerator.ui.tdDialog.js +++ b/modules/ext.templateDataGenerator.ui.tdDialog.js @@ -552,6 +552,8 @@ mw.TemplateData.Dialog.prototype.onParamPropertyInputChange = function ( propert } // Validate + // FIXME: Don't read model information from the DOM + // eslint-disable-next-line jquery/no-global-selector anyInputError = !!$( '.tdg-templateDataDialog-paramInput.tdg-editscreen-input-error' ).length; // Disable the 'done' button if there are any errors in the inputs @@ -662,7 +664,7 @@ mw.TemplateData.Dialog.prototype.changeParamPropertyInput = function ( paramKey, if ( languageProps.indexOf( propName ) !== -1 ) { propInput.setValue( value[ lang ] ); } else { - if ( prop.type === 'array' && $.type( value ) === 'array' ) { + if ( prop.type === 'array' && Array.isArray( value ) ) { value = value.join( prop.delimiter ); } propInput.setValue( value ); diff --git a/package.json b/package.json index 5e3a71f4..5851ddc3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "doc": "jsduck" }, "devDependencies": { - "eslint-config-wikimedia": "0.9.0", + "eslint-config-wikimedia": "0.10.1", "grunt": "1.0.3", "grunt-banana-checker": "0.6.0", "grunt-contrib-watch": "1.1.0", diff --git a/tests/qunit/ext.templateData.tests.js b/tests/qunit/ext.templateData.tests.js index 28d2511e..069feead 100644 --- a/tests/qunit/ext.templateData.tests.js +++ b/tests/qunit/ext.templateData.tests.js @@ -153,12 +153,6 @@ QUnit.test( 'Validation tools', function ( assert ) { var tests = { compare: [ - { - obj1: {}, - obj2: [], - result: false, - msg: 'Compare: object vs array' - }, { obj1: null, obj2: undefined,