]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Enable `unicorn/no-for-loop` rule
authorXhmikosR <xhmikosr@gmail.com>
Tue, 10 Aug 2021 15:07:39 +0000 (18:07 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Tue, 5 Oct 2021 16:52:11 +0000 (19:52 +0300)
.eslintrc.json
js/src/carousel.js
js/src/collapse.js
js/src/dom/event-handler.js
js/src/dropdown.js
js/src/util/sanitizer.js

index 72b267691cd0212347e6cff5514f0c784f0d0f03..302c765985626a5906af7799b83feb575562c798 100644 (file)
@@ -53,7 +53,6 @@
     "unicorn/no-array-callback-reference": "off",
     "unicorn/no-array-for-each": "off",
     "unicorn/no-array-method-this-argument": "off",
-    "unicorn/no-for-loop": "off",
     "unicorn/no-null": "off",
     "unicorn/no-unused-properties": "error",
     "unicorn/numeric-separators-style": "off",
index 96812d3b6a9026af0224ffb0773c13c3de47cf27..322ad46a09f834ede66dd2bca2d77f1c3be4cf07 100644 (file)
@@ -366,10 +366,10 @@ class Carousel extends BaseComponent {
 
       const indicators = SelectorEngine.find(SELECTOR_INDICATOR, this._indicatorsElement)
 
-      for (let i = 0; i < indicators.length; i++) {
-        if (Number.parseInt(indicators[i].getAttribute('data-bs-slide-to'), 10) === this._getItemIndex(element)) {
-          indicators[i].classList.add(CLASS_NAME_ACTIVE)
-          indicators[i].setAttribute('aria-current', 'true')
+      for (const indicator of indicators) {
+        if (Number.parseInt(indicator.getAttribute('data-bs-slide-to'), 10) === this._getItemIndex(element)) {
+          indicator.classList.add(CLASS_NAME_ACTIVE)
+          indicator.setAttribute('aria-current', 'true')
           break
         }
       }
@@ -574,8 +574,8 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.da
 EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
   const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE)
 
-  for (let i = 0, len = carousels.length; i < len; i++) {
-    Carousel.carouselInterface(carousels[i], Carousel.getInstance(carousels[i]))
+  for (const carousel of carousels) {
+    Carousel.carouselInterface(carousel, Carousel.getInstance(carousel))
   }
 })
 
index 4ed0dadd6e7ec07ff5be23aa3b7bc53b7dc1f652..dd42bc7e78bb1b1ca488977ca1f483bef041b746 100644 (file)
@@ -75,8 +75,7 @@ class Collapse extends BaseComponent {
 
     const toggleList = SelectorEngine.find(SELECTOR_DATA_TOGGLE)
 
-    for (let i = 0, len = toggleList.length; i < len; i++) {
-      const elem = toggleList[i]
+    for (const elem of toggleList) {
       const selector = getSelectorFromElement(elem)
       const filterElement = SelectorEngine.find(selector)
         .filter(foundElem => foundElem === this._element)
@@ -203,9 +202,7 @@ class Collapse extends BaseComponent {
     this._element.classList.add(CLASS_NAME_COLLAPSING)
     this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
 
-    const triggerArrayLength = this._triggerArray.length
-    for (let i = 0; i < triggerArrayLength; i++) {
-      const trigger = this._triggerArray[i]
+    for (const trigger of this._triggerArray) {
       const elem = getElementFromSelector(trigger)
 
       if (elem && !this._isShown(elem)) {
index 47f610493a2f031a52f9ada226852465932fc1f1..2aa687bb13dce1e10da2274e540d4c68ca225367 100644 (file)
@@ -129,8 +129,8 @@ function bootstrapDelegationHandler(element, selector, fn) {
 function findHandler(events, handler, delegationSelector = null) {
   const uidEventList = Object.keys(events)
 
-  for (let i = 0, len = uidEventList.length; i < len; i++) {
-    const event = events[uidEventList[i]]
+  for (const uidEvent of uidEventList) {
+    const event = events[uidEvent]
 
     if (event.originalHandler === handler && event.delegationSelector === delegationSelector) {
       return event
index f241be699c6d13eab6f6b172696b84d2a4e8a77d..335abaf05ee82948052947573d5634cb69b8e5c9 100644 (file)
@@ -377,8 +377,8 @@ class Dropdown extends BaseComponent {
 
     const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE)
 
-    for (let i = 0, len = toggles.length; i < len; i++) {
-      const context = Dropdown.getInstance(toggles[i])
+    for (const toggle of toggles) {
+      const context = Dropdown.getInstance(toggle)
       if (!context || context._config.autoClose === false) {
         continue
       }
index 2a0597be790b0d6056380e45dd0cbe441efc0ad4..c02a4eb906edc81d97c8492c3bd249871d5545e6 100644 (file)
@@ -46,8 +46,8 @@ const allowedAttribute = (attribute, allowedAttributeList) => {
   const regExp = allowedAttributeList.filter(attributeRegex => attributeRegex instanceof RegExp)
 
   // Check if a regular expression validates the attribute.
-  for (let i = 0, len = regExp.length; i < len; i++) {
-    if (regExp[i].test(attributeName)) {
+  for (const element of regExp) {
+    if (element.test(attributeName)) {
       return true
     }
   }
@@ -102,8 +102,7 @@ export function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) {
   const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html')
   const elements = [].concat(...createdDocument.body.querySelectorAll('*'))
 
-  for (let i = 0, len = elements.length; i < len; i++) {
-    const element = elements[i]
+  for (const element of elements) {
     const elementName = element.nodeName.toLowerCase()
 
     if (!Object.keys(allowList).includes(elementName)) {