Skip to content

Commit

Permalink
feat(lint): unify/simplify typeof operator usage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mvorisek authored Dec 12, 2022
1 parent 7498343 commit 504f80d
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 110 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ module.exports = {
'unicorn/no-hex-escape': 'off',
'unicorn/no-instanceof-array': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/no-typeof-undefined': 'off',
'unicorn/no-useless-switch-case': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/prefer-array-find': 'off',
Expand Down
12 changes: 6 additions & 6 deletions src/definitions/behaviors/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -34,7 +34,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),

returnedValue
Expand Down Expand Up @@ -126,7 +126,7 @@

decode: {
json: function (response) {
if (response !== undefined && typeof response == 'string') {
if (response !== undefined && typeof response === 'string') {
try {
response = JSON.parse(response);
} catch (e) {
Expand Down Expand Up @@ -431,8 +431,8 @@

if (useFormDataApi) {
formData = new FormData($form[0]);
settings.processData = typeof settings.processData !== 'undefined' ? settings.processData : false;
settings.contentType = typeof settings.contentType !== 'undefined' ? settings.contentType : false;
settings.processData = settings.processData !== undefined ? settings.processData : false;
settings.contentType = settings.contentType !== undefined ? settings.contentType : false;
} else {
var
formArray = $form.serializeArray(),
Expand Down Expand Up @@ -1000,7 +1000,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
26 changes: 13 additions & 13 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -29,7 +29,7 @@

query = arguments[0],
legacyParameters = arguments[1],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),
returnedValue
;
Expand Down Expand Up @@ -302,7 +302,7 @@
},
// duck type rule test
shorthandRules: function (rules) {
return (typeof rules == 'string' || Array.isArray(rules));
return (typeof rules === 'string' || Array.isArray(rules));
},
empty: function ($field) {
if (!$field || $field.length === 0) {
Expand Down Expand Up @@ -507,7 +507,7 @@
if (!Array.isArray(rules) && typeof rules === 'object') {
fullFields[name] = rules;
} else {
if (typeof rules == 'string') {
if (typeof rules === 'string') {
rules = [rules];
}
fullFields[name] = {
Expand Down Expand Up @@ -873,7 +873,7 @@
$prompt = $fieldGroup.children(selector.prompt),
promptExists = ($prompt.length !== 0)
;
errors = (typeof errors == 'string')
errors = (typeof errors === 'string')
? [errors]
: errors;
module.verbose('Adding field error state', identifier);
Expand Down Expand Up @@ -1229,7 +1229,7 @@
showErrors = (showErrors !== undefined)
? showErrors
: true;
if (typeof field == 'string') {
if (typeof field === 'string') {
module.verbose('Validating field', field);
fieldName = field;
field = validation[field];
Expand Down Expand Up @@ -1436,7 +1436,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down Expand Up @@ -1732,7 +1732,7 @@
return $.fn.form.settings.rules.range(value, range, 'integer');
},
range: function (value, range, regExp) {
if (typeof regExp == 'string') {
if (typeof regExp === 'string') {
regExp = $.fn.form.settings.regExp[regExp];
}
if (!(regExp instanceof RegExp)) {
Expand Down Expand Up @@ -1778,10 +1778,10 @@

// is value (case insensitive)
is: function (value, text) {
text = (typeof text == 'string')
text = (typeof text === 'string')
? text.toLowerCase()
: text;
value = (typeof value == 'string')
value = (typeof value === 'string')
? value.toLowerCase()
: value;

Expand All @@ -1795,10 +1795,10 @@

// value is not another value (case insensitive)
not: function (value, notValue) {
value = (typeof value == 'string')
value = (typeof value === 'string')
? value.toLowerCase()
: value;
notValue = (typeof notValue == 'string')
notValue = (typeof notValue === 'string')
? notValue.toLowerCase()
: notValue;

Expand Down Expand Up @@ -1952,7 +1952,7 @@
},
valid = {},
validCard = false,
requiredTypes = (typeof cardTypes == 'string')
requiredTypes = (typeof cardTypes === 'string')
? cardTypes.split(',')
: false,
unionPay,
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/behaviors/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -29,7 +29,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),

returnedValue
Expand Down Expand Up @@ -515,7 +515,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/behaviors/visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -28,7 +28,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),
returnedValue,

Expand Down Expand Up @@ -1123,7 +1123,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
10 changes: 5 additions & 5 deletions src/definitions/globals/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (window !== undefined && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -25,7 +25,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),

settings = ($.isPlainObject(parameters))
Expand Down Expand Up @@ -71,13 +71,13 @@
module.verbose('Console not available, normalizing events');
module.disable.console();
}
if (typeof console.group == 'undefined' || typeof console.groupEnd == 'undefined' || typeof console.groupCollapsed == 'undefined') {
if (console.group === undefined || console.groupEnd === undefined || console.groupCollapsed === undefined) {
module.verbose('Console group not available, normalizing events');
window.console.group = function () {};
window.console.groupEnd = function () {};
window.console.groupCollapsed = function () {};
}
if (typeof console.markTimeline == 'undefined') {
if (console.markTimeline === undefined) {
module.verbose('Mark timeline not available, normalizing events');
window.console.markTimeline = function () {};
}
Expand Down Expand Up @@ -357,7 +357,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/modules/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -27,7 +27,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),

returnedValue
Expand Down Expand Up @@ -478,7 +478,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/modules/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -30,7 +30,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),
returnedValue,
timeGapTable = {
Expand Down Expand Up @@ -1486,7 +1486,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
8 changes: 4 additions & 4 deletions src/definitions/modules/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -28,7 +28,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),
returnedValue
;
Expand Down Expand Up @@ -166,7 +166,7 @@
},

preventDefaultOnInputTarget: function () {
if (typeof event !== 'undefined' && event !== null && $(event.target).is(selector.input)) {
if (event !== undefined && event !== null && $(event.target).is(selector.input)) {
module.verbose('Preventing default check action after manual check action');
event.preventDefault();
}
Expand Down Expand Up @@ -763,7 +763,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/modules/dimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
return typeof obj === 'function' && typeof obj.nodeType !== 'number';
}

window = (typeof window != 'undefined' && window.Math == Math)
window = (window !== undefined && window.Math === Math)
? window
: globalThis;

Expand All @@ -27,7 +27,7 @@
performance = [],

query = arguments[0],
methodInvoked = (typeof query == 'string'),
methodInvoked = (typeof query === 'string'),
queryArguments = [].slice.call(arguments, 1),

returnedValue
Expand Down Expand Up @@ -573,7 +573,7 @@
;
passedArguments = passedArguments || queryArguments;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
if (typeof query === 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
$.each(query, function (depth, value) {
Expand Down
Loading

0 comments on commit 504f80d

Please sign in to comment.