Update eslint-config-wikimedia to 0.9.0

Also bump stylelint (no fixes required)

Change-Id: Ia6bd3a8c0392eafb939f9ff05827e1320f56b706
This commit is contained in:
Ed Sanders 2018-11-29 14:19:33 +00:00
parent 64367bfebe
commit 47c3c69baa
6 changed files with 96 additions and 99 deletions

View file

@ -1,12 +1,11 @@
{
"extends": "wikimedia",
"env": {
"browser": true
},
"extends": [
"wikimedia/client",
"wikimedia/jquery"
],
"globals": {
"OO": false,
"mw": false,
"$": false
"mw": false
},
"rules": {
"valid-jsdoc": 0,

View file

@ -217,8 +217,8 @@ mw.TemplateData.Model.static.splitAndTrimArray = function ( str, delim ) {
var arr = [];
delim = delim || mw.msg( 'comma-separator' );
$.each( str.split( delim ), function () {
var trimmed = $.trim( this );
str.split( delim ).forEach( function ( part ) {
var trimmed = part.trim();
if ( trimmed ) {
arr.push( trimmed );
}
@ -239,7 +239,7 @@ mw.TemplateData.Model.static.arrayUnionWithoutEmpty = function () {
// Trim and filter empty strings
return result.filter( function ( i ) {
return $.trim( i );
return i.trim();
} );
};
@ -299,7 +299,7 @@ mw.TemplateData.Model.prototype.getMissingParams = function () {
// Check source code params
for ( i = 0; i < this.sourceCodeParameters.length; i++ ) {
if ( $.inArray( this.sourceCodeParameters[ i ], allParamNames ) === -1 ) {
if ( allParamNames.indexOf( this.sourceCodeParameters[ i ] ) === -1 ) {
result.push( this.sourceCodeParameters[ i ] );
}
}
@ -321,7 +321,7 @@ mw.TemplateData.Model.prototype.importSourceCodeParameters = function () {
// Check existing params
for ( i = 0; i < allParamNames.length; i++ ) {
paramKey = allParamNames[ i ];
if ( $.inArray( paramKey, this.sourceCodeParameters ) !== -1 ) {
if ( this.sourceCodeParameters.indexOf( paramKey ) !== -1 ) {
existingArray.push( paramKey );
}
}
@ -329,7 +329,7 @@ mw.TemplateData.Model.prototype.importSourceCodeParameters = function () {
// Add sourceCodeParameters to the model
for ( i = 0; i < this.sourceCodeParameters.length; i++ ) {
if (
$.inArray( this.sourceCodeParameters[ i ], existingArray ) === -1 &&
existingArray.indexOf( this.sourceCodeParameters[ i ] ) === -1 &&
this.addParam( this.sourceCodeParameters[ i ] )
) {
importedArray.push( this.sourceCodeParameters[ i ] );
@ -371,7 +371,7 @@ mw.TemplateData.Model.prototype.getExistingLanguageCodes = function () {
for ( param in this.params ) {
// Go over the properties
for ( prop in this.params[ param ] ) {
if ( $.inArray( prop, languageProps ) !== -1 ) {
if ( languageProps.indexOf( prop ) !== -1 ) {
result = this.constructor.static.arrayUnionWithoutEmpty( result, Object.keys( this.params[ param ][ prop ] ) );
}
}
@ -399,7 +399,7 @@ mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
name = key;
// Check that the parameter is not already in the model
if ( this.params[ key ] || $.inArray( key, existingNames ) !== -1 ) {
if ( this.params[ key ] || existingNames.indexOf( key ) !== -1 ) {
// Change parameter key
key = this.getNewValidParameterKey( key );
}
@ -411,7 +411,7 @@ mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
this.params[ key ].name = name;
// Mark the parameter if it is in the template source
if ( $.inArray( key, this.sourceCodeParameters ) !== -1 ) {
if ( this.sourceCodeParameters.indexOf( key ) !== -1 ) {
this.params[ key ].inSource = true;
}
@ -451,7 +451,7 @@ mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
}
if (
$.inArray( propToSet, propertiesWithLanguage ) !== -1 &&
propertiesWithLanguage.indexOf( propToSet ) !== -1 &&
$.isPlainObject( data[ prop ] )
) {
// Add all language properties
@ -592,7 +592,7 @@ mw.TemplateData.Model.prototype.setTemplateFormat = function ( format ) {
* @fires change
*/
mw.TemplateData.Model.prototype.addKeyTemplateParamOrder = function ( key ) {
if ( $.inArray( key, this.paramOrder ) === -1 ) {
if ( this.paramOrder.indexOf( key ) === -1 ) {
this.paramOrder.push( key );
this.emit( 'add-paramOrder', key );
this.emit( 'change' );
@ -629,7 +629,7 @@ mw.TemplateData.Model.prototype.reorderParamOrderKey = function ( key, newIndex
* @fires change
*/
mw.TemplateData.Model.prototype.removeKeyTemplateParamOrder = function ( key ) {
var keyPos = $.inArray( key, this.paramOrder );
var keyPos = this.paramOrder.indexOf( key );
if ( keyPos > -1 ) {
this.paramOrder.splice( keyPos, 1 );
this.emit( 'change-paramOrder', this.paramOrder );
@ -680,11 +680,11 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
if ( allProps[ prop ].type === 'array' && $.type( value ) === 'string' ) {
// When we split the string, we want to use a trimmed delimiter
value = this.constructor.static.splitAndTrimArray( value, $.trim( allProps[ prop ].delimiter ) );
value = this.constructor.static.splitAndTrimArray( value, allProps[ prop ].delimiter.trim() );
}
// Check if the property is split by language code
if ( $.inArray( prop, propertiesWithLanguage ) !== -1 ) {
if ( propertiesWithLanguage.indexOf( prop ) !== -1 ) {
// Initialize property if necessary
if ( !$.isPlainObject( this.params[ paramKey ][ prop ] ) ) {
this.params[ paramKey ][ prop ] = {};
@ -828,7 +828,7 @@ mw.TemplateData.Model.prototype.isParamDeleted = function ( key ) {
};
mw.TemplateData.Model.prototype.isParamExists = function ( key ) {
return $.inArray( key, Object.keys( this.params ) ) > -1;
return Object.prototype.hasOwnProperty.call( this.params, key );
};
/**
@ -1050,7 +1050,7 @@ mw.TemplateData.Model.prototype.outputTemplateData = function () {
*/
mw.TemplateData.Model.prototype.getNewValidParameterKey = function ( key ) {
var allParamNames = this.getAllParamNames();
if ( this.params[ key ] || $.inArray( key, allParamNames ) !== -1 ) {
if ( this.params[ key ] || allParamNames.indexOf( key ) !== -1 ) {
// Change the key to be something else
key += this.paramIdentifierCounter;
this.paramIdentifierCounter++;

View file

@ -177,7 +177,7 @@ mw.TemplateData.SourceHandler.prototype.extractParametersFromTemplateCode = func
}
if ( paramNames.indexOf( matches[ 1 ] ) === -1 ) {
normalizedParamNames.push( normalizedParamName );
paramNames.push( $.trim( matches[ 1 ] ) );
paramNames.push( matches[ 1 ].trim() );
}
}
@ -201,10 +201,10 @@ mw.TemplateData.SourceHandler.prototype.parseModelFromString = function ( templa
);
// Check if <templatedata> exists
if ( parts && parts[ 1 ] && $.trim( parts[ 1 ] ).length > 0 ) {
if ( parts && parts[ 1 ] && parts[ 1 ].trim().length > 0 ) {
// Parse the json string
try {
return JSON.parse( $.trim( parts[ 1 ] ) );
return JSON.parse( parts[ 1 ].trim() );
} catch ( err ) {
return null;
}

View file

@ -386,7 +386,7 @@ mw.TemplateData.Dialog.prototype.onNewLanguageSearchResultsChoose = function ( i
newLanguage = item.getData().code;
if ( newLanguage ) {
if ( $.inArray( newLanguage, this.availableLanguages ) === -1 ) {
if ( this.availableLanguages.indexOf( newLanguage ) === -1 ) {
// Add new language
this.availableLanguages.push( newLanguage );
languageButton = new OO.ui.MenuOptionWidget( {
@ -659,7 +659,7 @@ mw.TemplateData.Dialog.prototype.changeParamPropertyInput = function ( paramKey,
} else if ( prop.type === 'boolean' ) {
propInput.setSelected( !!value );
} else {
if ( $.inArray( propName, languageProps ) !== -1 ) {
if ( languageProps.indexOf( propName ) !== -1 ) {
propInput.setValue( value[ lang ] );
} else {
if ( prop.type === 'array' && $.type( value ) === 'array' ) {
@ -842,9 +842,9 @@ mw.TemplateData.Dialog.prototype.toggleNoticeMessage = function ( type, isShowin
}
isShowing = isShowing || !noticeReference.$element.is( ':visible' );
if ( $.type( noticeMessage ) === 'array' ) {
if ( Array.isArray( noticeMessage ) ) {
$message = $( '<div>' );
$.each( noticeMessage, function ( i, msg ) {
noticeMessage.forEach( function ( msg ) {
$message.append( $( '<p>' ).text( msg ) );
} );
noticeReference.setLabel( $message );
@ -926,7 +926,7 @@ mw.TemplateData.Dialog.prototype.getSetupProcess = function ( data ) {
// Fill up the language selection
if (
languages.length === 0 ||
$.inArray( language, languages ) === -1
languages.indexOf( language ) === -1
) {
// Add the default language
languageItems.push( new OO.ui.MenuOptionWidget( {

View file

@ -5,15 +5,13 @@
"doc": "jsduck"
},
"devDependencies": {
"eslint-config-wikimedia": "0.8.1",
"eslint-plugin-qunit": "3.3.1",
"eslint-config-wikimedia": "0.9.0",
"grunt": "1.0.3",
"grunt-banana-checker": "0.6.0",
"grunt-contrib-watch": "1.1.0",
"grunt-eslint": "21.0.0",
"grunt-jsonlint": "1.1.0",
"grunt-stylelint": "0.10.1",
"stylelint": "9.2.0",
"stylelint-config-wikimedia": "0.4.3"
"stylelint-config-wikimedia": "0.5.0"
}
}

View file

@ -17,49 +17,49 @@
originalWikitext = 'Some text here that is not templatedata information.' +
'<templatedata>' +
'{' +
' "description": {\n' +
' "' + currLanguage + '": "Label unsigned comments in a conversation.",\n' +
' "blah": "Template description in some blah language."\n' +
' },' +
' "params": {' +
' "user": {' +
' "label": "Username",' +
' "type": "wiki-user-name",' +
' "required": true,' +
' "description": "User name of person who forgot to sign their comment.",' +
' "aliases": ["1"]' +
' },' +
' "date": {' +
' "label": "Date",' +
' "description": {' +
' "' + currLanguage + '": "Timestamp of when the comment was posted, in YYYY-MM-DD format."' +
' },' +
' "aliases": ["2"],' +
' "autovalue": "{{subst:CURRENTMONTHNAME}}",' +
' "suggested": true' +
' },' +
' "year": {' +
' "label": "Year",' +
' "type": "number"' +
' },' +
' "month": {' +
' "label": "Month",' +
' "inherits": "year"' +
' },' +
' "day": {' +
' "label": "Day",' +
' "inherits": "year"' +
' },' +
' "comment": {' +
' "required": false' +
' }' +
' },' +
' "sets": [' +
' {' +
' "label": "Date",' +
' "params": ["year", "month", "day"]' +
' }' +
' ]' +
'"description": {\n' +
'"' + currLanguage + '": "Label unsigned comments in a conversation.",\n' +
'"blah": "Template description in some blah language."\n' +
'},' +
'"params": {' +
'"user": {' +
'"label": "Username",' +
'"type": "wiki-user-name",' +
'"required": true,' +
'"description": "User name of person who forgot to sign their comment.",' +
'"aliases": ["1"]' +
'},' +
'"date": {' +
'"label": "Date",' +
'"description": {' +
'"' + currLanguage + '": "Timestamp of when the comment was posted, in YYYY-MM-DD format."' +
'},' +
'"aliases": ["2"],' +
'"autovalue": "{{subst:CURRENTMONTHNAME}}",' +
'"suggested": true' +
'},' +
'"year": {' +
'"label": "Year",' +
'"type": "number"' +
'},' +
'"month": {' +
'"label": "Month",' +
'"inherits": "year"' +
'},' +
'"day": {' +
'"label": "Day",' +
'"inherits": "year"' +
'},' +
'"comment": {' +
'"required": false' +
'}' +
'},' +
'"sets": [' +
'{' +
'"label": "Date",' +
'"params": ["year", "month", "day"]' +
'}' +
']' +
'}' +
'</templatedata>' +
'Trailing text at the end.';
@ -602,27 +602,27 @@
QUnit.test( 'TemplateData sourceHandler', function ( assert ) {
var sourceHandler = new mw.TemplateData.SourceHandler(),
erronousString = '<templatedata>{\n' +
' "params": {\n' +
// Open quote
' "user: {\n' +
' "label": "Username",\n' +
' "type": "wiki-user-name",\n' +
' "required": true,\n' +
' "description": "User name of person who forgot to sign their comment.",\n' +
' "aliases": [\n' +
' "1"\n' +
' ]\n' +
' },\n' +
' "date": {\n' +
' "label": "Date",\n' +
' "description": {\n' +
// Forgotten quotes
' ' + currLanguage + ': "Timestamp of when the comment was posted, in YYYY-MM-DD format."\n' +
' }\n' +
' "suggested": true\n' +
' }\n' +
' }\n' +
'}</templatedata>',
'"params": {\n' +
// Open quote
'"user: {\n' +
'"label": "Username",\n' +
'"type": "wiki-user-name",\n' +
'"required": true,\n' +
'"description": "User name of person who forgot to sign their comment.",\n' +
'"aliases": [\n' +
'"1"\n' +
']\n' +
'},\n' +
'"date": {\n' +
'"label": "Date",\n' +
'"description": {\n' +
// Forgotten quotes
currLanguage + ': "Timestamp of when the comment was posted, in YYYY-MM-DD format."\n' +
'}\n' +
'"suggested": true\n' +
'}\n' +
'}\n' +
'}</templatedata>',
done = assert.async(),
promise;
@ -637,7 +637,7 @@
QUnit.test( 'TemplateData sourceHandler adding default format', function ( assert ) {
var sourceHandler = new mw.TemplateData.SourceHandler(),
simpleTemplateDataNoFormat = '<templatedata>{\n' +
' "params": {}\n' +
'"params": {}\n' +
'}</templatedata>',
simpleTemplateDataDefaultFormat = {
params: {}