From 5bc8e82b5cce42ca0b157cfb6f9257b8d5bbcce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 16 Dec 2022 15:19:03 +0100 Subject: [PATCH 1/3] strictly autofix no-var rule --- .eslintrc.js | 1 - src/definitions/behaviors/api.js | 50 ++-- src/definitions/behaviors/form.js | 116 ++++----- src/definitions/behaviors/state.js | 22 +- src/definitions/behaviors/visibility.js | 64 ++--- src/definitions/globals/site.js | 18 +- src/definitions/modules/accordion.js | 24 +- src/definitions/modules/calendar.js | 310 ++++++++++++------------ src/definitions/modules/checkbox.js | 28 +-- src/definitions/modules/dimmer.js | 20 +- src/definitions/modules/dropdown.js | 234 +++++++++--------- src/definitions/modules/embed.js | 34 +-- src/definitions/modules/flyout.js | 76 +++--- src/definitions/modules/modal.js | 82 +++---- src/definitions/modules/nag.js | 32 +-- src/definitions/modules/popup.js | 40 +-- src/definitions/modules/progress.js | 76 +++--- src/definitions/modules/rating.js | 26 +- src/definitions/modules/search.js | 82 +++---- src/definitions/modules/shape.js | 46 ++-- src/definitions/modules/sidebar.js | 46 ++-- src/definitions/modules/slider.js | 106 ++++---- src/definitions/modules/sticky.js | 28 +-- src/definitions/modules/tab.js | 52 ++-- src/definitions/modules/toast.js | 32 +-- src/definitions/modules/transition.js | 44 ++-- 26 files changed, 844 insertions(+), 845 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 63bf21aef7..c71a4d8810 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -91,7 +91,6 @@ module.exports = { 'guard-for-in': 'off', // refactor to "for of" 'no-restricted-globals': 'off', 'no-restricted-properties': 'off', - 'no-var': 'off', // https://github.com/fomantic/Fomantic-UI/pull/2584 'one-var': 'off', 'prefer-const': 'off', 'prefer-exponentiation-operator': 'off', diff --git a/src/definitions/behaviors/api.js b/src/definitions/behaviors/api.js index 5704776e12..c1c2598290 100644 --- a/src/definitions/behaviors/api.js +++ b/src/definitions/behaviors/api.js @@ -24,7 +24,7 @@ : globalThis; $.fn.api = function (parameters) { - var + let // use window context if none specified $allModules = isFunction(this) ? $(window) @@ -41,7 +41,7 @@ ; $allModules.each(function () { - var + let settings = $.isPlainObject(parameters) ? $.extend(true, {}, $.fn.api.settings, parameters) : $.extend({}, $.fn.api.settings), @@ -109,7 +109,7 @@ bind: { events: function () { - var + let triggerEvent = module.get.event() ; if (triggerEvent) { @@ -140,7 +140,7 @@ read: { cachedResponse: function (url) { - var + let response ; if (window.Storage === undefined) { @@ -346,7 +346,7 @@ add: { urlData: function (url, urlData) { - var + let requiredVariables, optionalVariables ; @@ -357,7 +357,7 @@ if (requiredVariables) { module.debug('Looking for required URL variables', requiredVariables); $.each(requiredVariables, function (index, templatedString) { - var + let // allow legacy {$var} style variable = templatedString.indexOf('$') !== -1 ? templatedString.slice(2, -1) @@ -388,7 +388,7 @@ if (optionalVariables) { module.debug('Looking for optional URL variables', requiredVariables); $.each(optionalVariables, function (index, templatedString) { - var + let // allow legacy {/$var} style variable = templatedString.indexOf('$') !== -1 ? templatedString.slice(3, -1) @@ -419,7 +419,7 @@ return url; }, formData: function (data) { - var + let formData = {}, hasOtherData, useFormDataApi = settings.serializeForm === 'formdata' @@ -432,7 +432,7 @@ settings.processData = settings.processData !== undefined ? settings.processData : false; settings.contentType = settings.contentType !== undefined ? settings.contentType : false; } else { - var + let formArray = $form.serializeArray(), pushes = {}, pushValues = {}, @@ -452,7 +452,7 @@ if (!settings.regExp.validate.test(el.name)) { return; } - var + let isCheckbox = $('[name="' + el.name + '"]', $form).attr('type') === 'checkbox', floatValue = parseFloat(el.value), value = (isCheckbox && el.value === 'on') @@ -476,7 +476,7 @@ } while (nameKeys.length > 0) { - var k = nameKeys.pop(); + let k = nameKeys.pop(); if (k === '' && !Array.isArray(value)) { // foo[] value = build([], pushes[pushKey]++, value); @@ -534,7 +534,7 @@ // nothing special }, done: function (response, textStatus, xhr) { - var + let context = this, elapsedTime = Date.now() - requestStartTime, timeLeft = settings.loadingDuration - elapsedTime, @@ -563,7 +563,7 @@ }, timeLeft); }, fail: function (xhr, status, httpMessage) { - var + let context = this, elapsedTime = Date.now() - requestStartTime, timeLeft = settings.loadingDuration - elapsedTime @@ -593,7 +593,7 @@ settings.onSuccess.call(context, response, $module, xhr); }, complete: function (firstParameter, secondParameter) { - var + let xhr, response ; @@ -609,7 +609,7 @@ settings.onComplete.call(context, response, $module, xhr); }, fail: function (xhr, status, httpMessage) { - var + let // pull response from xhr if available response = module.get.responseFromXHR(xhr), errorMessage = module.get.errorFromRequest(response, status, httpMessage) @@ -658,7 +658,7 @@ }, mockedXHR: function () { - var + let // xhr does not simulate these properties of xhr but must return them textStatus = false, status = false, @@ -704,7 +704,7 @@ }, xhr: function () { - var + let xhr ; // ajax request promise @@ -767,7 +767,7 @@ return module.xhr || false; }, settings: function () { - var + let runSettings ; runSettings = settings.beforeSend.call($module, settings); @@ -800,7 +800,7 @@ : $.extend(true, {}, settings); }, urlEncodedValue: function (value) { - var + let decodedValue = window.decodeURIComponent(value), encodedValue = window.encodeURIComponent(value), alreadyEncoded = decodedValue !== value @@ -815,7 +815,7 @@ return encodedValue; }, defaultData: function () { - var + let data = {} ; if (!isWindow(element)) { @@ -877,7 +877,7 @@ }, abort: function () { - var + let xhr = module.get.xhr() ; if (xhr && xhr.state() !== 'resolved') { @@ -943,7 +943,7 @@ }, performance: { log: function (message) { - var + let currentTime, executionTime, previousTime @@ -964,7 +964,7 @@ module.performance.timer = setTimeout(module.performance.display, 500); }, display: function () { - var + let title = settings.name + ':', totalTime = 0 ; @@ -992,7 +992,7 @@ }, }, invoke: function (query, passedArguments, context) { - var + let object = instance, maxDepth, found, @@ -1004,7 +1004,7 @@ query = query.split(/[ .]/); maxDepth = query.length - 1; $.each(query, function (depth, value) { - var camelCaseValue = depth !== maxDepth + let camelCaseValue = depth !== maxDepth ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1) : query ; diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index d86c8fb619..e5a9b00b8b 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -20,7 +20,7 @@ : globalThis; $.fn.form = function (parameters) { - var + let $allModules = $(this), moduleSelector = $allModules.selector || '', @@ -34,7 +34,7 @@ returnedValue ; $allModules.each(function () { - var + let $module = $(this), element = this, @@ -159,7 +159,7 @@ $module.on('keydown' + eventNamespace, selector.field, module.event.field.keydown); } $field.each(function (index, el) { - var + let $input = $(el), type = $input.prop('type'), inputEvent = module.get.changeEvent(type, $input) @@ -187,7 +187,7 @@ clear: function () { $field.each(function (index, el) { - var + let $field = $(el), $element = $field.parent(), $fieldGroup = $field.closest($group), @@ -221,7 +221,7 @@ reset: function () { $field.each(function (index, el) { - var + let $field = $(el), $element = $field.parent(), $fieldGroup = $field.closest($group), @@ -259,7 +259,7 @@ determine: { isValid: function () { - var + let allValid = true ; $.each(validation, function (fieldName, field) { @@ -271,10 +271,10 @@ return allValid; }, isDirty: function (e) { - var formIsDirty = false; + let formIsDirty = false; $field.each(function (index, el) { - var + let $el = $(el), isCheckbox = $el.filter(selector.checkbox).length > 0, isDirty @@ -319,7 +319,7 @@ return String($field.val()).trim() === ''; }, valid: function (field, showErrors) { - var + let allValid = true ; if (field) { @@ -344,14 +344,14 @@ return !dirty; }, fieldDirty: function ($el) { - var initialValue = $el.data(metadata.defaultValue); + let initialValue = $el.data(metadata.defaultValue); // Explicitly check for undefined/null here as value may be `false`, so ($el.data(dataInitialValue) || '') would not work if (initialValue === undefined || initialValue === null) { initialValue = ''; } else if (Array.isArray(initialValue)) { initialValue = initialValue.toString(); } - var currentValue = $el.val(); + let currentValue = $el.val(); if (currentValue === undefined || currentValue === null) { currentValue = ''; } else if (Array.isArray(currentValue)) { @@ -359,10 +359,10 @@ currentValue = currentValue.toString(); } // Boolean values can be encoded as "true/false" or "True/False" depending on underlying frameworks so we need a case insensitive comparison - var boolRegex = /^(true|false)$/i; - var isBoolValue = boolRegex.test(initialValue) && boolRegex.test(currentValue); + let boolRegex = /^(true|false)$/i; + let isBoolValue = boolRegex.test(initialValue) && boolRegex.test(currentValue); if (isBoolValue) { - var regex = new RegExp('^' + initialValue + '$', 'i'); + let regex = new RegExp('^' + initialValue + '$', 'i'); return !regex.test(currentValue); } @@ -370,8 +370,8 @@ return currentValue !== initialValue; }, checkboxDirty: function ($el) { - var initialValue = $el.data(metadata.defaultValue); - var currentValue = $el.is(':checked'); + let initialValue = $el.data(metadata.defaultValue); + let currentValue = $el.is(':checked'); return initialValue !== currentValue; }, @@ -392,7 +392,7 @@ event: { field: { keydown: function (event) { - var + let $field = $(this), key = event.which, isInput = $field.is(selector.input), @@ -423,7 +423,7 @@ keyHeldDown = false; }, blur: function (event) { - var + let $field = $(this), $fieldGroup = $field.closest($group), validationRules = module.get.validation($field) @@ -437,7 +437,7 @@ } }, change: function (event) { - var + let $field = $(this), $fieldGroup = $field.closest($group), validationRules = module.get.validation($field) @@ -502,7 +502,7 @@ : 'keyup'); }, fieldsFromShorthand: function (fields) { - var + let fullFields = {} ; $.each(fields, function (name, rules) { @@ -524,7 +524,7 @@ return fullFields; }, prompt: function (rule, field) { - var + let ruleName = module.get.ruleName(rule), ancillary = module.get.ancillaryValue(rule), $field = module.get.field(field.identifier), @@ -572,7 +572,7 @@ }, settings: function () { if ($.isPlainObject(parameters)) { - var + let keys = Object.keys(parameters), isLegacySettings = keys.length > 0 ? parameters[keys[0]].identifier !== undefined && parameters[keys[0]].rules !== undefined @@ -618,7 +618,7 @@ field: function (identifier) { module.verbose('Finding field with identifier', identifier); identifier = module.escape.string(identifier); - var t; + let t; t = $field.filter('#' + identifier); if (t.length > 0) { return t; @@ -640,7 +640,7 @@ return $(''); }, fields: function (fields) { - var + let $fields = $() ; $.each(fields, function (index, name) { @@ -650,7 +650,7 @@ return $fields; }, validation: function ($field) { - var + let fieldValidation, identifier ; @@ -672,7 +672,7 @@ return fieldValidation || false; }, value: function (field) { - var + let fields = [], results ; @@ -682,14 +682,14 @@ return results[field]; }, values: function (fields) { - var + let $fields = Array.isArray(fields) ? module.get.fields(fields) : $field, values = {} ; $fields.each(function (index, field) { - var + let $field = $(field), $calendar = $field.closest(selector.uiCalendar), name = $field.prop('name'), @@ -727,7 +727,7 @@ } else if (isCheckbox) { values[name] = isChecked ? value || true : false; } else if (isCalendar) { - var date = $calendar.calendar('get date'); + let date = $calendar.calendar('get date'); if (date !== null) { switch (settings.dateHandling) { @@ -742,7 +742,7 @@ break; } case 'formatter': { - var type = $calendar.calendar('setting', 'type'); + let type = $calendar.calendar('setting', 'type'); switch (type) { case 'date': { @@ -847,7 +847,7 @@ rules: [], }; } - var + let newValidation = { rules: [], } @@ -878,7 +878,7 @@ module.refreshEvents(); }, prompt: function (identifier, errors, internal) { - var + let $field = module.get.field(identifier), $fieldGroup = $field.closest($group), $prompt = $fieldGroup.children(selector.prompt), @@ -940,7 +940,7 @@ module.determine.isDirty(); }, rule: function (field, rule) { - var + let rules = Array.isArray(rule) ? rule : [rule] @@ -962,7 +962,7 @@ }); }, field: function (field) { - var + let fields = Array.isArray(field) ? field : [field] @@ -986,7 +986,7 @@ module.remove.field(fields); }, prompt: function (identifier) { - var + let $field = module.get.field(identifier), $fieldGroup = $field.closest($group), $prompt = $fieldGroup.children(selector.prompt) @@ -1020,7 +1020,7 @@ }, defaults: function () { $field.each(function (index, el) { - var + let $el = $(el), $parent = $el.parent(), isCheckbox = $el.filter(selector.checkbox).length > 0, @@ -1047,7 +1047,7 @@ ; }, value: function (field, value) { - var + let fields = {} ; fields[field] = value; @@ -1059,7 +1059,7 @@ return; } $.each(fields, function (key, value) { - var + let $field = module.get.field(key), $element = $field.parent(), $calendar = $field.closest(selector.uiCalendar), @@ -1141,7 +1141,7 @@ autoCheck: function () { module.debug('Enabling auto check on required fields'); $field.each(function (_index, el) { - var + let $el = $(el), $elGroup = $el.closest($group), isCheckbox = $el.filter(selector.checkbox).length > 0, @@ -1179,7 +1179,7 @@ validate: { form: function (event, ignoreCallbacks) { - var values = module.get.values(); + let values = module.get.values(); // input keydown event will fire submit repeatedly by browser default if (keyHeldDown) { @@ -1209,7 +1209,7 @@ event.stopImmediatePropagation(); } if (settings.errorFocus && ignoreCallbacks !== true) { - var + let $focusElement, hasTabIndex = true ; @@ -1245,7 +1245,7 @@ fieldName = field; field = validation[field]; } - var + let identifier = field.identifier || fieldName, $field = module.get.field(identifier), $dependsField = field.depends @@ -1258,7 +1258,7 @@ module.debug('Using field name as identifier', identifier); field.identifier = identifier; } - var isDisabled = $field.filter(':not(:disabled)').length === 0; + let isDisabled = $field.filter(':not(:disabled)').length === 0; if (isDisabled) { module.debug('Field is disabled. Skipping', identifier); } else if (field.optional && module.is.blank($field)) { @@ -1271,7 +1271,7 @@ } $.each(field.rules, function (index, rule) { if (module.has.field(identifier)) { - var invalidFields = module.validate.rule(field, rule, true) || []; + let invalidFields = module.validate.rule(field, rule, true) || []; if (invalidFields.length > 0) { module.debug('Field is invalid', identifier, rule.type); fieldErrors.push(module.get.prompt(rule, field)); @@ -1303,7 +1303,7 @@ // takes validation rule and returns whether field passes rule rule: function (field, rule, internal) { - var + let $field = module.get.field(field.identifier), ancillary = module.get.ancillaryValue(rule), ruleName = module.get.ruleName(rule), @@ -1311,7 +1311,7 @@ invalidFields = [], isCheckbox = $field.is(selector.checkbox), isValid = function (field) { - var value = isCheckbox ? $(field).filter(':checked').val() : $(field).val(); + let value = isCheckbox ? $(field).filter(':checked').val() : $(field).val(); // cast to string avoiding encoding special values value = value === undefined || value === '' || value === null ? '' @@ -1389,7 +1389,7 @@ }, performance: { log: function (message) { - var + let currentTime, executionTime, previousTime @@ -1410,7 +1410,7 @@ module.performance.timer = setTimeout(module.performance.display, 500); }, display: function () { - var + let title = settings.name + ':', totalTime = 0 ; @@ -1441,7 +1441,7 @@ }, }, invoke: function (query, passedArguments, context) { - var + let object = instance, maxDepth, found, @@ -1453,7 +1453,7 @@ query = query.split(/[ .]/); maxDepth = query.length - 1; $.each(query, function (depth, value) { - var camelCaseValue = depth !== maxDepth + let camelCaseValue = depth !== maxDepth ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1) : query; if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) { @@ -1629,7 +1629,7 @@ // template that produces error message error: function (errors) { - var + let html = '