Skip to content

Commit

Permalink
Use prettier for auto-formatting (sweetalert2#2385)
Browse files Browse the repository at this point in the history
  • Loading branch information
Limon Monte authored Jan 23, 2022
1 parent e8ec23f commit b7320c5
Show file tree
Hide file tree
Showing 88 changed files with 1,105 additions and 951 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
extends: [
'@sweetalert2/eslint-config',
'plugin:no-unsanitized/DOM'
],
extends: ['@sweetalert2/eslint-config', 'plugin:no-unsanitized/DOM'],
plugins: ['import'],
rules: {
'import/extensions': ['error', 'always'],
'@typescript-eslint/ban-ts-comment': 0,
}
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/no-explicit-any': 0,
},
}
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('@sweetalert2/prettier-config'),
}
8 changes: 3 additions & 5 deletions cypress/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module.exports = {
plugins: [
'cypress'
],
plugins: ['cypress'],
env: {
'cypress/globals': true
'cypress/globals': true,
},
rules: {
'no-unsanitized/property': 0,
'no-unused-expressions': 0,
'import/extensions': 0,
}
},
}
28 changes: 14 additions & 14 deletions cypress/integration/accessibility.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Accessibility:', () => {
button.focus()

SwalWithoutAnimation.fire({
returnFocus: false
returnFocus: false,
})
Swal.clickConfirm()

Expand Down Expand Up @@ -68,7 +68,7 @@ describe('Accessibility:', () => {
document.body.appendChild(div)

SwalWithoutAnimation.fire({
target: div
target: div,
})
expect(div.hasAttribute('aria-hidden')).to.be.false
})
Expand All @@ -78,7 +78,7 @@ describe('Accessibility:', () => {
document.body.appendChild(div)

SwalWithoutAnimation.fire({
backdrop: false
backdrop: false,
})
expect(div.hasAttribute('aria-hidden')).to.be.false
})
Expand All @@ -94,7 +94,7 @@ describe('Accessibility:', () => {
didClose: () => {
expect(divAriaHiddenTrue.getAttribute('aria-hidden')).to.equal('true')
done()
}
},
})
expect(div.hasAttribute('aria-hidden')).to.be.false
Swal.close()
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('should trap focus in modals', () => {
triggerKeydownEvent(document.activeElement, 'Tab')
expect(document.activeElement).to.equal(Swal.getInput())
done()
}
},
})
})

Expand All @@ -167,7 +167,7 @@ describe('should trap focus in modals', () => {
triggerKeydownEvent(document.activeElement, 'Tab', { shiftKey: true })
expect(document.activeElement).to.equal(Swal.getInput())
done()
}
},
})
})

Expand All @@ -185,7 +185,7 @@ describe('should trap focus in modals', () => {
triggerKeydownEvent(document.activeElement, 'ArrowLeft')
expect(document.activeElement).to.equal(Swal.getConfirmButton())
done()
}
},
})
})
})
Expand All @@ -196,12 +196,12 @@ describe('Focus', () => {
expect(document.activeElement).to.equal(document.querySelector('.swal2-confirm'))
SwalWithoutAnimation.fire({
text: 'Modal with two buttons',
showCancelButton: true
showCancelButton: true,
})
expect(document.activeElement).to.equal(document.querySelector('.swal2-confirm'))
SwalWithoutAnimation.fire({
text: 'Modal with no focusable elements in it',
showConfirmButton: false
showConfirmButton: false,
})
expect(document.activeElement).to.equal(document.querySelector('.swal2-modal'))
SwalWithoutAnimation.fire({
Expand All @@ -210,13 +210,13 @@ describe('Focus', () => {
didOpen: () => {
expect(document.activeElement).to.equal(document.querySelector('.swal2-input'))
done()
}
},
})
})

it('focusConfirm', () => {
Swal.fire({
showCancelButton: true
showCancelButton: true,
})
expect(document.activeElement).to.equal(Swal.getConfirmButton())
const anchor = document.createElement('a')
Expand All @@ -225,7 +225,7 @@ describe('Focus', () => {
Swal.fire({
html: anchor,
showCancelButton: true,
focusConfirm: false
focusConfirm: false,
})
expect(document.activeElement.outerHTML).to.equal(anchor.outerHTML)
})
Expand All @@ -234,7 +234,7 @@ describe('Focus', () => {
Swal.fire({
text: 'Modal with Cancel button focused',
showCancelButton: true,
focusCancel: true
focusCancel: true,
})
expect(document.activeElement).to.equal(Swal.getCancelButton())
})
Expand All @@ -243,7 +243,7 @@ describe('Focus', () => {
Swal.fire({
text: 'Modal with Deny button focused',
showDenyButton: true,
focusDeny: true
focusDeny: true,
})
expect(document.activeElement).to.equal(Swal.getDenyButton())
})
Expand Down
40 changes: 21 additions & 19 deletions cypress/integration/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Swal } from '../utils'

describe('API', () => {
it('properties of `Swal` class are consistent', (done) => {
const assertConsistent = postfix => {
const assertConsistent = (postfix) => {
const currentSwalPropNames = Object.keys(Swal)
// const extraPropNames = currentSwalPropNames.filter(key => !initialSwalPropNames.includes(key))
// expect(extraPropNames.length, 0).to.be.eql(`# of extra properties ${postfix}`)
// expect(extraPropNames.join(','), '').to.be.eql(`extra property names ${postfix}`)
const missingProps = currentSwalPropNames.filter(key => !currentSwalPropNames.includes(key))
const missingProps = currentSwalPropNames.filter((key) => !currentSwalPropNames.includes(key))
expect(missingProps.length).to.equal(0, `# of missing properties ${postfix}`)
expect(missingProps.join(',')).to.equal('', `missing property names ${postfix}`)
}
Expand All @@ -17,15 +17,15 @@ describe('API', () => {
didOpen: () => {
assertConsistent('after opening first swal')
Swal.clickConfirm()
}
},
}).then(() => {
assertConsistent('after closing first swal')
done()
})
})

it('ways to instantiate', () => {
expect((new Swal('foo')) instanceof Swal).to.be.true
expect(new Swal('foo') instanceof Swal).to.be.true
expect(Swal.fire('foo') instanceof Swal).to.be.true
})

Expand All @@ -39,29 +39,31 @@ describe('API', () => {

it('extending swal', (done) => {
const MySwal = class extends Swal {
static argsToParams (args) {
static argsToParams(args) {
expect(args).to.be.eql(['arg'])
return { title: 'title' }
}

_main (params) {
_main(params) {
expect(params).to.be.eql({ title: 'title' })
return super._main({
input: 'text',
inputValue: 'inputValue',
didOpen: () => MySwal.clickConfirm()
}).then(result => {
expect(result).to.be.eql({
value: 'inputValue',
isConfirmed: true,
isDenied: false,
isDismissed: false,
return super
._main({
input: 'text',
inputValue: 'inputValue',
didOpen: () => MySwal.clickConfirm(),
})
.then((result) => {
expect(result).to.be.eql({
value: 'inputValue',
isConfirmed: true,
isDenied: false,
isDismissed: false,
})
return 'result'
})
return 'result'
})
}
}
MySwal.fire('arg').then(result => {
MySwal.fire('arg').then((result) => {
expect(result).to.equal('result')
done()
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/bindClickHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('bindClickHandler', () => {
it('bindClickHandler', () => {
SwalWithoutAnimation.bindClickHandler()
SwalWithoutAnimation.mixin({
toast: true
toast: true,
}).bindClickHandler('data-swal-toast-template')

const template = document.createElement('template')
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/methods/clickConfirm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ describe('clickConfirm()', () => {
input: 'radio',
inputOptions: {
one: 'one',
two: 'two'
}
two: 'two',
},
}).then((result) => {
expect(result).to.eql({
value: 'two',
Expand Down
14 changes: 7 additions & 7 deletions cypress/integration/methods/close.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ describe('close()', () => {
willClose: () => {
expect(Swal.getPopup().classList.contains('swal2-hide')).to.be.true
done()
}
},
})
Swal.close()
})

it('resolves when calling Swal.close()', (done) => {
Swal.fire().then(result => {
Swal.fire().then((result) => {
expect(result).to.be.eql({
isConfirmed: false,
isDenied: false,
Expand All @@ -29,7 +29,7 @@ describe('close()', () => {
willClose: () => {
expect(Swal.isVisible()).to.be.true
done()
}
},
})
Swal.close()
})
Expand All @@ -39,7 +39,7 @@ describe('close()', () => {
didClose: () => {
expect(Swal.isVisible()).to.be.false
done()
}
},
})
Swal.close()
})
Expand All @@ -53,10 +53,10 @@ describe('close()', () => {
didOpen: () => {
expect(Swal.getInput()).to.not.be.null
done()
}
},
})
expect(Swal.isVisible()).to.be.true
}
},
})
Swal.close()
})
Expand All @@ -67,7 +67,7 @@ describe('close()', () => {
Swal.close()
expect(Swal.isVisible()).to.be.false
done()
}
},
})
Swal.close()
})
Expand Down
Loading

0 comments on commit b7320c5

Please sign in to comment.