Skip to content

Commit 504f80d

Browse files
authored
feat(lint): unify/simplify typeof operator usage
Modernize code using eslint advisory introduced in GH-2596. This PR focuses on fixing unicorn/no-typeof-undefined rule with some related changes done manually
1 parent 7498343 commit 504f80d

26 files changed

+109
-110
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ module.exports = {
148148
'unicorn/no-hex-escape': 'off',
149149
'unicorn/no-instanceof-array': 'off',
150150
'unicorn/no-process-exit': 'off',
151-
'unicorn/no-typeof-undefined': 'off',
152151
'unicorn/no-useless-switch-case': 'off',
153152
'unicorn/no-useless-undefined': 'off',
154153
'unicorn/prefer-array-find': 'off',

src/definitions/behaviors/api.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
2020
}
2121

22-
window = (typeof window != 'undefined' && window.Math == Math)
22+
window = (window !== undefined && window.Math === Math)
2323
? window
2424
: globalThis;
2525

@@ -34,7 +34,7 @@
3434
performance = [],
3535

3636
query = arguments[0],
37-
methodInvoked = (typeof query == 'string'),
37+
methodInvoked = (typeof query === 'string'),
3838
queryArguments = [].slice.call(arguments, 1),
3939

4040
returnedValue
@@ -126,7 +126,7 @@
126126

127127
decode: {
128128
json: function (response) {
129-
if (response !== undefined && typeof response == 'string') {
129+
if (response !== undefined && typeof response === 'string') {
130130
try {
131131
response = JSON.parse(response);
132132
} catch (e) {
@@ -431,8 +431,8 @@
431431

432432
if (useFormDataApi) {
433433
formData = new FormData($form[0]);
434-
settings.processData = typeof settings.processData !== 'undefined' ? settings.processData : false;
435-
settings.contentType = typeof settings.contentType !== 'undefined' ? settings.contentType : false;
434+
settings.processData = settings.processData !== undefined ? settings.processData : false;
435+
settings.contentType = settings.contentType !== undefined ? settings.contentType : false;
436436
} else {
437437
var
438438
formArray = $form.serializeArray(),
@@ -1000,7 +1000,7 @@
10001000
;
10011001
passedArguments = passedArguments || queryArguments;
10021002
context = context || element;
1003-
if (typeof query == 'string' && object !== undefined) {
1003+
if (typeof query === 'string' && object !== undefined) {
10041004
query = query.split(/[\. ]/);
10051005
maxDepth = query.length - 1;
10061006
$.each(query, function (depth, value) {

src/definitions/behaviors/form.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (typeof window != 'undefined' && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -29,7 +29,7 @@
2929

3030
query = arguments[0],
3131
legacyParameters = arguments[1],
32-
methodInvoked = (typeof query == 'string'),
32+
methodInvoked = (typeof query === 'string'),
3333
queryArguments = [].slice.call(arguments, 1),
3434
returnedValue
3535
;
@@ -302,7 +302,7 @@
302302
},
303303
// duck type rule test
304304
shorthandRules: function (rules) {
305-
return (typeof rules == 'string' || Array.isArray(rules));
305+
return (typeof rules === 'string' || Array.isArray(rules));
306306
},
307307
empty: function ($field) {
308308
if (!$field || $field.length === 0) {
@@ -507,7 +507,7 @@
507507
if (!Array.isArray(rules) && typeof rules === 'object') {
508508
fullFields[name] = rules;
509509
} else {
510-
if (typeof rules == 'string') {
510+
if (typeof rules === 'string') {
511511
rules = [rules];
512512
}
513513
fullFields[name] = {
@@ -873,7 +873,7 @@
873873
$prompt = $fieldGroup.children(selector.prompt),
874874
promptExists = ($prompt.length !== 0)
875875
;
876-
errors = (typeof errors == 'string')
876+
errors = (typeof errors === 'string')
877877
? [errors]
878878
: errors;
879879
module.verbose('Adding field error state', identifier);
@@ -1229,7 +1229,7 @@
12291229
showErrors = (showErrors !== undefined)
12301230
? showErrors
12311231
: true;
1232-
if (typeof field == 'string') {
1232+
if (typeof field === 'string') {
12331233
module.verbose('Validating field', field);
12341234
fieldName = field;
12351235
field = validation[field];
@@ -1436,7 +1436,7 @@
14361436
;
14371437
passedArguments = passedArguments || queryArguments;
14381438
context = context || element;
1439-
if (typeof query == 'string' && object !== undefined) {
1439+
if (typeof query === 'string' && object !== undefined) {
14401440
query = query.split(/[\. ]/);
14411441
maxDepth = query.length - 1;
14421442
$.each(query, function (depth, value) {
@@ -1732,7 +1732,7 @@
17321732
return $.fn.form.settings.rules.range(value, range, 'integer');
17331733
},
17341734
range: function (value, range, regExp) {
1735-
if (typeof regExp == 'string') {
1735+
if (typeof regExp === 'string') {
17361736
regExp = $.fn.form.settings.regExp[regExp];
17371737
}
17381738
if (!(regExp instanceof RegExp)) {
@@ -1778,10 +1778,10 @@
17781778

17791779
// is value (case insensitive)
17801780
is: function (value, text) {
1781-
text = (typeof text == 'string')
1781+
text = (typeof text === 'string')
17821782
? text.toLowerCase()
17831783
: text;
1784-
value = (typeof value == 'string')
1784+
value = (typeof value === 'string')
17851785
? value.toLowerCase()
17861786
: value;
17871787

@@ -1795,10 +1795,10 @@
17951795

17961796
// value is not another value (case insensitive)
17971797
not: function (value, notValue) {
1798-
value = (typeof value == 'string')
1798+
value = (typeof value === 'string')
17991799
? value.toLowerCase()
18001800
: value;
1801-
notValue = (typeof notValue == 'string')
1801+
notValue = (typeof notValue === 'string')
18021802
? notValue.toLowerCase()
18031803
: notValue;
18041804

@@ -1952,7 +1952,7 @@
19521952
},
19531953
valid = {},
19541954
validCard = false,
1955-
requiredTypes = (typeof cardTypes == 'string')
1955+
requiredTypes = (typeof cardTypes === 'string')
19561956
? cardTypes.split(',')
19571957
: false,
19581958
unionPay,

src/definitions/behaviors/state.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (typeof window != 'undefined' && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -29,7 +29,7 @@
2929
performance = [],
3030

3131
query = arguments[0],
32-
methodInvoked = (typeof query == 'string'),
32+
methodInvoked = (typeof query === 'string'),
3333
queryArguments = [].slice.call(arguments, 1),
3434

3535
returnedValue
@@ -515,7 +515,7 @@
515515
;
516516
passedArguments = passedArguments || queryArguments;
517517
context = context || element;
518-
if (typeof query == 'string' && object !== undefined) {
518+
if (typeof query === 'string' && object !== undefined) {
519519
query = query.split(/[\. ]/);
520520
maxDepth = query.length - 1;
521521
$.each(query, function (depth, value) {

src/definitions/behaviors/visibility.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (typeof window != 'undefined' && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -28,7 +28,7 @@
2828
performance = [],
2929

3030
query = arguments[0],
31-
methodInvoked = (typeof query == 'string'),
31+
methodInvoked = (typeof query === 'string'),
3232
queryArguments = [].slice.call(arguments, 1),
3333
returnedValue,
3434

@@ -1123,7 +1123,7 @@
11231123
;
11241124
passedArguments = passedArguments || queryArguments;
11251125
context = context || element;
1126-
if (typeof query == 'string' && object !== undefined) {
1126+
if (typeof query === 'string' && object !== undefined) {
11271127
query = query.split(/[\. ]/);
11281128
maxDepth = query.length - 1;
11291129
$.each(query, function (depth, value) {

src/definitions/globals/site.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (window !== undefined && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -25,7 +25,7 @@
2525
performance = [],
2626

2727
query = arguments[0],
28-
methodInvoked = (typeof query == 'string'),
28+
methodInvoked = (typeof query === 'string'),
2929
queryArguments = [].slice.call(arguments, 1),
3030

3131
settings = ($.isPlainObject(parameters))
@@ -71,13 +71,13 @@
7171
module.verbose('Console not available, normalizing events');
7272
module.disable.console();
7373
}
74-
if (typeof console.group == 'undefined' || typeof console.groupEnd == 'undefined' || typeof console.groupCollapsed == 'undefined') {
74+
if (console.group === undefined || console.groupEnd === undefined || console.groupCollapsed === undefined) {
7575
module.verbose('Console group not available, normalizing events');
7676
window.console.group = function () {};
7777
window.console.groupEnd = function () {};
7878
window.console.groupCollapsed = function () {};
7979
}
80-
if (typeof console.markTimeline == 'undefined') {
80+
if (console.markTimeline === undefined) {
8181
module.verbose('Mark timeline not available, normalizing events');
8282
window.console.markTimeline = function () {};
8383
}
@@ -357,7 +357,7 @@
357357
;
358358
passedArguments = passedArguments || queryArguments;
359359
context = context || element;
360-
if (typeof query == 'string' && object !== undefined) {
360+
if (typeof query === 'string' && object !== undefined) {
361361
query = query.split(/[\. ]/);
362362
maxDepth = query.length - 1;
363363
$.each(query, function (depth, value) {

src/definitions/modules/accordion.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (typeof window != 'undefined' && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -27,7 +27,7 @@
2727
performance = [],
2828

2929
query = arguments[0],
30-
methodInvoked = (typeof query == 'string'),
30+
methodInvoked = (typeof query === 'string'),
3131
queryArguments = [].slice.call(arguments, 1),
3232

3333
returnedValue
@@ -478,7 +478,7 @@
478478
;
479479
passedArguments = passedArguments || queryArguments;
480480
context = context || element;
481-
if (typeof query == 'string' && object !== undefined) {
481+
if (typeof query === 'string' && object !== undefined) {
482482
query = query.split(/[\. ]/);
483483
maxDepth = query.length - 1;
484484
$.each(query, function (depth, value) {

src/definitions/modules/calendar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (typeof window != 'undefined' && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -30,7 +30,7 @@
3030
performance = [],
3131

3232
query = arguments[0],
33-
methodInvoked = (typeof query == 'string'),
33+
methodInvoked = (typeof query === 'string'),
3434
queryArguments = [].slice.call(arguments, 1),
3535
returnedValue,
3636
timeGapTable = {
@@ -1486,7 +1486,7 @@
14861486
;
14871487
passedArguments = passedArguments || queryArguments;
14881488
context = context || element;
1489-
if (typeof query == 'string' && object !== undefined) {
1489+
if (typeof query === 'string' && object !== undefined) {
14901490
query = query.split(/[\. ]/);
14911491
maxDepth = query.length - 1;
14921492
$.each(query, function (depth, value) {

src/definitions/modules/checkbox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (typeof window != 'undefined' && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -28,7 +28,7 @@
2828
performance = [],
2929

3030
query = arguments[0],
31-
methodInvoked = (typeof query == 'string'),
31+
methodInvoked = (typeof query === 'string'),
3232
queryArguments = [].slice.call(arguments, 1),
3333
returnedValue
3434
;
@@ -166,7 +166,7 @@
166166
},
167167

168168
preventDefaultOnInputTarget: function () {
169-
if (typeof event !== 'undefined' && event !== null && $(event.target).is(selector.input)) {
169+
if (event !== undefined && event !== null && $(event.target).is(selector.input)) {
170170
module.verbose('Preventing default check action after manual check action');
171171
event.preventDefault();
172172
}
@@ -763,7 +763,7 @@
763763
;
764764
passedArguments = passedArguments || queryArguments;
765765
context = context || element;
766-
if (typeof query == 'string' && object !== undefined) {
766+
if (typeof query === 'string' && object !== undefined) {
767767
query = query.split(/[\. ]/);
768768
maxDepth = query.length - 1;
769769
$.each(query, function (depth, value) {

src/definitions/modules/dimmer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
1616
}
1717

18-
window = (typeof window != 'undefined' && window.Math == Math)
18+
window = (window !== undefined && window.Math === Math)
1919
? window
2020
: globalThis;
2121

@@ -27,7 +27,7 @@
2727
performance = [],
2828

2929
query = arguments[0],
30-
methodInvoked = (typeof query == 'string'),
30+
methodInvoked = (typeof query === 'string'),
3131
queryArguments = [].slice.call(arguments, 1),
3232

3333
returnedValue
@@ -573,7 +573,7 @@
573573
;
574574
passedArguments = passedArguments || queryArguments;
575575
context = context || element;
576-
if (typeof query == 'string' && object !== undefined) {
576+
if (typeof query === 'string' && object !== undefined) {
577577
query = query.split(/[\. ]/);
578578
maxDepth = query.length - 1;
579579
$.each(query, function (depth, value) {

0 commit comments

Comments
 (0)