Skip to content

Commit

Permalink
Add eslint rule
Browse files Browse the repository at this point in the history
- strip eslint comments from deliverables
  • Loading branch information
replete committed Jun 27, 2024
1 parent 8cbff6c commit 62d6448
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/biscuitman.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
function clearStorages() {
const localStores = Object1.fromEntries(Object1.entries(localStorage));
const cookies = Object1.fromEntries(d.cookie.split('; ').map((cookie)=>cookie.split('=')));
// eslint-disable-next-line no-unused-vars

const { consentTime, ...consents } = loadConsents() || options.sections.slice(1).reduce((consents, section)=>{
consents[section] = false;
return {
Expand Down
2 changes: 1 addition & 1 deletion dist/biscuitman.withcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
function clearStorages() {
const localStores = Object1.fromEntries(Object1.entries(localStorage));
const cookies = Object1.fromEntries(d.cookie.split('; ').map((cookie)=>cookie.split('=')));
// eslint-disable-next-line no-unused-vars

const { consentTime, ...consents } = loadConsents() || options.sections.slice(1).reduce((consents, section)=>{
consents[section] = false;
return {
Expand Down
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default [
rules: {
...pluginJs.configs.recommended.rules,
semi: [2,'never'],
quotes: [2,'single']
quotes: [2,'single'],
'object-curly-spacing': [2, 'always']
},
},
{
Expand Down
6 changes: 4 additions & 2 deletions run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import swc from '@swc/core'
import { transform as transformCss, browserslistToTargets, Features} from 'lightningcss'
import { transform as transformCss, browserslistToTargets, Features } from 'lightningcss'
import browserslist from 'browserslist'
import browserSync from 'browser-sync'
import { Readable } from 'stream'
Expand Down Expand Up @@ -58,6 +58,7 @@ export async function scripts(skipFileSave) {
minify: false
})
.then(async ({ code }) => {
code = code.replace(/(\/\* eslint-disable.*?\*\/)|(\/\/ eslint-disable-.*?$)/gm,'') // strip eslint comments
if (!skipFileSave) await writeFile(`dist/${filenames.js}`, `${comment}\n` + code)
log('js',`Saved dist/${filenames.js}`)
return code
Expand Down Expand Up @@ -99,6 +100,7 @@ ${js[0]};
css.textContent=\`${css[0]}\`;
d.head.appendChild(css)
})(document);`
jsCss = jsCss.replace(/(\/\* eslint-disable.*?\*\/)|(\/\/ eslint-disable-.*?$)/gm,'') // strip eslint comments
let jsCssMin = `${comment}${js[1].replace(/[\n\t]/g, '')};((d)=>{let c=d.createElement('style');c.textContent=\`${css[1]}\`;d.head.appendChild(c)})(document);`

await Promise.all([
Expand Down Expand Up @@ -165,7 +167,7 @@ export async function report() {
cssReportData.push(usageInfo)
})
.on('end', async () => {
await writeFile('cssreport.json', JSON.stringify({report: cssReportData}))
await writeFile('cssreport.json', JSON.stringify({ report: cssReportData }))
log('report: css','Saved cssreport.json (see compatibility table on index.html')
})
}
Expand Down
22 changes: 11 additions & 11 deletions src/biscuitman.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// uncategorizedTitle: 'Uncategorized',
// uncategorizedMessage: 'Uncategorized cookies are those currently under analysis and have not yet been assigned to a specific category',
}
const options = {...defaults, ...w.biscuitman}
const options = { ...defaults, ...w.biscuitman }

// UI & Events:

Expand Down Expand Up @@ -134,7 +134,7 @@

function buttonHandler(e) {
let id = e.target.dataset.id
dispatch('button', {id})
dispatch('button', { id })
switch (id) {
case 'accept': saveConsents(true); break
case 'close': dialog.close(); break
Expand Down Expand Up @@ -179,7 +179,7 @@
function checkConsents(oldConsents, newConsents) {
for (const sectionName in oldConsents)
if (oldConsents[sectionName] && newConsents[sectionName] === false)
dispatch('revoke', {section: sectionName})
dispatch('revoke', { section: sectionName })
}

function loadConsents() {
Expand Down Expand Up @@ -210,7 +210,7 @@
sectionCookieNames
.filter(name => name.endsWith('*'))
.map(wildcardName => {
Object.keys({...cookies, ...localStores}).map(name => {
Object.keys({ ...cookies, ...localStores }).map(name => {
if (name.startsWith(wildcardName.slice(0, -1))) sectionCookieNames.push(name)
})
})
Expand All @@ -221,11 +221,11 @@
d.cookie = expiredCookie
d.cookie = `${expiredCookie}domain=${location.hostname};` // Safari iOS
d.cookie = `${expiredCookie}domain=.${location.hostname};` // Safari iOS
dispatch('delete',{cookie : name})
dispatch('delete',{ cookie : name })
}
if (localStores[name]) {
localStorage.removeItem(name)
dispatch('delete',{localStorage : name})
dispatch('delete',{ localStorage : name })
}
}
}
Expand All @@ -248,7 +248,7 @@
checkConsents(getConsents(),consents)
setConsents(consents)
localStorage.setItem(options.key, JSON.stringify(consents))
dispatch('save', {data: consents})
dispatch('save', { data: consents })
clearStorages()
insertScripts()
dialog.close()
Expand All @@ -268,15 +268,15 @@
newScript.setAttribute('type', script.dataset.type || 'text/javascript')
if (!script.src) newScript.textContent = script.textContent
script.parentNode.replaceChild(newScript, script)
dispatch('inject', {el: script, ...(script.id && {id: script.id})})
dispatch('inject', { el: script, ...(script.id && { id: script.id }) })

// If tag has src AND tag content, inject new tag adjacent to parent after load
if (script.src && script.textContent.trim() !== '') newScript.addEventListener('load', () => {
let afterScript = d.createElement('script')
afterScript.textContent = script.textContent
if (script.id) afterScript.id = script.id + '-after'
newScript.insertAdjacentElement('afterend', afterScript)
dispatch('inject', {el: afterScript, parent: script, ...(afterScript.id && {id: afterScript.id})})
dispatch('inject', { el: afterScript, parent: script, ...(afterScript.id && { id: afterScript.id }) })
})
})
}
Expand Down Expand Up @@ -308,7 +308,7 @@
// Helper methods
// <a onclick="bmInvalidate()" href="javascript:void(0)">Delete Consent Preferences</a>
w.bmInvalidate = () => {
dispatch('invalidate', {data: getConsents()})
dispatch('invalidate', { data: getConsents() })
checkConsents({})
saveConsents(false)
setConsents({})
Expand All @@ -317,7 +317,7 @@
}
// <a onclick="bmUpdate()" href="javascript:void(0)">Update Consent Preferences</a>
w.bmUpdate = () => {
dispatch('update', {data: getConsents()})
dispatch('update', { data: getConsents() })
openModal()
}
})(document, window, Object, document.documentElement, 'biscuitman')

0 comments on commit 62d6448

Please sign in to comment.