0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-26 23:54:23 +01:00

Enable unicorn/prefer-spread rule

This commit is contained in:
XhmikosR 2023-07-25 10:48:42 +03:00
parent 6ce0c62e21
commit 8590295993
13 changed files with 27 additions and 24 deletions

View File

@ -96,7 +96,6 @@
"unicorn/prefer-dom-node-dataset": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-query-selector": "off",
"unicorn/prefer-spread": "off",
"unicorn/prefer-string-replace-all": "off",
"unicorn/prevent-abbreviations": "off"
},

View File

@ -23,7 +23,7 @@ export default {
// can be removed later when multiple key/instances are fine to be used
if (!instanceMap.has(key) && instanceMap.size !== 0) {
// eslint-disable-next-line no-console
console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`)
console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${[...instanceMap.keys()][0]}.`)
return
}

View File

@ -34,7 +34,7 @@ const getSelector = element => {
const SelectorEngine = {
find(selector, element = document.documentElement) {
return [].concat(...Element.prototype.querySelectorAll.call(element, selector))
return [...Element.prototype.querySelectorAll.call(element, selector)]
},
findOne(selector, element = document.documentElement) {
@ -42,7 +42,7 @@ const SelectorEngine = {
},
children(element, selector) {
return [].concat(...element.children).filter(child => child.matches(selector))
return [...element.children].filter(child => child.matches(selector))
},
parents(element, selector) {

View File

@ -143,7 +143,8 @@ class Dropdown extends BaseComponent {
// only needed because of broken event delegation on iOS
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
if ('ontouchstart' in document.documentElement && !this._parent.closest(SELECTOR_NAVBAR_NAV)) {
for (const element of [].concat(...document.body.children)) {
const children = [...document.body.children]
for (const element of children) {
EventHandler.on(element, 'mouseover', noop)
}
}
@ -193,7 +194,8 @@ class Dropdown extends BaseComponent {
// If this is a touch-enabled device we remove the extra
// empty mouseover listeners we added for iOS support
if ('ontouchstart' in document.documentElement) {
for (const element of [].concat(...document.body.children)) {
const children = [...document.body.children]
for (const element of children) {
EventHandler.off(element, 'mouseover', noop)
}
}

View File

@ -222,7 +222,8 @@ class Tooltip extends BaseComponent {
// only needed because of broken event delegation on iOS
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
if ('ontouchstart' in document.documentElement) {
for (const element of [].concat(...document.body.children)) {
const children = [...document.body.children]
for (const element of children) {
EventHandler.on(element, 'mouseover', noop)
}
}
@ -256,7 +257,8 @@ class Tooltip extends BaseComponent {
// If this is a touch-enabled device we remove the extra
// empty mouseover listeners we added for iOS support
if ('ontouchstart' in document.documentElement) {
for (const element of [].concat(...document.body.children)) {
const children = [...document.body.children]
for (const element of children) {
EventHandler.off(element, 'mouseover', noop)
}
}

View File

@ -93,7 +93,7 @@ export function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) {
const domParser = new window.DOMParser()
const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html')
const elements = [].concat(...createdDocument.body.querySelectorAll('*'))
const elements = [...createdDocument.body.querySelectorAll('*')]
for (const element of elements) {
const elementName = element.nodeName.toLowerCase()
@ -103,8 +103,8 @@ export function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) {
continue
}
const attributeList = [].concat(...element.attributes)
const allowedAttributes = [].concat(allowList['*'] || [], allowList[elementName] || [])
const attributeList = [...element.attributes]
const allowedAttributes = [...allowList['*'] || [], ...allowList[elementName] || []]
for (const attribute of attributeList) {
if (!allowedAttribute(attribute, allowedAttributes)) {

View File

@ -4,6 +4,6 @@ import Tooltip from '../../dist/tooltip'
import '../../dist/carousel'
window.addEventListener('load', () => {
[].concat(...document.querySelectorAll('[data-bs-toggle="tooltip"]'))
[...document.querySelectorAll('[data-bs-toggle="tooltip"]')]
.map(tooltipNode => new Tooltip(tooltipNode))
})

View File

@ -1,6 +1,6 @@
import { Tooltip } from '../../../dist/js/bootstrap.esm.js'
window.addEventListener('load', () => {
[].concat(...document.querySelectorAll('[data-bs-toggle="tooltip"]'))
[...document.querySelectorAll('[data-bs-toggle="tooltip"]')]
.map(tooltipNode => new Tooltip(tooltipNode))
})

View File

@ -153,7 +153,7 @@ describe('Collapse', () => {
const collapseEl1 = fixtureEl.querySelector('#collapse1')
const collapseEl2 = fixtureEl.querySelector('#collapse2')
const collapseList = [].concat(...fixtureEl.querySelectorAll('.collapse'))
const collapseList = [...fixtureEl.querySelectorAll('.collapse')]
.map(el => new Collapse(el, {
parent,
toggle: false

View File

@ -68,7 +68,7 @@ describe('SelectorEngine', () => {
].join('')
const list = fixtureEl.querySelector('ul')
const liList = [].concat(...fixtureEl.querySelectorAll('li'))
const liList = [...fixtureEl.querySelectorAll('li')]
const result = SelectorEngine.children(list, 'li')
expect(result).toEqual(liList)
@ -356,7 +356,7 @@ describe('SelectorEngine', () => {
const testEl = fixtureEl.querySelector('#test')
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual([...fixtureEl.querySelectorAll('.target')])
})
it('should get elements if several ids are given', () => {
@ -368,7 +368,7 @@ describe('SelectorEngine', () => {
const testEl = fixtureEl.querySelector('#test')
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual([...fixtureEl.querySelectorAll('.target')])
})
it('should get elements if several ids with special chars are given', () => {
@ -380,7 +380,7 @@ describe('SelectorEngine', () => {
const testEl = fixtureEl.querySelector('#test')
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual([...fixtureEl.querySelectorAll('.target')])
})
it('should get elements in array, from href if no data-bs-target set', () => {
@ -392,7 +392,7 @@ describe('SelectorEngine', () => {
const testEl = fixtureEl.querySelector('#test')
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual([...fixtureEl.querySelectorAll('.target')])
})
it('should return empty array if elements not found', () => {

View File

@ -3,10 +3,10 @@
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
const forms = document.querySelectorAll('.needs-validation')
const forms = document.querySelectorAll('.needs-validation');
// Loop over them and prevent submission
Array.from(forms).forEach(form => {
[...forms].forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()

View File

@ -1,7 +1,7 @@
/* global bootstrap: false */
(() => {
'use strict'
const tooltipTriggerList = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
const tooltipTriggerList = [...document.querySelectorAll('[data-bs-toggle="tooltip"]')]
tooltipTriggerList.forEach(tooltipTriggerEl => {
new bootstrap.Tooltip(tooltipTriggerEl)
})

View File

@ -3,10 +3,10 @@
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
const forms = document.querySelectorAll('.needs-validation')
const forms = document.querySelectorAll('.needs-validation');
// Loop over them and prevent submission
Array.from(forms).forEach(form => {
[...forms].forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()