Skip to content

Commit 979c0f7

Browse files
authored
Eslint jQuery migration tests (#42)
* 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
1 parent 95445b3 commit 979c0f7

File tree

35 files changed

+302
-54
lines changed

35 files changed

+302
-54
lines changed

app/code/Magento/Bundle/view/frontend/web/js/slide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ define([
8585
$('html, body').animate({
8686
scrollTop: $(this.options.bundleOptionsContainer).offset().top
8787
}, 600);
88-
$('#product-options-wrapper > fieldset').focus();
88+
$('#product-options-wrapper > fieldset').trigger('focus');
8989
},
9090

9191
/**

app/code/Magento/Catalog/view/adminhtml/web/catalog/category/form.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ define([
4545
content: data.message
4646
});
4747
} else {
48-
$(this.options.categoryIdSelector).val(data.id).change();
49-
$(this.options.categoryPathSelector).val(data.path).change();
50-
$(this.options.categoryParentSelector).val(data.parentId).change();
51-
$(this.options.categoryLevelSelector).val(data.level).change();
48+
$(this.options.categoryIdSelector).val(data.id).trigger('change');
49+
$(this.options.categoryPathSelector).val(data.path).trigger('change');
50+
$(this.options.categoryParentSelector).val(data.parentId).trigger('change');
51+
$(this.options.categoryLevelSelector).val(data.level).trigger('change');
5252
}
5353
}
5454
};

app/code/Magento/Catalog/view/adminhtml/web/js/custom-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ define([
437437
this.refreshSortableElements();
438438
this.options.selectionItemCount[data.id] = parseInt(this.options.selectionItemCount[data.id], 10) + 1;
439439

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

443443
/**

app/code/Magento/Catalog/view/adminhtml/web/js/new-category-dialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ define([
7575
$('#new_category_name').val(enteredName);
7676

7777
if (enteredName === '') {
78-
$('#new_category_name').focus();
78+
$('#new_category_name').trigger('focus');
7979
}
8080
$('#new_category_messages').html('');
8181
},
@@ -88,7 +88,7 @@ define([
8888
validationOptions.unhighlight($('#new_category_parent-suggest').get(0),
8989
validationOptions.errorClass, validationOptions.validClass || '');
9090
newCategoryForm.validation('clearError');
91-
$('#category_ids-suggest').focus();
91+
$('#category_ids-suggest').trigger('focus');
9292
},
9393
buttons: [{
9494
text: $.mage.__('Create Category'),

app/code/Magento/Catalog/view/frontend/web/js/zoom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ define([
9292
}, this));
9393

9494
// Window resize will change offset for draggable
95-
$(window).resize(this._draggableImage());
95+
$(window).on('resize', this._draggableImage);
9696
},
9797

9898
/**

app/code/Magento/Checkout/view/frontend/web/js/model/full-screen-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ define([
2727
*/
2828
stopLoader: function (forceStop) {
2929
var $elem = $(containerId),
30-
stop = $elem.trigger.bind($elem, 'processStop');
30+
stop = $elem.trigger.bind($elem, 'processStop'); //eslint-disable-line jquery-no-bind-unbind
3131

3232
forceStop ? stop() : resolver(stop);
3333
}

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ define([
354354
}
355355

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

359359
return false;
360360
}

app/code/Magento/GiftMessage/view/frontend/web/js/gift-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ define([
4848
container.show()
4949
.find('.giftmessage-area:not(:visible)').each(function (x, element) {
5050
if ($(element).val().length > 0) {
51-
$(element).change();
51+
$(element).trigger('change');
5252
container.find('a').click();
5353
}
5454
});

app/code/Magento/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/insertImageAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ define([
4949
if (targetElement.is('textarea')) {
5050
this.insertAtCursor(targetElement.get(0), data.content);
5151
targetElement.focus();
52-
$(targetElement).change();
52+
$(targetElement).trigger('change');
5353
} else {
5454
targetElement.val(data.content)
5555
.data('size', data.size)

app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ define([
812812

813813
if (self.isFullscreen && !self.fotoramaItem.data('fotorama').options.fullscreen.arrows) {
814814
if ($('.' + self.FTAR + '--prev').is(':focus') || $('.' + self.FTAR + '--next').is(':focus')) {
815-
$(self.FTCF).focus();
815+
$(self.FTCF).trigger('focus');
816816
}
817817
}
818818
});

app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ define([
5555
});
5656

5757
if (firstSwatch.length) {
58-
$(firstSwatch).focus();
58+
$(firstSwatch).trigger('focus');
5959
}
6060
}
6161
});

app/code/Magento/Ui/view/base/web/js/grid/resize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ define([
9292
if ($(table).is(this.mainTableSelector)) {
9393
this.table = table;
9494
this.tableWidth = $(table).outerWidth();
95-
$(window).resize(this.checkAfterResize);
95+
$(window).on('resize', this.checkAfterResize);
9696
}
9797

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

245245
setTimeout(function () {
246246
if (self.layoutFixedPolyfillIterator < 20) {
247-
$(window).resize();
247+
$(window).trigger('resize');
248248
self.layoutFixedPolyfillIterator++;
249249
self._layoutFixedPolyfill();
250250
} else {

app/code/Magento/Ui/view/base/web/js/grid/sticky/sticky.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ define([
220220
* @returns {Object} Chainable.
221221
*/
222222
initOnListingScroll: function () {
223-
$(this.listingNode).scroll(function (e) {
223+
$(this.listingNode).on('scroll', function (e) {
224224
this.flags.listingScrolled = true;
225225
this.flags.listingScrolledValue = $(e.target).scrollLeft();
226226
}.bind(this));
@@ -234,7 +234,7 @@ define([
234234
* @returns {Object} Chainable.
235235
*/
236236
initOnResize: function () {
237-
$(window).resize(function () {
237+
$(window).on('resize', function () {
238238
this.flags.resized = true;
239239
}.bind(this));
240240

app/code/Magento/Ui/view/base/web/js/modal/modal.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ define([
260260
infelicity;
261261

262262
if (type === 'opened' && this.options.focus) {
263-
this.modal.find($(this.options.focus)).focus();
263+
this.modal.find($(this.options.focus)).trigger('focus');
264264
} else if (type === 'opened' && !this.options.focus) {
265-
this.modal.find(this.options.focusableScope).focus();
265+
this.modal.find(this.options.focusableScope).trigger('focus');
266266
} else if (position === 'end') {
267-
this.modal.find(this.options.modalCloseBtn).focus();
267+
this.modal.find(this.options.modalCloseBtn).trigger('focus');
268268
} else if (position === 'start') {
269269
infelicity = 2; //Constant for find last focusable element
270270
focusableElements = this.modal.find(':focusable');
271-
focusableElements.eq(focusableElements.length - infelicity).focus();
271+
focusableElements.eq(focusableElements.length - infelicity).trigger('focus');
272272
}
273273
},
274274

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

334-
$(this.focussedElement).focus();
334+
$(this.focussedElement).trigger('focus');
335335
this._destroyOverlay();
336336
this._unsetActive();
337337
_.defer(trigger, this);

app/design/adminhtml/Magento/backend/web/js/theme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ define('globalNavigation', [
224224

225225
if (e.which === 13) {
226226
this._close(e);
227-
$(selectors.topLevelHref, menuItem).focus();
227+
$(selectors.topLevelHref, menuItem).trigger('focus');
228228
}
229229
},
230230

dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/region-updater.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ define([
159159
});
160160
it('Check that region list is not displayed when selected country has no predefined regions', function () {
161161
init();
162-
$(countryEl).val('GB').change();
162+
$(countryEl).val('GB').trigger('change');
163163
expect($(regionInputEl).is(':visible')).toBe(true);
164164
expect($(regionInputEl).is(':disabled')).toBe(false);
165165
expect($(regionSelectEl).is(':visible')).toBe(false);
166166
expect($(regionSelectEl).is(':disabled')).toBe(true);
167167
});
168168
it('Check country that has predefined and optional regions', function () {
169169
init();
170-
$(countryEl).val('DE').change();
170+
$(countryEl).val('DE').trigger('change');
171171
expect($(regionSelectEl).is(':visible')).toBe(true);
172172
expect($(regionSelectEl).is(':disabled')).toBe(false);
173173
expect($(regionSelectEl).hasClass('required-entry')).toBe(false);
@@ -182,7 +182,7 @@ define([
182182
});
183183
it('Check country that has predefined and required regions', function () {
184184
init();
185-
$(countryEl).val('US').change();
185+
$(countryEl).val('US').trigger('change');
186186
expect($(regionSelectEl).is(':visible')).toBe(true);
187187
expect($(regionSelectEl).is(':disabled')).toBe(false);
188188
expect($(regionSelectEl).hasClass('required-entry')).toBe(true);
@@ -199,7 +199,7 @@ define([
199199
init({
200200
optionalRegionAllowed: false
201201
});
202-
$(countryEl).val('DE').change();
202+
$(countryEl).val('DE').trigger('change');
203203
expect($(regionSelectEl).is(':visible')).toBe(false);
204204
expect($(regionInputEl).is(':visible')).toBe(false);
205205
});
@@ -226,7 +226,7 @@ define([
226226
$(countryEl).val('GB');
227227
$(regionInputEl).val('Liverpool');
228228
init();
229-
$(countryEl).val('IT').change();
229+
$(countryEl).val('IT').trigger('change');
230230
expect($(countryEl).val()).toBe('IT');
231231
expect($(regionInputEl).val()).toBe('');
232232
});
@@ -235,7 +235,7 @@ define([
235235
init({
236236
defaultRegion: '2'
237237
});
238-
$(countryEl).val('DE').change();
238+
$(countryEl).val('DE').trigger('change');
239239
expect($(countryEl).val()).toBe('DE');
240240
expect($(regionSelectEl).val()).toBe('');
241241
});

dev/tests/js/jasmine/tests/app/code/Magento/PageCache/frontend/js/page-cache.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ define([
185185
patternPlaceholderClose: /^ \/BLOCK (.+) $/
186186
}
187187
};
188+
// eslint-disable-next-line jquery-no-bind-unbind
188189
replacer = $.mage.pageCache.prototype._replacePlaceholder.bind(context);
190+
// eslint-disable-next-line jquery-no-bind-unbind
189191
searcher = $.mage.pageCache.prototype._searchPlaceholders.bind(context);
190192

191193
wdContainer
@@ -208,7 +210,9 @@ define([
208210
patternPlaceholderClose: /^ \/BLOCK (.+) $/
209211
}
210212
};
213+
// eslint-disable-next-line jquery-no-bind-unbind
211214
replacer = $.mage.pageCache.prototype._replacePlaceholder.bind(context);
215+
// eslint-disable-next-line jquery-no-bind-unbind
212216
searcher = $.mage.pageCache.prototype._searchPlaceholders.bind(context);
213217

214218
wdContainer

dev/tests/js/jasmine/tests/lib/mage/backend/bootstrap.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ define([
2525
$pageMainActions.appendTo('body');
2626
$('body').notification();
2727

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

3031
expect($('.message-error').length).toBe(1);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": [
33
"./.eslintrc-reset",
4-
"./.eslintrc-magento"
4+
"./.eslintrc-magento",
5+
"./.eslintrc-jquery"
56
]
6-
}
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"rules": {
3+
"jquery-no-andSelf": 2,
4+
"jquery-no-bind-unbind": 2,
5+
"jquery-no-click-event-shorthand": 2,
6+
"jquery-no-delegate-undelegate": 2,
7+
"jquery-no-event-shorthand": 2,
8+
"jquery-no-size": 2,
9+
"jquery-no-trim": 2
10+
}
11+
}

dev/tests/static/testsuite/Magento/Test/Js/_files/eslint/.eslintrc-reset

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
{
22
// http://eslint.org/docs/rules/
33

4-
"ecmaFeatures": {
5-
"binaryLiterals": false, // enable binary literals
6-
"blockBindings": false, // enable let and const (aka block bindings)
7-
"defaultParams": false, // enable default function parameters
8-
"forOf": false, // enable for-of loops
9-
"generators": false, // enable generators
10-
"objectLiteralComputedProperties": false, // enable computed object literal property names
11-
"objectLiteralDuplicateProperties": false, // enable duplicate object literal properties in strict mode
12-
"objectLiteralShorthandMethods": false, // enable object literal shorthand methods
13-
"objectLiteralShorthandProperties": false, // enable object literal shorthand properties
14-
"octalLiterals": false, // enable octal literals
15-
"regexUFlag": false, // enable the regular expression u flag
16-
"regexYFlag": false, // enable the regular expression y flag
17-
"templateStrings": false, // enable template strings
18-
"unicodeCodePointEscapes": false, // enable code point escapes
19-
"jsx": false // enable JSX
4+
"parserOptions": {
5+
"ecmaFeatures": {
6+
"binaryLiterals": false, // enable binary literals
7+
"blockBindings": false, // enable let and const (aka block bindings)
8+
"defaultParams": false, // enable default function parameters
9+
"forOf": false, // enable for-of loops
10+
"generators": false, // enable generators
11+
"objectLiteralComputedProperties": false, // enable computed object literal property names
12+
"objectLiteralDuplicateProperties": false, // enable duplicate object literal properties in strict mode
13+
"objectLiteralShorthandMethods": false, // enable object literal shorthand methods
14+
"objectLiteralShorthandProperties": false, // enable object literal shorthand properties
15+
"octalLiterals": false, // enable octal literals
16+
"regexUFlag": false, // enable the regular expression u flag
17+
"regexYFlag": false, // enable the regular expression y flag
18+
"templateStrings": false, // enable template strings
19+
"unicodeCodePointEscapes": false, // enable code point escapes
20+
"jsx": false // enable JSX
21+
},
2022
},
2123

2224
"env": {
@@ -214,4 +216,4 @@
214216
"no-bitwise": 0, // disallow use of bitwise operators (off by default)
215217
"no-plusplus": 0 // disallow use of unary operators, ++ and -- (off by default)
216218
}
217-
}
219+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const utils = require('./utils.js')
4+
5+
module.exports = {
6+
meta: {
7+
docs: {},
8+
schema: []
9+
},
10+
11+
create: function(context) {
12+
return {
13+
CallExpression: function(node) {
14+
if (node.callee.type !== 'MemberExpression') return
15+
if (node.callee.property.name !== 'andSelf') return
16+
17+
if (utils.isjQuery(node)) {
18+
context.report({
19+
node: node,
20+
message: 'jQuery.andSelf() removed, use jQuery.addBack()'
21+
})
22+
}
23+
}
24+
}
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const utils = require('./utils.js')
4+
5+
module.exports = {
6+
meta: {
7+
docs: {},
8+
schema: []
9+
},
10+
11+
create: function(context) {
12+
return {
13+
CallExpression: function(node) {
14+
if (node.callee.type !== 'MemberExpression') return
15+
if (!['bind', 'unbind'].includes(node.callee.property.name)) return
16+
17+
if (utils.isjQuery(node)) {
18+
context.report({
19+
node: node,
20+
message: 'jQuery $.bind and $.unbind are deprecated, use $.on and $.off instead'
21+
})
22+
}
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)