Fixed eslint errors

This commit is contained in:
Geomitron
2020-03-14 17:33:07 -04:00
parent f8316d18e7
commit 0b4e50174d
19 changed files with 63 additions and 66 deletions

1
.eslintignore Normal file
View File

@@ -0,0 +1 @@
src/assets/semantic/**

View File

@@ -23,7 +23,9 @@
"indent": "off",
"space-before-function-paren": ["off", "never"],
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/brace-style": ["error"],
"@typescript-eslint/brace-style": ["error", "1tbs", {
"allowSingleLine": true
}],
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/space-before-function-paren": ["error", "never"],
"@typescript-eslint/no-var-requires": ["off"],
@@ -33,6 +35,7 @@
]
}],
"@typescript-eslint/no-explicit-any": ["error"],
"@typescript-eslint/ban-ts-ignore": ["off"],
"@typescript-eslint/interface-name-prefix": ["off"],
"@typescript-eslint/member-delimiter-style": ["error", {
"multiline": {

View File

@@ -90,7 +90,7 @@
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"eslintConfig": "./eslintrc.json",
"eslintConfig": "./.eslintrc.json",
"tsConfig": [
"./tsconfig.json"
],

View File

@@ -21,8 +21,8 @@ export class BrowseComponent implements AfterViewInit {
const $tableColumn = $('#table-column')
// TODO: on new search, scroll to the top
$tableColumn.on('scroll', () => {
let pos = $tableColumn[0].scrollTop + $tableColumn[0].offsetHeight
let max = $tableColumn[0].scrollHeight
const pos = $tableColumn[0].scrollTop + $tableColumn[0].offsetHeight
const max = $tableColumn[0].scrollHeight
if (pos >= max - 5) {
this.searchService.updateScroll()
}

View File

@@ -111,13 +111,9 @@ export class ChartSidebarComponent implements OnInit {
* Converts <this.selectedVersion.song_length> into a readable duration.
*/
updateSongLength() {
if (this.selectedVersion.song_length == 0) {
this.songLength = 'Unknown'
}
if (this.selectedVersion.song_length == 0) { this.songLength = 'Unknown' }
let seconds = Math.round(this.selectedVersion.song_length / 1000)
if (seconds < 60) {
this.songLength = `${seconds} second${seconds == 1 ? '' : 's'}`
}
if (seconds < 60) { this.songLength = `${seconds} second${seconds == 1 ? '' : 's'}` }
let minutes = Math.floor(seconds / 60)
let hours = 0
while (minutes > 59) {

View File

@@ -14,7 +14,7 @@ export class SearchBarComponent implements AfterViewInit {
$('.ui.dropdown').dropdown()
}
async onSearch(query: string) {
onSearch(query: string) {
this.searchService.newSearch(query)
}
}

View File

@@ -21,7 +21,7 @@ export class TabPersistStrategy extends RouteReuseStrategy {
if (!route.routeConfig) return null
return this.handles[route.routeConfig.path]
}
shouldReuseRoute(future: ActivatedRouteSnapshot, _curr: ActivatedRouteSnapshot) {
shouldReuseRoute(future: ActivatedRouteSnapshot) {
return future.data.shouldReuse || false
}
}

View File

@@ -89,3 +89,4 @@ class SetSettingsHandler implements IPCEmitHandler<'set-settings'> {
export const getSettingsHandler = new GetSettingsHandler()
export const setSettingsHandler = new SetSettingsHandler()
export function getSettings() { return getSettingsHandler.getSettings() }

View File

@@ -17,7 +17,7 @@ const mkdir = promisify(_mkdir)
export class ChartDownload {
// This changes if the user needs to click 'retry' or 'continue'
run: () => void | Promise<void> = this.beginDownload
run: () => void | Promise<void> = this.beginDownload.bind(this)
cancel: () => void
isArchive: boolean
@@ -51,7 +51,7 @@ export class ChartDownload {
this.header = ''
this.description = 'Waiting for other downloads to finish...'
this.type = 'good'
this.cancel = () => { }
this.cancel = () => { /* do nothing */ }
emitIPCEvent('download-updated', this)
}
@@ -64,7 +64,7 @@ export class ChartDownload {
try {
chartPath = await this.createDownloadFolder()
} catch (e) {
this.run = this.beginDownload // Retry action
this.run = this.beginDownload.bind(this) // Retry action
this.error('Access Error', e.message)
return
}

View File

@@ -1,7 +1,5 @@
import { IPCEmitHandler } from '../../shared/IPCHandler'
import { randomBytes as _randomBytes } from 'crypto'
import { Download } from '../../shared/interfaces/download.interface'
import { mkdir as _mkdir } from 'fs'
import { ChartDownload } from './ChartDownload'
class DownloadHandler implements IPCEmitHandler<'download'> {
@@ -11,7 +9,7 @@ class DownloadHandler implements IPCEmitHandler<'download'> {
downloadQueue: ChartDownload[] = []
isGoogleDownloading = false // This is a lock controlled by only one ChartDownload at a time
async handler(data: Download) {
handler(data: Download) {
if (data.action == 'add') {
this.downloads[data.versionID] = new ChartDownload(data.versionID, data.data)
}

View File

@@ -3,8 +3,7 @@ import * as fs from 'fs'
import * as path from 'path'
import * as needle from 'needle'
// TODO: replace needle with got (for cancel() method) (if before-headers event is possible?)
import { getSettingsHandler } from '../SettingsHandler.ipc'
const getSettings = getSettingsHandler.getSettings
import { getSettings } from '../SettingsHandler.ipc'
type EventCallback = {
'request': () => void
@@ -16,7 +15,7 @@ type EventCallback = {
}
type Callbacks = { [E in keyof EventCallback]: EventCallback[E] }
export type DownloadError = { header: string, body: string }
export type DownloadError = { header: string; body: string }
/**
* Downloads a file from `url` to `destinationFolder` and verifies that its hash matches `expectedHash`.
@@ -64,11 +63,11 @@ export class FileDownloader {
private requestDownload(cookieHeader?: string) {
if (this.wasCanceled) { return } // CANCEL POINT
this.callbacks.request()
let uuid = generateUUID()
const uuid = generateUUID()
const req = needle.get(this.url, {
follow_max: 10,
open_timeout: 5000,
headers: Object.assign({
'follow_max': 10,
'open_timeout': 5000,
'headers': Object.assign({
'User-Agent': 'PostmanRuntime/7.22.0',
'Referer': this.url,
'Accept': '*/*',
@@ -99,7 +98,7 @@ export class FileDownloader {
return
}
let fileType = headers['content-type']
const fileType = headers['content-type']
if (fileType.startsWith('text/html')) {
this.handleHTMLResponse(req, headers['set-cookie'])
} else {
@@ -183,7 +182,7 @@ export class FileDownloader {
} else {
// GDrive specific jazz
const filenameRegex = /filename="(.*?)"/g
let results = filenameRegex.exec(headers['content-disposition'])
const results = filenameRegex.exec(headers['content-disposition'])
if (results == null) {
console.log(`Warning: couldn't find filename in content-disposition header: [${headers['content-disposition']}]`)
return 'unknownFilename'

View File

@@ -4,9 +4,8 @@ import { promisify } from 'util'
import { join, extname } from 'path'
import * as node7z from 'node-7z'
import * as zipBin from '7zip-bin'
import { getSettingsHandler } from '../SettingsHandler.ipc'
import { getSettings } from '../SettingsHandler.ipc'
import { extractRar } from './RarExtractor'
const getSettings = getSettingsHandler.getSettings
const readdir = promisify(fs.readdir)
const unlink = promisify(fs.unlink)
@@ -21,7 +20,7 @@ type EventCallback = {
'extractProgress': (percent: number, fileCount: number) => void
'transfer': (filepath: string) => void
'complete': (filepath: string) => void
'error': (error: DownloadError, retry: () => void) => void
'error': (error: DownloadError, retry: () => void | Promise<void>) => void
}
type Callbacks = { [E in keyof EventCallback]: EventCallback[E] }
@@ -70,9 +69,7 @@ export class FileExtractor {
this.callbacks.error({
header: 'Extract Failed.',
body: `Unable to extract [${filename}]: ${err}`
},
() => this.extract(filename, extname(filename) == '.rar')
)
}, () => this.extract(filename, extname(filename) == '.rar'))
return
}
this.transfer(source)
@@ -82,7 +79,7 @@ export class FileExtractor {
// Use node-7z to extract the archive
const stream = node7z.extractFull(source, this.sourceFolder, { $progress: true, $bin: zipBin.path7za })
stream.on('progress', (progress: { percent: number, fileCount: number }) => {
stream.on('progress', (progress: { percent: number; fileCount: number }) => {
this.callbacks.extractProgress(progress.percent, progress.fileCount)
})
@@ -107,6 +104,7 @@ export class FileExtractor {
*/
private async transfer(archiveFilepath?: string) {
// TODO: this fails if the extracted chart has nested folders
// TODO: skip over "__MACOSX" folder
if (this.wasCanceled) { return } // CANCEL POINT
try {

View File

@@ -1,5 +1,4 @@
import { getSettingsHandler } from '../SettingsHandler.ipc'
const getSettings = getSettingsHandler.getSettings
import { getSettings } from '../SettingsHandler.ipc'
class GoogleTimer {

View File

@@ -1,3 +1,4 @@
/* eslint @typescript-eslint/no-explicit-any: 0 */ // Using any is required because that type is required in catch statements
import { red } from 'cli-color'
import { getRelativeFilepath } from './ElectronUtilFunctions'

7
src/typings.d.ts vendored
View File

@@ -1,12 +1,13 @@
/* eslint @typescript-eslint/no-explicit-any: 0 */ // Semantic adds functions to JQuery in a way that can't be type checked
/* SystemJS module definition */
declare var nodeModule: NodeModule
declare let nodeModule: NodeModule
interface NodeModule {
id: string
}
// @ts-ignore
declare var window: Window
declare var $: any
declare let window: Window
declare let $: any
interface Window {
process: any
require: any