Skip to content

Commit

Permalink
Eslint jQuery migration tests (#42)
Browse files Browse the repository at this point in the history
* MC-41858: Eslint jQuery migration tests

* MC-41858: Updated eslint jQuery configuration

* MC-41858: Fixed eslint jQuery static tests

* MC-41858: Fixed eslint jQuery static tests

* MC-41858: Fixed eslint jQuery static tests

* MC-41858: Fixed eslint jQuery static tests
  • Loading branch information
sivaschenko authored May 26, 2021
1 parent 95445b3 commit 979c0f7
Show file tree
Hide file tree
Showing 35 changed files with 302 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/view/frontend/web/js/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ define([
$('html, body').animate({
scrollTop: $(this.options.bundleOptionsContainer).offset().top
}, 600);
$('#product-options-wrapper > fieldset').focus();
$('#product-options-wrapper > fieldset').trigger('focus');
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ define([
content: data.message
});
} else {
$(this.options.categoryIdSelector).val(data.id).change();
$(this.options.categoryPathSelector).val(data.path).change();
$(this.options.categoryParentSelector).val(data.parentId).change();
$(this.options.categoryLevelSelector).val(data.level).change();
$(this.options.categoryIdSelector).val(data.id).trigger('change');
$(this.options.categoryPathSelector).val(data.path).trigger('change');
$(this.options.categoryParentSelector).val(data.parentId).trigger('change');
$(this.options.categoryLevelSelector).val(data.level).trigger('change');
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ define([
this.refreshSortableElements();
this.options.selectionItemCount[data.id] = parseInt(this.options.selectionItemCount[data.id], 10) + 1;

$('#' + this.options.fieldId + '_' + data.id + '_select_' + data['select_id'] + '_title').focus();
$('#' + this.options.fieldId + '_' + data.id + '_select_' + data['select_id'] + '_title').trigger('focus');
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ define([
$('#new_category_name').val(enteredName);

if (enteredName === '') {
$('#new_category_name').focus();
$('#new_category_name').trigger('focus');
}
$('#new_category_messages').html('');
},
Expand All @@ -88,7 +88,7 @@ define([
validationOptions.unhighlight($('#new_category_parent-suggest').get(0),
validationOptions.errorClass, validationOptions.validClass || '');
newCategoryForm.validation('clearError');
$('#category_ids-suggest').focus();
$('#category_ids-suggest').trigger('focus');
},
buttons: [{
text: $.mage.__('Create Category'),
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/view/frontend/web/js/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ define([
}, this));

// Window resize will change offset for draggable
$(window).resize(this._draggableImage());
$(window).on('resize', this._draggableImage);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ define([
*/
stopLoader: function (forceStop) {
var $elem = $(containerId),
stop = $elem.trigger.bind($elem, 'processStop');
stop = $elem.trigger.bind($elem, 'processStop'); //eslint-disable-line jquery-no-bind-unbind

forceStop ? stop() : resolver(stop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ define([
}

if (!emailValidationResult) {
$(loginFormSelector + ' input[name=username]').focus();
$(loginFormSelector + ' input[name=username]').trigger('focus');

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ define([
container.show()
.find('.giftmessage-area:not(:visible)').each(function (x, element) {
if ($(element).val().length > 0) {
$(element).change();
$(element).trigger('change');
container.find('a').click();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ define([
if (targetElement.is('textarea')) {
this.insertAtCursor(targetElement.get(0), data.content);
targetElement.focus();
$(targetElement).change();
$(targetElement).trigger('change');
} else {
targetElement.val(data.content)
.data('size', data.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ define([

if (self.isFullscreen && !self.fotoramaItem.data('fotorama').options.fullscreen.arrows) {
if ($('.' + self.FTAR + '--prev').is(':focus') || $('.' + self.FTAR + '--next').is(':focus')) {
$(self.FTCF).focus();
$(self.FTCF).trigger('focus');
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define([
});

if (firstSwatch.length) {
$(firstSwatch).focus();
$(firstSwatch).trigger('focus');
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/grid/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ define([
if ($(table).is(this.mainTableSelector)) {
this.table = table;
this.tableWidth = $(table).outerWidth();
$(window).resize(this.checkAfterResize);
$(window).on('resize', this.checkAfterResize);
}

//TODO - Must be deleted when Firefox fixed problem with table-layout: fixed
Expand Down Expand Up @@ -244,7 +244,7 @@ define([

setTimeout(function () {
if (self.layoutFixedPolyfillIterator < 20) {
$(window).resize();
$(window).trigger('resize');
self.layoutFixedPolyfillIterator++;
self._layoutFixedPolyfill();
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/grid/sticky/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ define([
* @returns {Object} Chainable.
*/
initOnListingScroll: function () {
$(this.listingNode).scroll(function (e) {
$(this.listingNode).on('scroll', function (e) {
this.flags.listingScrolled = true;
this.flags.listingScrolledValue = $(e.target).scrollLeft();
}.bind(this));
Expand All @@ -234,7 +234,7 @@ define([
* @returns {Object} Chainable.
*/
initOnResize: function () {
$(window).resize(function () {
$(window).on('resize', function () {
this.flags.resized = true;
}.bind(this));

Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/Ui/view/base/web/js/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ define([
infelicity;

if (type === 'opened' && this.options.focus) {
this.modal.find($(this.options.focus)).focus();
this.modal.find($(this.options.focus)).trigger('focus');
} else if (type === 'opened' && !this.options.focus) {
this.modal.find(this.options.focusableScope).focus();
this.modal.find(this.options.focusableScope).trigger('focus');
} else if (position === 'end') {
this.modal.find(this.options.modalCloseBtn).focus();
this.modal.find(this.options.modalCloseBtn).trigger('focus');
} else if (position === 'start') {
infelicity = 2; //Constant for find last focusable element
focusableElements = this.modal.find(':focusable');
focusableElements.eq(focusableElements.length - infelicity).focus();
focusableElements.eq(focusableElements.length - infelicity).trigger('focus');
}
},

Expand Down Expand Up @@ -331,7 +331,7 @@ define([
_close: function () {
var trigger = _.bind(this._trigger, this, 'closed', this.modal);

$(this.focussedElement).focus();
$(this.focussedElement).trigger('focus');
this._destroyOverlay();
this._unsetActive();
_.defer(trigger, this);
Expand Down
2 changes: 1 addition & 1 deletion app/design/adminhtml/Magento/backend/web/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ define('globalNavigation', [

if (e.which === 13) {
this._close(e);
$(selectors.topLevelHref, menuItem).focus();
$(selectors.topLevelHref, menuItem).trigger('focus');
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ define([
});
it('Check that region list is not displayed when selected country has no predefined regions', function () {
init();
$(countryEl).val('GB').change();
$(countryEl).val('GB').trigger('change');
expect($(regionInputEl).is(':visible')).toBe(true);
expect($(regionInputEl).is(':disabled')).toBe(false);
expect($(regionSelectEl).is(':visible')).toBe(false);
expect($(regionSelectEl).is(':disabled')).toBe(true);
});
it('Check country that has predefined and optional regions', function () {
init();
$(countryEl).val('DE').change();
$(countryEl).val('DE').trigger('change');
expect($(regionSelectEl).is(':visible')).toBe(true);
expect($(regionSelectEl).is(':disabled')).toBe(false);
expect($(regionSelectEl).hasClass('required-entry')).toBe(false);
Expand All @@ -182,7 +182,7 @@ define([
});
it('Check country that has predefined and required regions', function () {
init();
$(countryEl).val('US').change();
$(countryEl).val('US').trigger('change');
expect($(regionSelectEl).is(':visible')).toBe(true);
expect($(regionSelectEl).is(':disabled')).toBe(false);
expect($(regionSelectEl).hasClass('required-entry')).toBe(true);
Expand All @@ -199,7 +199,7 @@ define([
init({
optionalRegionAllowed: false
});
$(countryEl).val('DE').change();
$(countryEl).val('DE').trigger('change');
expect($(regionSelectEl).is(':visible')).toBe(false);
expect($(regionInputEl).is(':visible')).toBe(false);
});
Expand All @@ -226,7 +226,7 @@ define([
$(countryEl).val('GB');
$(regionInputEl).val('Liverpool');
init();
$(countryEl).val('IT').change();
$(countryEl).val('IT').trigger('change');
expect($(countryEl).val()).toBe('IT');
expect($(regionInputEl).val()).toBe('');
});
Expand All @@ -235,7 +235,7 @@ define([
init({
defaultRegion: '2'
});
$(countryEl).val('DE').change();
$(countryEl).val('DE').trigger('change');
expect($(countryEl).val()).toBe('DE');
expect($(regionSelectEl).val()).toBe('');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ define([
patternPlaceholderClose: /^ \/BLOCK (.+) $/
}
};
// eslint-disable-next-line jquery-no-bind-unbind
replacer = $.mage.pageCache.prototype._replacePlaceholder.bind(context);
// eslint-disable-next-line jquery-no-bind-unbind
searcher = $.mage.pageCache.prototype._searchPlaceholders.bind(context);

wdContainer
Expand All @@ -208,7 +210,9 @@ define([
patternPlaceholderClose: /^ \/BLOCK (.+) $/
}
};
// eslint-disable-next-line jquery-no-bind-unbind
replacer = $.mage.pageCache.prototype._replacePlaceholder.bind(context);
// eslint-disable-next-line jquery-no-bind-unbind
searcher = $.mage.pageCache.prototype._searchPlaceholders.bind(context);

wdContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ define([
$pageMainActions.appendTo('body');
$('body').notification();

// eslint-disable-next-line jquery-no-event-shorthand
$.ajaxSettings.error();

expect($('.message-error').length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": [
"./.eslintrc-reset",
"./.eslintrc-magento"
"./.eslintrc-magento",
"./.eslintrc-jquery"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"rules": {
"jquery-no-andSelf": 2,
"jquery-no-bind-unbind": 2,
"jquery-no-click-event-shorthand": 2,
"jquery-no-delegate-undelegate": 2,
"jquery-no-event-shorthand": 2,
"jquery-no-size": 2,
"jquery-no-trim": 2
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
// http://eslint.org/docs/rules/

"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
"objectLiteralDuplicateProperties": false, // enable duplicate object literal properties in strict mode
"objectLiteralShorthandMethods": false, // enable object literal shorthand methods
"objectLiteralShorthandProperties": false, // enable object literal shorthand properties
"octalLiterals": false, // enable octal literals
"regexUFlag": false, // enable the regular expression u flag
"regexYFlag": false, // enable the regular expression y flag
"templateStrings": false, // enable template strings
"unicodeCodePointEscapes": false, // enable code point escapes
"jsx": false // enable JSX
"parserOptions": {
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
"objectLiteralDuplicateProperties": false, // enable duplicate object literal properties in strict mode
"objectLiteralShorthandMethods": false, // enable object literal shorthand methods
"objectLiteralShorthandProperties": false, // enable object literal shorthand properties
"octalLiterals": false, // enable octal literals
"regexUFlag": false, // enable the regular expression u flag
"regexYFlag": false, // enable the regular expression y flag
"templateStrings": false, // enable template strings
"unicodeCodePointEscapes": false, // enable code point escapes
"jsx": false // enable JSX
},
},

"env": {
Expand Down Expand Up @@ -214,4 +216,4 @@
"no-bitwise": 0, // disallow use of bitwise operators (off by default)
"no-plusplus": 0 // disallow use of unary operators, ++ and -- (off by default)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const utils = require('./utils.js')

module.exports = {
meta: {
docs: {},
schema: []
},

create: function(context) {
return {
CallExpression: function(node) {
if (node.callee.type !== 'MemberExpression') return
if (node.callee.property.name !== 'andSelf') return

if (utils.isjQuery(node)) {
context.report({
node: node,
message: 'jQuery.andSelf() removed, use jQuery.addBack()'
})
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const utils = require('./utils.js')

module.exports = {
meta: {
docs: {},
schema: []
},

create: function(context) {
return {
CallExpression: function(node) {
if (node.callee.type !== 'MemberExpression') return
if (!['bind', 'unbind'].includes(node.callee.property.name)) return

if (utils.isjQuery(node)) {
context.report({
node: node,
message: 'jQuery $.bind and $.unbind are deprecated, use $.on and $.off instead'
})
}
}
}
}
}
Loading

0 comments on commit 979c0f7

Please sign in to comment.