workflow: added linter and linted src/ folder

This commit is contained in:
Roberto Tonino
2021-05-23 18:46:03 +02:00
parent 0f2a1103fd
commit 3a58636d36
61 changed files with 7343 additions and 2498 deletions

View File

@@ -5,7 +5,7 @@ export function fetchData(key, data = {}, method = 'GET') {
url.searchParams.append(key, data[key])
})
return fetch(url.href, {method})
return fetch(url.href, { method })
.then(response => response.json())
.catch(() => {})
}

View File

@@ -1,6 +1,6 @@
export const COUNTRIES = {
AF: 'Afghanistan',
AX: '\u00c5land Islands',
AX: '\u00C5land Islands',
AL: 'Albania',
DZ: 'Algeria',
AS: 'American Samoa',
@@ -53,10 +53,10 @@ export const COUNTRIES = {
CD: 'Congo, the Democratic Republic of the',
CK: 'Cook Islands',
CR: 'Costa Rica',
CI: "C\u00f4te d'Ivoire",
CI: "C\u00F4te d'Ivoire",
HR: 'Croatia',
CU: 'Cuba',
CW: 'Cura\u00e7ao',
CW: 'Cura\u00E7ao',
CY: 'Cyprus',
CZ: 'Czech Republic',
DK: 'Denmark',
@@ -179,11 +179,11 @@ export const COUNTRIES = {
PT: 'Portugal',
PR: 'Puerto Rico',
QA: 'Qatar',
RE: 'R\u00e9union',
RE: 'R\u00E9union',
RO: 'Romania',
RU: 'Russian Federation',
RW: 'Rwanda',
BL: 'Saint Barth\u00e9lemy',
BL: 'Saint Barth\u00E9lemy',
SH: 'Saint Helena, Ascension and Tristan da Cunha',
KN: 'Saint Kitts and Nevis',
LC: 'Saint Lucia',

View File

@@ -4,7 +4,7 @@
* therefore it's considered a new release, if referring to a track or album
*/
export function checkNewRelease(dateToCheck) {
let now = new Date()
const now = new Date()
now.setHours(0, 0, 0, 0)
dateToCheck = new Date(dateToCheck)

View File

@@ -11,7 +11,7 @@ export function sendAddToQueue(url, bitrate = null) {
}
export function aggregateDownloadLinks(releases) {
let links = []
const links = []
releases.forEach(release => {
links.push(release.link)

View File

@@ -3,13 +3,15 @@ class CustomSocket extends WebSocket {
super(args)
this.listeners = {}
}
emit(key, data) {
if (this.readyState !== WebSocket.OPEN) return false
this.send(JSON.stringify({ key, data }))
}
on(key, cb) {
if (Object.keys(this.listeners).indexOf(key) == -1){
if (!Object.keys(this.listeners).includes(key)) {
console.log('on:', key)
this.listeners[key] = cb
@@ -21,10 +23,10 @@ class CustomSocket extends WebSocket {
}
})
}
}
off(key) {
if (Object.keys(this.listeners).indexOf(key) != -1){
if (Object.keys(this.listeners).includes(key)) {
console.log('off:', key)
this.removeEventListener('message', this.listeners[key])
delete this.listeners[key]

View File

@@ -9,13 +9,13 @@ const sharedOptions = {
position: 'left'
}
let toastsWithId = {}
const toastsWithId = {}
export const toast = function(msg, icon = null, dismiss = true, id = null) {
export const toast = function (msg, icon = null, dismiss = true, id = null) {
if (toastsWithId[id]) {
let toastObj = toastsWithId[id]
const toastObj = toastsWithId[id]
let toastElement = document.querySelectorAll(`div.toastify[toast_id=${id}]`)
const toastElement = document.querySelectorAll(`div.toastify[toast_id=${id}]`)
if (msg) {
toastElement.forEach(toast => {
@@ -28,15 +28,15 @@ export const toast = function(msg, icon = null, dismiss = true, id = null) {
}
if (icon) {
let iconNode = document.createElement('span')
const iconNode = document.createElement('span')
iconNode.classList.add('toast-icon')
if (icon == 'loading') {
let loader = document.createElement('div')
const loader = document.createElement('div')
loader.classList.add('circle-loader')
iconNode.appendChild(loader)
} else {
let materialIcon = document.createElement('i')
const materialIcon = document.createElement('i')
materialIcon.classList.add('material-icons')
materialIcon.appendChild(document.createTextNode(icon))
iconNode.appendChild(materialIcon)
@@ -62,41 +62,41 @@ export const toast = function(msg, icon = null, dismiss = true, id = null) {
}, 3000)
}
} else {
let iconNode = document.createElement('span')
const iconNode = document.createElement('span')
iconNode.classList.add('toast-icon')
if (icon == null) {
iconNode.appendChild(document.createTextNode(''))
} else if (icon == 'loading') {
let loader = document.createElement('div')
const loader = document.createElement('div')
loader.classList.add('circle-loader')
iconNode.appendChild(loader)
} else {
let materialIcon = document.createElement('i')
const materialIcon = document.createElement('i')
materialIcon.classList.add('material-icons')
materialIcon.appendChild(document.createTextNode(icon))
iconNode.appendChild(materialIcon)
}
let messageNode = document.createElement('span')
const messageNode = document.createElement('span')
messageNode.classList.add('toast-message')
messageNode.appendChild(document.createTextNode(msg))
let toastNode = document.createElement('toast')
const toastNode = document.createElement('toast')
toastNode.appendChild(iconNode)
toastNode.appendChild(messageNode)
let toastObj = Toastify({
const toastObj = Toastify({
...sharedOptions,
node: toastNode,
duration: dismiss ? 3000 : 0,
className: dismiss ? 'dismissable' : '',
onClick: function() {
onClick() {
let dismissable = true
if (id) {
let toastClasses = document.querySelector(`div.toastify[toast_id=${id}]`).classList
const toastClasses = document.querySelector(`div.toastify[toast_id=${id}]`).classList
if (toastClasses) {
dismissable = Array.prototype.slice.call(toastClasses).indexOf('dismissable') != -1
dismissable = Array.prototype.slice.call(toastClasses).includes('dismissable')
}
}
if (toastObj && dismissable) {
@@ -108,7 +108,7 @@ export const toast = function(msg, icon = null, dismiss = true, id = null) {
}
},
offset: {
x: 'true' === localStorage.getItem('slimSidebar') ? '3rem': '14rem'
x: localStorage.getItem('slimSidebar') === 'true' ? '3rem' : '14rem'
}
}).showToast()
if (id) {

View File

@@ -8,7 +8,7 @@ export function generatePath(el) {
throw new Error('No element passed to the generatePath function!')
}
let path = [el]
const path = [el]
while ((el = el.parentNode) && el !== document) {
path.push(el)
@@ -18,14 +18,14 @@ export function generatePath(el) {
}
export function isValidURL(text) {
let lowerCaseText = text.toLowerCase()
const lowerCaseText = text.toLowerCase()
if (lowerCaseText.startsWith('http')) {
if (
lowerCaseText.indexOf('deezer.com') >= 0 ||
lowerCaseText.indexOf('deezer.page.link') >= 0 ||
lowerCaseText.indexOf('open.spotify.com') >= 0 ||
lowerCaseText.indexOf('link.tospotify.com') >= 0
lowerCaseText.includes('deezer.com') ||
lowerCaseText.includes('deezer.page.link') ||
lowerCaseText.includes('open.spotify.com') ||
lowerCaseText.includes('link.tospotify.com')
) {
return true
}
@@ -63,15 +63,15 @@ export function numberWithDots(x) {
// On scroll event, returns currentTarget = null
// Probably on other events too
export function debounce(func, wait, immediate) {
var timeout
return function() {
var context = this
var args = arguments
var later = function() {
let timeout
return function () {
const context = this
const args = arguments
const later = function () {
timeout = null
if (!immediate) func.apply(context, args)
}
var callNow = immediate && !timeout
const callNow = immediate && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)
if (callNow) func.apply(context, args)
@@ -104,10 +104,10 @@ export function copyToClipboard(text) {
export function getPropertyWithFallback(obj, ...props) {
for (const prop of props) {
// Example: this.is.an.example
let hasDotNotation = /\./.test(prop)
const hasDotNotation = /\./.test(prop)
// Searching the properties in the object
let valueToTest = hasDotNotation
const valueToTest = hasDotNotation
? prop.split('.').reduce((o, i) => {
if (o) {
return o[i]
@@ -115,7 +115,7 @@ export function getPropertyWithFallback(obj, ...props) {
}, obj)
: obj[prop]
if ('undefined' !== typeof valueToTest) {
if (typeof valueToTest !== 'undefined') {
return valueToTest
}
}