Skip to content

Commit

Permalink
fix eslint rule no-jquery/variable-pattern (wikimedia-gadgets#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae authored and ptsgrn committed Dec 4, 2024
1 parent 1d516ed commit 3adc85d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
19 changes: 18 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@
"no-underscore-dangle": "off",
"security/detect-non-literal-regexp": "off",
"security/detect-unsafe-regex": "off",
"unicorn/prefer-string-slice": "off"
"unicorn/prefer-string-slice": "off",

"eqeqeq": "warn",
"es-x/no-array-prototype-includes": "warn",
"es-x/no-object-values": "warn",
"es-x/no-regexp-s-flag": "warn",
"no-global-assign": "warn",
"no-implicit-globals": "warn",
"no-jquery/no-animate": "warn",
"no-jquery/no-each-util": "warn",
"no-jquery/no-grep": "warn",
"no-jquery/no-in-array": "warn",
"no-jquery/no-map-util": "warn",
"no-jquery/no-sizzle": "warn",
"no-jquery/no-slide": "warn",
"no-jquery/no-trim": "warn",
"no-undef": "warn",
"prefer-const": "warn"
}
}
26 changes: 13 additions & 13 deletions src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@
/**
* Represents the status container, created ub init()
*/
container: false,
$container: false,

/**
* Creates the status container
Expand All @@ -978,7 +978,7 @@
* status container should be prepended
*/
init: function ( location ) {
AFCH.status.container = $( '<div>' )
AFCH.status.$container = $( '<div>' )
.attr( 'id', 'afchStatus' )
.addClass( 'afchStatus' )
.prependTo( location || '#mw-content-text' );
Expand Down Expand Up @@ -1015,7 +1015,7 @@
html = html.replace( key, value );
} );
// Then update the element
this.element.html( html );
this.$element.html( html );
};

/**
Expand All @@ -1026,7 +1026,7 @@
};

// Sanity check, there better be a status container
if ( !AFCH.status.container ) {
if ( !AFCH.status.$container ) {
AFCH.status.init();
}

Expand All @@ -1038,8 +1038,8 @@

this.substitutions = substitutions;

this.element = $( '<li>' )
.appendTo( AFCH.status.container );
this.$element = $( '<li>' )
.appendTo( AFCH.status.$container );

this.update( initialText );
}
Expand Down Expand Up @@ -1400,20 +1400,20 @@
this.views = views;
this.$element = $element;

this.previousState = false;
this.$previousState = false;

this.loadView = function ( view, data ) {
var code = this.views.renderView( view, data );

// Update the view cache
this.previousState = this.$element.clone( true );
this.$previousState = this.$element.clone( true );

this.$element.html( code );
};

this.loadPrevious = function () {
this.$element.replaceWith( this.previousState );
this.$element = this.previousState;
this.$element.replaceWith( this.$previousState );
this.$element = this.$previousState;
};
},

Expand Down Expand Up @@ -1538,13 +1538,13 @@
titles: 'หมวดหมู่:' + pagename,
prop: 'categoryinfo'
},
linkSpan = $( '<span>' ).append( linkElement ),
$linkSpan = $( '<span>' ).append( linkElement ),
countSpanId = 'afch-cat-count-' + pagename
.toLowerCase()
.replace( / /g, '-' )
.replace( /\//g, '-' );

linkSpan.append( $( '<span>' ).attr( 'id', countSpanId ) );
$linkSpan.append( $( '<span>' ).attr( 'id', countSpanId ) );

AFCH.api.get( request )
.done( function ( data ) {
Expand All @@ -1558,7 +1558,7 @@
}
} );

return linkSpan;
return $linkSpan;
},

/**
Expand Down
36 changes: 18 additions & 18 deletions src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,19 +2156,19 @@
// is triggering this update is first or second in the multi-select
// control
function updateTextfield( newPrompt, newPlaceholder, newValue, pos ) {
var wrapper = $afch.find( '#textfieldWrapper' + ( pos === 2 ? '2' : '' ) );
const $wrapper = $afch.find( '#textfieldWrapper' + ( pos === 2 ? '2' : '' ) );

// Update label and placeholder
wrapper.find( 'label' ).text( newPrompt );
wrapper.find( 'input' ).attr( 'placeholder', newPlaceholder );
$wrapper.find( 'label' ).text( newPrompt );
$wrapper.find( 'input' ).attr( 'placeholder', newPlaceholder );

// Update default textfield value (perhaps)
if ( typeof newValue !== 'undefined' ) {
wrapper.find( 'input' ).val( newValue );
$wrapper.find( 'input' ).val( newValue );
}

// And finally show the textfield
wrapper.removeClass( 'hidden' );
$wrapper.removeClass( 'hidden' );
}

// Copy most-used options to top of decline dropdown
Expand Down Expand Up @@ -2231,16 +2231,16 @@
$afch.find( '#cvUrlTextarea' ).keyup( function () {
var text = $( this ).val(),
numUrls = text ? text.split( '\n' ).length : 0,
submitButton = $afch.find( '#afchSubmitForm' );
$submitButton = $afch.find( '#afchSubmitForm' );
if ( numUrls >= 1 && numUrls <= 3 ) {
$( this ).removeClass( 'bad-input' );
submitButton
$submitButton
.removeClass( 'disabled' )
.css( 'pointer-events', 'auto' )
.text( 'ตีกลับฉบับร่าง' );
} else {
$( this ).addClass( 'bad-input' );
submitButton
$submitButton
.addClass( 'disabled' )
.css( 'pointer-events', 'none' )
.text( 'กรุณาใส่หนึ่งถึงสามลิงก์' );
Expand Down Expand Up @@ -2484,10 +2484,10 @@

// Show an error if there's no such user
$afch.find( '#submitterName' ).keyup( function () {
var field = $( this ),
status = $( '#submitterNameStatus' ),
submitButton = $afch.find( '#afchSubmitForm' ),
submitter = field.val();
var $field = $( this ),
$status = $( '#submitterNameStatus' ),
$submitButton = $afch.find( '#afchSubmitForm' ),
submitter = $field.val();

// Reset form
resetStatus();
Expand All @@ -2499,9 +2499,9 @@

// Check if the user string starts with "User:", because Template:AFC submission dies horribly if it does
if ( submitter.lastIndexOf( 'ผู้ใช้:', 0 ) === 0 ) {
field.addClass( 'bad-input' );
status.text( 'ลบ "ผู้ใช้:" ออกจากข้อความเริ่มต้น' );
submitButton
$field.addClass( 'bad-input' );
$status.text( 'ลบ "ผู้ใช้:" ออกจากข้อความเริ่มต้น' );
$submitButton
.addClass( 'disabled' )
.css( 'pointer-events', 'none' )
.text( 'ชื่อผู้ใช้ไม่ถูกต้อง' );
Expand All @@ -2515,9 +2515,9 @@
ususers: submitter
} ).done( function ( data ) {
if ( data.query.users[ 0 ].missing !== undefined ) {
field.addClass( 'bad-input' );
status.text( 'ไม่พบผู้ใช้ชื่อ "' + submitter + '"' );
submitButton
$field.addClass( 'bad-input' );
$status.text( 'ไม่พบผู้ใช้ชื่อ "' + submitter + '"' );
$submitButton
.addClass( 'disabled' )
.css( 'pointer-events', 'none' )
.text( 'ไม่พบผู้ใช้' );
Expand Down

0 comments on commit 3adc85d

Please sign in to comment.