aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2021-09-11 21:56:28 +0300
committerXhmikosR <[email protected]>2021-09-28 19:09:04 +0300
commita74f33c40649711293a009ada8b7c21330a999a5 (patch)
treebc0135f3bcfd45ed9a0a140038cd077e8e3c2317
parenta82d31f4329c4dd8fabf258d807917dfed4dcca1 (diff)
downloadbootstrap-main-xmr-js-wip.tar.xz
bootstrap-main-xmr-js-wip.zip
Prefer using function expressionsmain-xmr-js-wip
-rw-r--r--.eslintrc.json4
-rw-r--r--build/banner.js2
-rw-r--r--build/change-version.js12
-rw-r--r--js/src/dom/event-handler.js20
-rw-r--r--js/src/dom/manipulator.js4
-rw-r--r--js/src/util/sanitizer.js2
-rw-r--r--js/tests/unit/collapse.spec.js8
-rw-r--r--js/tests/unit/scrollspy.spec.js2
-rw-r--r--js/tests/unit/util/index.spec.js4
-rw-r--r--js/tests/unit/util/sanitizer.spec.js1
10 files changed, 30 insertions, 29 deletions
diff --git a/.eslintrc.json b/.eslintrc.json
index 1e45281a2..0efdc4e0d 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -14,6 +14,10 @@
"error",
"never"
],
+ "func-style": [
+ "error",
+ "expression"
+ ],
"indent": [
"error",
2,
diff --git a/build/banner.js b/build/banner.js
index df82ff32e..c591cc1ad 100644
--- a/build/banner.js
+++ b/build/banner.js
@@ -3,7 +3,7 @@
const pkg = require('../package.json')
const year = new Date().getFullYear()
-function getBanner(pluginFilename) {
+const getBanner = pluginFilename => {
return `/*!
* Bootstrap${pluginFilename ? ` ${pluginFilename}` : ''} v${pkg.version} (${pkg.homepage})
* Copyright 2011-${year} ${pkg.author}
diff --git a/build/change-version.js b/build/change-version.js
index 63f231ea2..dd55393cb 100644
--- a/build/change-version.js
+++ b/build/change-version.js
@@ -26,15 +26,11 @@ const GLOBBY_OPTIONS = {
}
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
-function regExpQuote(string) {
- return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&')
-}
+const regExpQuote = string => string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&')
-function regExpQuoteReplacement(string) {
- return string.replace(/\$/g, '$$')
-}
+const regExpQuoteReplacement = string => string.replace(/\$/g, '$$')
-async function replaceRecursively(file, oldVersion, newVersion) {
+const replaceRecursively = async (file, oldVersion, newVersion) => {
const originalString = await fs.readFile(file, 'utf8')
const newString = originalString.replace(
new RegExp(regExpQuote(oldVersion), 'g'), regExpQuoteReplacement(newVersion)
@@ -56,7 +52,7 @@ async function replaceRecursively(file, oldVersion, newVersion) {
await fs.writeFile(file, newString, 'utf8')
}
-async function main(args) {
+const main = async args => {
const [oldVersion, newVersion] = args
if (!oldVersion || !newVersion) {
diff --git a/js/src/dom/event-handler.js b/js/src/dom/event-handler.js
index 9cb0583fc..8e291e76c 100644
--- a/js/src/dom/event-handler.js
+++ b/js/src/dom/event-handler.js
@@ -78,11 +78,11 @@ const nativeEvents = new Set([
* ------------------------------------------------------------------------
*/
-function getUidEvent(element, uid) {
+const getUidEvent = (element, uid) => {
return (uid && `${uid}::${uidEvent++}`) || element.uidEvent || uidEvent++
}
-function getEvent(element) {
+const getEvent = element => {
const uid = getUidEvent(element)
element.uidEvent = uid
@@ -91,7 +91,7 @@ function getEvent(element) {
return eventRegistry[uid]
}
-function bootstrapHandler(element, fn) {
+const bootstrapHandler = (element, fn) => {
return function handler(event) {
event.delegateTarget = element
@@ -103,7 +103,7 @@ function bootstrapHandler(element, fn) {
}
}
-function bootstrapDelegationHandler(element, selector, fn) {
+const bootstrapDelegationHandler = (element, selector, fn) => {
return function handler(event) {
const domElements = element.querySelectorAll(selector)
@@ -126,7 +126,7 @@ function bootstrapDelegationHandler(element, selector, fn) {
}
}
-function findHandler(events, handler, delegationSelector = null) {
+const findHandler = (events, handler, delegationSelector = null) => {
const uidEventList = Object.keys(events)
for (const element of uidEventList) {
@@ -140,7 +140,7 @@ function findHandler(events, handler, delegationSelector = null) {
return null
}
-function normalizeParams(originalTypeEvent, handler, delegationFn) {
+const normalizeParams = (originalTypeEvent, handler, delegationFn) => {
const delegation = typeof handler === 'string'
const originalHandler = delegation ? delegationFn : handler
@@ -154,7 +154,7 @@ function normalizeParams(originalTypeEvent, handler, delegationFn) {
return [delegation, originalHandler, typeEvent]
}
-function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
+const addHandler = (element, originalTypeEvent, handler, delegationFn, oneOff) => {
if (typeof originalTypeEvent !== 'string' || !element) {
return
}
@@ -207,7 +207,7 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) {
element.addEventListener(typeEvent, fn, delegation)
}
-function removeHandler(element, events, typeEvent, handler, delegationSelector) {
+const removeHandler = (element, events, typeEvent, handler, delegationSelector) => {
const fn = findHandler(events[typeEvent], handler, delegationSelector)
if (!fn) {
@@ -218,7 +218,7 @@ function removeHandler(element, events, typeEvent, handler, delegationSelector)
delete events[typeEvent][fn.uidEvent]
}
-function removeNamespacedHandlers(element, events, typeEvent, namespace) {
+const removeNamespacedHandlers = (element, events, typeEvent, namespace) => {
const storeElementEvent = events[typeEvent] || {}
for (const handlerKey of Object.keys(storeElementEvent)) {
@@ -230,7 +230,7 @@ function removeNamespacedHandlers(element, events, typeEvent, namespace) {
}
}
-function getTypeEvent(event) {
+const getTypeEvent = event => {
// allow to get the native events from namespaced events ('click.bs.button' --> 'click')
event = event.replace(stripNameRegex, '')
return customEvents[event] || event
diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js
index b9a73ee37..dece35100 100644
--- a/js/src/dom/manipulator.js
+++ b/js/src/dom/manipulator.js
@@ -5,7 +5,7 @@
* --------------------------------------------------------------------------
*/
-function normalizeData(val) {
+const normalizeData = val => {
if (val === 'true') {
return true
}
@@ -25,7 +25,7 @@ function normalizeData(val) {
return val
}
-function normalizeDataKey(key) {
+const normalizeDataKey = key => {
return key.replace(/[A-Z]/g, chr => `-${chr.toLowerCase()}`)
}
diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js
index 50199625e..a164936a7 100644
--- a/js/src/util/sanitizer.js
+++ b/js/src/util/sanitizer.js
@@ -82,7 +82,7 @@ export const DefaultAllowlist = {
ul: []
}
-export function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) {
+export const sanitizeHtml = (unsafeHtml, allowList, sanitizeFn) => {
if (!unsafeHtml.length) {
return unsafeHtml
}
diff --git a/js/tests/unit/collapse.spec.js b/js/tests/unit/collapse.spec.js
index da709bb85..082e6505f 100644
--- a/js/tests/unit/collapse.spec.js
+++ b/js/tests/unit/collapse.spec.js
@@ -734,7 +734,7 @@ describe('Collapse', () => {
two: false
}
- function firstTest() {
+ const firstTest = () => {
expect(collapseOneOne.classList.contains('show')).toEqual(true)
expect(collapseOneTwo.classList.contains('show')).toEqual(true)
@@ -744,7 +744,7 @@ describe('Collapse', () => {
triggerTwo.click()
}
- function secondTest() {
+ const secondTest = () => {
expect(collapseOneOne.classList.contains('show')).toEqual(false)
expect(collapseOneTwo.classList.contains('show')).toEqual(false)
@@ -816,7 +816,7 @@ describe('Collapse', () => {
const collapseTwo = fixtureEl.querySelector('#collapseTwo')
const nestedCollapseOne = fixtureEl.querySelector('#nestedCollapseOne')
- function handlerCollapseOne() {
+ const handlerCollapseOne = () => {
expect(collapseOne.classList.contains('show')).toEqual(true)
expect(collapseTwo.classList.contains('show')).toEqual(false)
expect(nestedCollapseOne.classList.contains('show')).toEqual(false)
@@ -826,7 +826,7 @@ describe('Collapse', () => {
collapseOne.removeEventListener('shown.bs.collapse', handlerCollapseOne)
}
- function handlerNestedCollapseOne() {
+ const handlerNestedCollapseOne = () => {
expect(collapseOne.classList.contains('show')).toEqual(true)
expect(collapseTwo.classList.contains('show')).toEqual(false)
expect(nestedCollapseOne.classList.contains('show')).toEqual(true)
diff --git a/js/tests/unit/scrollspy.spec.js b/js/tests/unit/scrollspy.spec.js
index ad44d5b3c..66e4cd7bf 100644
--- a/js/tests/unit/scrollspy.spec.js
+++ b/js/tests/unit/scrollspy.spec.js
@@ -15,7 +15,7 @@ describe('ScrollSpy', () => {
const paddingTop = 5
const scrollHeight = Math.ceil(contentEl.scrollTop + Manipulator.position(target).top) + paddingTop
- function listener() {
+ const listener = () => {
expect(element.classList.contains('active')).toEqual(true)
contentEl.removeEventListener('scroll', listener)
expect(scrollSpy._process).toHaveBeenCalled()
diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js
index 38e94dc6b..2563aad8f 100644
--- a/js/tests/unit/util/index.spec.js
+++ b/js/tests/unit/util/index.spec.js
@@ -625,9 +625,9 @@ describe('Util', () => {
})
it('should define a plugin on the jQuery instance', () => {
- const pluginMock = function () {}
+ const pluginMock = () => {}
pluginMock.NAME = 'test'
- pluginMock.jQueryInterface = function () {}
+ pluginMock.jQueryInterface = () => {}
Util.defineJQueryPlugin(pluginMock)
expect(fakejQuery.fn.test).toBe(pluginMock.jQueryInterface)
diff --git a/js/tests/unit/util/sanitizer.spec.js b/js/tests/unit/util/sanitizer.spec.js
index 7379d221f..6aa307f72 100644
--- a/js/tests/unit/util/sanitizer.spec.js
+++ b/js/tests/unit/util/sanitizer.spec.js
@@ -55,6 +55,7 @@ describe('Sanitizer', () => {
'</div>'
].join('')
+ // eslint-disable-next-line func-style
function mySanitize(htmlUnsafe) {
return htmlUnsafe
}