Skip to content

Commit

Permalink
fix: upgrade to eslint 9 (#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte authored Aug 1, 2024
1 parent 7b0c619 commit 6696b81
Show file tree
Hide file tree
Showing 11 changed files with 587 additions and 605 deletions.
28 changes: 0 additions & 28 deletions .eslintrc.cjs

This file was deleted.

11 changes: 0 additions & 11 deletions cypress/.eslintrc.cjs

This file was deleted.

11 changes: 4 additions & 7 deletions cypress/e2e/tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ describe('_destroy()', () => {
it('should empty the private methods after having received a reject of an async call', (done) => {
let instance = null
Swal.fire({
preConfirm: () => new Promise((resolve, reject) => cy.wait(500).then(() => reject(new Error('msg3')))),
preConfirm: () => new Promise((resolve, reject) => cy.wait(TIMEOUT).then(() => reject(new Error('msg3')))),
})
.then(() => {
//
Expand All @@ -1455,7 +1455,7 @@ describe('_destroy()', () => {
it('should empty the private methods after having received a resolve of an async call', (done) => {
let instance = null
Swal.fire({
preConfirm: () => new Promise((resolve) => cy.wait(500).then(resolve)),
preConfirm: () => new Promise((resolve) => cy.wait(TIMEOUT).then(resolve)),
}).then(() => {
expect(privateMethods.swalPromiseResolve.get(instance)).to.equal(undefined)
done()
Expand All @@ -1478,7 +1478,7 @@ describe('_destroy()', () => {
expect(privateMethods.swalPromiseResolve.get(instance)).to.not.equal(undefined)
},
})
cy.wait(500).then(resolve)
cy.wait(TIMEOUT).then(resolve)
}),
}).then(() => {
expect(privateMethods.swalPromiseResolve.get(instance)).to.equal(undefined)
Expand All @@ -1500,7 +1500,7 @@ describe('_destroy()', () => {
expect(privateMethods.swalPromiseResolve.get(instance)).to.not.equal(undefined)
},
})
cy.wait(500).then(resolve)
cy.wait(TIMEOUT).then(resolve)
}),
}).then(() => {
expect(privateMethods.swalPromiseResolve.get(instance)).to.equal(undefined)
Expand Down Expand Up @@ -3681,9 +3681,6 @@ describe('Vertical scrollbar', () => {

SwalWithoutAnimation.fire({
title: 'no padding right adjustment when overflow-y: scroll is set on body',
didClose: () => {
document.body.removeChild(talltDiv)
},
})

const bodyStyles = window.getComputedStyle(document.body)
Expand Down
57 changes: 57 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import jsdoc from 'eslint-plugin-jsdoc'
import sweetAlert2EslintConfig from '@sweetalert2/eslint-config'
// TODO: https://github.com/mozilla/eslint-plugin-no-unsanitized/issues/241
// import eslintPluginNoUnsanitized from 'eslint-plugin-no-unsanitized'
import pluginCypress from 'eslint-plugin-cypress/flat'
import globals from 'globals'

export default [
...sweetAlert2EslintConfig,
// eslintPluginNoUnsanitized,
jsdoc.configs['flat/recommended'],
pluginCypress.configs.recommended,
{
plugins: {
jsdoc,
},
rules: {
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-this-alias': 0,
'@typescript-eslint/no-unused-vars': ['error', { varsIgnorePattern: '_' }],
'@typescript-eslint/triple-slash-reference': 0,
'jsdoc/require-param-description': 0,
'jsdoc/require-property-description': 0,
'jsdoc/require-returns-description': 0,
'jsdoc/no-undefined-types': 0,
'jsdoc/tag-lines': 0,
'jsdoc/valid-types': 0,
},
},
{
files: ['sweetalert2.d.ts'],
rules: {
'jsdoc/require-param': 0,
'jsdoc/require-returns': 0,
'jsdoc/require-param-type': 0,
},
},
{
files: ['cypress/**/*.js'],
rules: {
'@typescript-eslint/no-unused-expressions': 0,
'no-unsanitized/property': 0,
'no-unused-expressions': 0,
'jsdoc/require-jsdoc': 0,
},
},
{
files: ['rollup.config.js', 'release.config.js'],
languageOptions: {
globals: {
...globals.node,
},
},
},
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@sweetalert2/eslint-config": "^1.0.11",
"@sweetalert2/stylelint-config": "^3.0.0",
"cypress": "^13.0.0",
"eslint": "^8.24.0",
"eslint": "^9.0.0",
"eslint-plugin-cypress": "^3.0.0",
"eslint-plugin-jsdoc": "^48.0.0",
"eslint-plugin-no-unsanitized": "^4.0.1",
Expand Down
3 changes: 1 addition & 2 deletions src/staticMethods/fire.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
* @returns {Promise<SweetAlertResult>}
*/
export function fire(...args) {
const Swal = this // eslint-disable-line @typescript-eslint/no-this-alias
return new Swal(...args)
return new this(...args)
}
2 changes: 1 addition & 1 deletion src/staticMethods/showLoading.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as dom from '../utils/dom/index.js'
const showLoading = (buttonToReplace) => {
let popup = dom.getPopup()
if (!popup) {
new Swal() // eslint-disable-line no-new
new Swal()
}
popup = dom.getPopup()
if (!popup) {
Expand Down
36 changes: 29 additions & 7 deletions src/utils/dom/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ export const setInnerHtml = (elem, html) => {
const parser = new DOMParser()
const parsed = parser.parseFromString(html, `text/html`)
const head = parsed.querySelector('head')
head &&
if (head) {
Array.from(head.childNodes).forEach((child) => {
elem.appendChild(child)
})
}
const body = parsed.querySelector('body')
body &&
if (body) {
Array.from(body.childNodes).forEach((child) => {
if (child instanceof HTMLVideoElement || child instanceof HTMLAudioElement) {
elem.appendChild(child.cloneNode(true)) // https://github.com/sweetalert2/sweetalert2/issues/2507
} else {
elem.appendChild(child)
}
})
}
}
}

Expand Down Expand Up @@ -149,10 +151,18 @@ export const toggleClass = (target, classList, condition) => {
classList.forEach((className) => {
if (Array.isArray(target)) {
target.forEach((elem) => {
condition ? elem.classList.add(className) : elem.classList.remove(className)
if (condition) {
elem.classList.add(className)
} else {
elem.classList.remove(className)
}
})
} else {
condition ? target.classList.add(className) : target.classList.remove(className)
if (condition) {
target.classList.add(className)
} else {
target.classList.remove(className)
}
}
})
}
Expand Down Expand Up @@ -211,14 +221,22 @@ export const applyNumericalStyle = (elem, property, value) => {
* @param {string} display
*/
export const show = (elem, display = 'flex') => {
elem && (elem.style.display = display)
if (!elem) {
return
}

elem.style.display = display
}

/**
* @param {HTMLElement | null} elem
*/
export const hide = (elem) => {
elem && (elem.style.display = 'none')
if (!elem) {
return
}

elem.style.display = 'none'
}

/**
Expand Down Expand Up @@ -254,7 +272,11 @@ export const setStyle = (parent, selector, property, value) => {
* @param {string} display
*/
export const toggle = (elem, condition, display = 'flex') => {
condition ? show(elem, display) : hide(elem)
if (condition) {
show(elem, display)
} else {
hide(elem)
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/utils/dom/renderers/renderPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const renderPopup = (instance, params) => {
dom.applyNumericalStyle(container, 'width', params.width)
popup.style.width = '100%'
const loader = dom.getLoader()
loader && popup.insertBefore(loader, dom.getIcon())
if (loader) {
popup.insertBefore(loader, dom.getIcon())
}
} else {
dom.applyNumericalStyle(popup, 'width', params.width)
}
Expand Down
6 changes: 3 additions & 3 deletions sweetalert2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1228,18 +1228,18 @@ declare module 'sweetalert2' {
declare module 'sweetalert2/*/sweetalert2.js' {
export * from 'sweetalert2'
// "export *" does not matches the default export, so do it explicitly.
export { default } from 'sweetalert2' // eslint-disable-line
export { default } from 'sweetalert2'
}

declare module 'sweetalert2/*/sweetalert2.all.js' {
export * from 'sweetalert2'
// "export *" does not matches the default export, so do it explicitly.
export { default } from 'sweetalert2' // eslint-disable-line
export { default } from 'sweetalert2'
}

/**
* These interfaces aren't provided by SweetAlert2, but its definitions use them.
* They will be merged with 'true' definitions.
*/

interface JQuery {}
interface JQuery {} // eslint-disable-line @typescript-eslint/no-empty-object-type
Loading

0 comments on commit 6696b81

Please sign in to comment.