diff options
| author | stonedDiscord <Tukz@gmx.de> | 2023-09-20 11:52:34 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2023-09-20 11:52:34 +0200 |
| commit | 5fc20f9dd53fe4d32be08d538782baa47c67853c (patch) | |
| tree | ba0994a4c3a7b090d3732f7381b96e92ee365249 | |
| parent | 4db738e6e5e3287c3621501a01988ab90eed447e (diff) | |
make eslint a lot happier
| -rw-r--r-- | .eslintrc.js | 3 | ||||
| -rw-r--r-- | webAO/client/__tests__/setEmote.test.js | 12 | ||||
| -rw-r--r-- | webAO/components/__tests__/audioChannels.test.js | 14 | ||||
| -rw-r--r-- | webAO/components/__tests__/blips.test.js | 14 | ||||
| -rw-r--r-- | webAO/components/audioChannels.js | 18 | ||||
| -rw-r--r-- | webAO/components/blip.js | 24 | ||||
| -rw-r--r-- | webAO/constants/transparentPng.js | 2 | ||||
| -rw-r--r-- | webAO/dom/changeVolume.js | 4 | ||||
| -rw-r--r-- | webAO/dom/toggleElement.js | 12 | ||||
| -rw-r--r-- | webAO/ui.js | 7 | ||||
| -rw-r--r-- | webAO/utils/calculateApngLength.js | 24 | ||||
| -rw-r--r-- | webAO/utils/calculateGifLength.js | 14 | ||||
| -rw-r--r-- | webAO/utils/fileExistsSync.js | 11 | ||||
| -rw-r--r-- | webAO/utils/getAnimLength.js | 12 |
14 files changed, 80 insertions, 91 deletions
diff --git a/.eslintrc.js b/.eslintrc.js index 83d8348..1c6b45b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,6 +2,7 @@ module.exports = { env: { browser: true, es2021: true, + jest: true, }, extends: [ 'airbnb-base', @@ -11,5 +12,7 @@ module.exports = { sourceType: 'module', }, rules: { + "indent": ["warn", 2], + "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], }, }; diff --git a/webAO/client/__tests__/setEmote.test.js b/webAO/client/__tests__/setEmote.test.js index 252fb2a..829c94d 100644 --- a/webAO/client/__tests__/setEmote.test.js +++ b/webAO/client/__tests__/setEmote.test.js @@ -1,13 +1,13 @@ -import setEmote from '../setEmote'; -import Client from '../../client'; +import setEmote from '../setEmote.ts'; +import Client from '../../client.ts'; import fileExists from '../../utils/fileExists'; import transparentPng from '../../constants/transparentPng'; -jest.mock('../../viewport/utils/createMusic') +jest.mock('../../viewport/utils/createMusic'); jest.mock('../../utils/fileExists'); -jest.mock('../../viewport/utils/createSfxAudio') -jest.mock('../../viewport/utils/createShoutAudio') -jest.mock('../../viewport/utils/createTestimonyAudio') +jest.mock('../../viewport/utils/createSfxAudio'); +jest.mock('../../viewport/utils/createShoutAudio'); +jest.mock('../../viewport/utils/createTestimonyAudio'); describe('setEmote', () => { const AO_HOST = ''; diff --git a/webAO/components/__tests__/audioChannels.test.js b/webAO/components/__tests__/audioChannels.test.js index 243d870..cd46d33 100644 --- a/webAO/components/__tests__/audioChannels.test.js +++ b/webAO/components/__tests__/audioChannels.test.js @@ -1,9 +1,9 @@ -import createAudioChannels from "../audioChannels"; +import createAudioChannels from '../audioChannels'; describe('createAudioChannels', () => { - test('Should create 4 channels', () => { - document.body.innerHTML = '' - createAudioChannels(4) - expect(document.getElementsByClassName('audioChannel').length).toBe(4) - }) -})
\ No newline at end of file + test('Should create 4 channels', () => { + document.body.innerHTML = ''; + createAudioChannels(4); + expect(document.getElementsByClassName('audioChannel').length).toBe(4); + }); +}); diff --git a/webAO/components/__tests__/blips.test.js b/webAO/components/__tests__/blips.test.js index 9c57e78..03468c9 100644 --- a/webAO/components/__tests__/blips.test.js +++ b/webAO/components/__tests__/blips.test.js @@ -1,9 +1,9 @@ -import createBlip from "../blip"; +import createBlip from '../blip'; describe('createBlip', () => { - test('create 3 blips audios', () => { - document.body.innerHTML = `` - createBlip(3) - expect(document.getElementsByClassName('blipSound').length).toBe(3) - }) -})
\ No newline at end of file + test('create 3 blips audios', () => { + document.body.innerHTML = ''; + createBlip(3); + expect(document.getElementsByClassName('blipSound').length).toBe(3); + }); +}); diff --git a/webAO/components/audioChannels.js b/webAO/components/audioChannels.js index 1979653..80bdb4f 100644 --- a/webAO/components/audioChannels.js +++ b/webAO/components/audioChannels.js @@ -1,13 +1,13 @@ /** - * + * * @param {number} amountOfChannels Amount of Blips to put on page */ const createAudioChannels = (amountOfChannels) => { - for (let i = 0; i < amountOfChannels; i++) { - const audioChannel = document.createElement('audio') - audioChannel.setAttribute('class', 'audioChannel') - document.body.appendChild(audioChannel) - } -} -createAudioChannels(4) -export default createAudioChannels + for (let i = 0; i < amountOfChannels; i++) { + const audioChannel = document.createElement('audio'); + audioChannel.setAttribute('class', 'audioChannel'); + document.body.appendChild(audioChannel); + } +}; +createAudioChannels(4); +export default createAudioChannels; diff --git a/webAO/components/blip.js b/webAO/components/blip.js index 6f896f5..02f5ced 100644 --- a/webAO/components/blip.js +++ b/webAO/components/blip.js @@ -1,17 +1,17 @@ -import { AO_HOST } from '../client/aoHost' +import { AO_HOST } from '../client/aoHost.ts'; /** - * + * * @param {number} amountOfBlips Amount of Blips to put on page */ const createBlip = (amountOfBlips) => { - for (let i = 0; i < amountOfBlips; i++) { - const audio = document.createElement('audio') - const blipUrl = `${AO_HOST}sounds/blips/male.opus` - audio.setAttribute('class', 'blipSound') - audio.setAttribute('src', blipUrl) - document.body.appendChild(audio) - } -} -createBlip(6) -export default createBlip
\ No newline at end of file + for (let i = 0; i < amountOfBlips; i++) { + const audio = document.createElement('audio'); + const blipUrl = `${AO_HOST}sounds/blips/male.opus`; + audio.setAttribute('class', 'blipSound'); + audio.setAttribute('src', blipUrl); + document.body.appendChild(audio); + } +}; +createBlip(6); +export default createBlip; diff --git a/webAO/constants/transparentPng.js b/webAO/constants/transparentPng.js index f78dae0..452dad9 100644 --- a/webAO/constants/transparentPng.js +++ b/webAO/constants/transparentPng.js @@ -1 +1 @@ -export default 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
\ No newline at end of file +export default 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; diff --git a/webAO/dom/changeVolume.js b/webAO/dom/changeVolume.js index 0f7d47e..b79204a 100644 --- a/webAO/dom/changeVolume.js +++ b/webAO/dom/changeVolume.js @@ -1,4 +1,4 @@ -import setCookie from '../utils/setCookie'; +import setCookie from '../utils/setCookie.ts'; /** * Triggered by the sound effect volume slider. @@ -12,7 +12,7 @@ window.changeSFXVolume = changeSFXVolume; /** * Triggered by the testimony volume slider. */ - export function changeTestimonyVolume() { +export function changeTestimonyVolume() { setCookie('testimonyVolume', document.getElementById('client_testimonyaudio').volume); } window.changeTestimonyVolume = changeTestimonyVolume; diff --git a/webAO/dom/toggleElement.js b/webAO/dom/toggleElement.js index efddabf..b5481e8 100644 --- a/webAO/dom/toggleElement.js +++ b/webAO/dom/toggleElement.js @@ -3,11 +3,11 @@ * @param {string} element_id the id of the element to toggle */ export function toggleElement(element_id) { - const element = document.getElementById(element_id); - if (element.style.display !== 'none') { - element.style.display = 'none'; - } else { - element.style.display = 'block'; - } + const element = document.getElementById(element_id); + if (element.style.display !== 'none') { + element.style.display = 'none'; + } else { + element.style.display = 'block'; + } } window.toggleElement = toggleElement; diff --git a/webAO/ui.js b/webAO/ui.js index 0baad1d..69d4905 100644 --- a/webAO/ui.js +++ b/webAO/ui.js @@ -1,6 +1,4 @@ -/* eslint indent: ["error", 2] */ - -import { GoldenLayout } from "golden-layout"; +import { GoldenLayout } from 'golden-layout'; const config = { settings: { @@ -73,5 +71,4 @@ golden.registerComponentFactoryFunction('template', (container, componentState) // TODO: support multiple locales // container.setTitle(document.querySelector(`#${componentState.id} meta[name='frame-title']`).getAttribute("content")); }); -golden.loadLayout(config) - +golden.loadLayout(config); diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js index d6a40b6..6b9aed2 100644 --- a/webAO/utils/calculateApngLength.js +++ b/webAO/utils/calculateApngLength.js @@ -1,7 +1,7 @@ /** - * Adds up the chunk delays to find out how long a APNG is - * @param {data} apngFile the APNG data - */ + * Adds up the chunk delays to find out how long a APNG is + * @param {data} apngFile the APNG data + */ const calculateApngLength = (apngFile) => { const d = new Uint8Array(apngFile); // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk @@ -9,20 +9,20 @@ const calculateApngLength = (apngFile) => { for (let i = 0; i < d.length; i++) { // Find fcTL header (66 63 54 4C) if (d[i] === 0x66 - && d[i + 1] === 0x63 - && d[i + 2] === 0x54 - && d[i + 3] === 0x4C) { + && d[i + 1] === 0x63 + && d[i + 2] === 0x54 + && d[i + 3] === 0x4C) { // numerator and denominator - const delay_num = Number(d[i + 23]); - const delay_den = Number(d[i + 25]); + const delayNum = Number(d[i + 23]); + const delayDen = Number(d[i + 25]); let delay; // minimum is 100ms - if (delay_den == 0) - delay = delay_num / 100; + if (delayDen === 0) + delay = delayNum / 100; else - delay = delay_num / delay_den; + delay = delayNum / delayDen; - duration = duration + delay; + duration += delay; } } return duration * 10; diff --git a/webAO/utils/calculateGifLength.js b/webAO/utils/calculateGifLength.js index 1df0ba9..ca0e1e1 100644 --- a/webAO/utils/calculateGifLength.js +++ b/webAO/utils/calculateGifLength.js @@ -1,8 +1,8 @@ /** - * Adds up the frame delays to find out how long a GIF is - * I totally didn't steal this - * @param {data} gifFile the GIF data - */ + * Adds up the frame delays to find out how long a GIF is + * I totally didn't steal this + * @param {data} gifFile the GIF data + */ const calculateGifLength = (gifFile) => { const d = new Uint8Array(gifFile); // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/ @@ -11,9 +11,9 @@ const calculateGifLength = (gifFile) => { for (let i = 0; i < d.length; i++) { // Find a Graphic Control Extension hex(21F904__ ____ __00) if (d[i] === 0x21 - && d[i + 1] === 0xF9 - && d[i + 2] === 0x04 - && d[i + 7] === 0x00) { + && d[i + 1] === 0xF9 + && d[i + 2] === 0x04 + && d[i + 7] === 0x00) { // Swap 5th and 6th bytes to get the delay per frame const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF); diff --git a/webAO/utils/fileExistsSync.js b/webAO/utils/fileExistsSync.js deleted file mode 100644 index 1d7fde2..0000000 --- a/webAO/utils/fileExistsSync.js +++ /dev/null @@ -1,11 +0,0 @@ -const fileExistsSync = (url) => { - try { - const http = new XMLHttpRequest(); - http.open('HEAD', url, false); - http.send(); - return http.status != 404; - } catch (e) { - return false; - } -}; -export default fileExistsSync; diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js index aa303cf..f9d793f 100644 --- a/webAO/utils/getAnimLength.js +++ b/webAO/utils/getAnimLength.js @@ -1,11 +1,11 @@ import calculatorHandler from './calculatorHandler'; -import fileExists from './fileExists.js'; -import { requestBuffer } from '../services/request.js'; +import fileExists from './fileExists'; +import { requestBuffer } from '../services/request'; /** - * Gets animation length. If the animation cannot be found, it will - * silently fail and return 0 instead. - * @param {string} filename the animation file name - */ + * Gets animation length. If the animation cannot be found, it will + * silently fail and return 0 instead. + * @param {string} filename the animation file name + */ const getAnimLength = async (url) => { const extensions = ['.gif', '.webp', '.apng']; |
