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", "indent": "off",
"space-before-function-paren": ["off", "never"], "space-before-function-paren": ["off", "never"],
"@typescript-eslint/semi": ["error", "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/indent": ["error", 2],
"@typescript-eslint/space-before-function-paren": ["error", "never"], "@typescript-eslint/space-before-function-paren": ["error", "never"],
"@typescript-eslint/no-var-requires": ["off"], "@typescript-eslint/no-var-requires": ["off"],
@@ -33,6 +35,7 @@
] ]
}], }],
"@typescript-eslint/no-explicit-any": ["error"], "@typescript-eslint/no-explicit-any": ["error"],
"@typescript-eslint/ban-ts-ignore": ["off"],
"@typescript-eslint/interface-name-prefix": ["off"], "@typescript-eslint/interface-name-prefix": ["off"],
"@typescript-eslint/member-delimiter-style": ["error", { "@typescript-eslint/member-delimiter-style": ["error", {
"multiline": { "multiline": {

View File

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

View File

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

View File

@@ -111,13 +111,9 @@ export class ChartSidebarComponent implements OnInit {
* Converts <this.selectedVersion.song_length> into a readable duration. * Converts <this.selectedVersion.song_length> into a readable duration.
*/ */
updateSongLength() { updateSongLength() {
if (this.selectedVersion.song_length == 0) { if (this.selectedVersion.song_length == 0) { this.songLength = 'Unknown' }
this.songLength = 'Unknown'
}
let seconds = Math.round(this.selectedVersion.song_length / 1000) let seconds = Math.round(this.selectedVersion.song_length / 1000)
if (seconds < 60) { if (seconds < 60) { this.songLength = `${seconds} second${seconds == 1 ? '' : 's'}` }
this.songLength = `${seconds} second${seconds == 1 ? '' : 's'}`
}
let minutes = Math.floor(seconds / 60) let minutes = Math.floor(seconds / 60)
let hours = 0 let hours = 0
while (minutes > 59) { while (minutes > 59) {
@@ -182,10 +178,10 @@ export class ChartSidebarComponent implements OnInit {
onDownloadClicked() { onDownloadClicked() {
this.downloadService.addDownload( this.downloadService.addDownload(
this.selectedVersion.versionID, { this.selectedVersion.versionID, {
avTagName: this.selectedVersion.avTagName, avTagName: this.selectedVersion.avTagName,
artist: this.songResult.artist, artist: this.songResult.artist,
charter: this.selectedVersion.charters, //TODO: get the charter name associated with this particular version charter: this.selectedVersion.charters, // TODO: get the charter name associated with this particular version
links: JSON.parse(this.selectedVersion.downloadLink) links: JSON.parse(this.selectedVersion.downloadLink)
}) })
} }
} }

View File

@@ -10,14 +10,14 @@ import { SearchService } from 'src/app/core/services/search.service'
styleUrls: ['./result-table.component.scss'] styleUrls: ['./result-table.component.scss']
}) })
export class ResultTableComponent implements OnInit { export class ResultTableComponent implements OnInit {
@Output() rowClicked = new EventEmitter<SongResult>() @Output() rowClicked = new EventEmitter<SongResult>()
@Output() songChecked = new EventEmitter<SongResult>() @Output() songChecked = new EventEmitter<SongResult>()
@Output() songUnchecked = new EventEmitter<SongResult>() @Output() songUnchecked = new EventEmitter<SongResult>()
@ViewChild(CheckboxDirective, { static: true }) checkboxColumn: CheckboxDirective @ViewChild(CheckboxDirective, { static: true }) checkboxColumn: CheckboxDirective
@ViewChildren('tableRow') tableRows: QueryList<ResultTableRowComponent> @ViewChildren('tableRow') tableRows: QueryList<ResultTableRowComponent>
results: SongResult[] results: SongResult[]
constructor(private searchService: SearchService) { } constructor(private searchService: SearchService) { }

View File

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

View File

@@ -78,11 +78,11 @@ export class StatusBarComponent {
const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID) const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID)
this.downloadService.addDownload( this.downloadService.addDownload(
downloadVersion.versionID, { downloadVersion.versionID, {
avTagName: downloadVersion.avTagName, avTagName: downloadVersion.avTagName,
artist: downloadSong.artist, artist: downloadSong.artist,
charter: downloadVersion.charters, charter: downloadVersion.charters,
links: JSON.parse(downloadVersion.downloadLink) links: JSON.parse(downloadVersion.downloadLink)
}) })
} }
} else { } else {
$('#selectedModal').modal('show') $('#selectedModal').modal('show')
@@ -96,11 +96,11 @@ export class StatusBarComponent {
const downloadSong = this.selectedResults.find(song => song.id == version.songID) const downloadSong = this.selectedResults.find(song => song.id == version.songID)
this.downloadService.addDownload( this.downloadService.addDownload(
version.versionID, { version.versionID, {
avTagName: version.avTagName, avTagName: version.avTagName,
artist: downloadSong.artist, artist: downloadSong.artist,
charter: version.charters, charter: version.charters,
links: JSON.parse(version.downloadLink) links: JSON.parse(version.downloadLink)
}) })
} }
} }

View File

@@ -63,4 +63,4 @@ export class SearchService {
get allResultsVisible() { get allResultsVisible() {
return this._allResultsVisible return this._allResultsVisible
} }
} }

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,5 @@
import { IPCEmitHandler } from '../../shared/IPCHandler' import { IPCEmitHandler } from '../../shared/IPCHandler'
import { randomBytes as _randomBytes } from 'crypto'
import { Download } from '../../shared/interfaces/download.interface' import { Download } from '../../shared/interfaces/download.interface'
import { mkdir as _mkdir } from 'fs'
import { ChartDownload } from './ChartDownload' import { ChartDownload } from './ChartDownload'
class DownloadHandler implements IPCEmitHandler<'download'> { class DownloadHandler implements IPCEmitHandler<'download'> {
@@ -11,7 +9,7 @@ class DownloadHandler implements IPCEmitHandler<'download'> {
downloadQueue: ChartDownload[] = [] downloadQueue: ChartDownload[] = []
isGoogleDownloading = false // This is a lock controlled by only one ChartDownload at a time 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') { if (data.action == 'add') {
this.downloads[data.versionID] = new ChartDownload(data.versionID, data.data) 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 path from 'path'
import * as needle from 'needle' import * as needle from 'needle'
// TODO: replace needle with got (for cancel() method) (if before-headers event is possible?) // TODO: replace needle with got (for cancel() method) (if before-headers event is possible?)
import { getSettingsHandler } from '../SettingsHandler.ipc' import { getSettings } from '../SettingsHandler.ipc'
const getSettings = getSettingsHandler.getSettings
type EventCallback = { type EventCallback = {
'request': () => void 'request': () => void
@@ -16,7 +15,7 @@ type EventCallback = {
} }
type Callbacks = { [E in keyof EventCallback]: EventCallback[E] } 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`. * Downloads a file from `url` to `destinationFolder` and verifies that its hash matches `expectedHash`.
@@ -36,7 +35,7 @@ export class FileDownloader {
* @param expectedHash The hash header value that is expected for this file. * @param expectedHash The hash header value that is expected for this file.
*/ */
constructor(private url: string, private destinationFolder: string, private expectedHash?: string) { } constructor(private url: string, private destinationFolder: string, private expectedHash?: string) { }
/** /**
* Calls `callback` when `event` fires. * Calls `callback` when `event` fires.
*/ */
@@ -53,7 +52,7 @@ export class FileDownloader {
this.callbacks.error({ header: 'Library folder not specified', body: 'Please go to the settings to set your library folder.' }, () => this.beginDownload()) this.callbacks.error({ header: 'Library folder not specified', body: 'Please go to the settings to set your library folder.' }, () => this.beginDownload())
return return
} }
this.requestDownload() this.requestDownload()
} }
@@ -64,17 +63,17 @@ export class FileDownloader {
private requestDownload(cookieHeader?: string) { private requestDownload(cookieHeader?: string) {
if (this.wasCanceled) { return } // CANCEL POINT if (this.wasCanceled) { return } // CANCEL POINT
this.callbacks.request() this.callbacks.request()
let uuid = generateUUID() const uuid = generateUUID()
const req = needle.get(this.url, { const req = needle.get(this.url, {
follow_max: 10, 'follow_max': 10,
open_timeout: 5000, 'open_timeout': 5000,
headers: Object.assign({ 'headers': Object.assign({
'User-Agent': 'PostmanRuntime/7.22.0', 'User-Agent': 'PostmanRuntime/7.22.0',
'Referer': this.url, 'Referer': this.url,
'Accept': '*/*', 'Accept': '*/*',
'Postman-Token': uuid 'Postman-Token': uuid
}, },
(cookieHeader ? { 'Cookie': cookieHeader } : undefined) (cookieHeader ? { 'Cookie': cookieHeader } : undefined)
) )
}) })
@@ -99,7 +98,7 @@ export class FileDownloader {
return return
} }
let fileType = headers['content-type'] const fileType = headers['content-type']
if (fileType.startsWith('text/html')) { if (fileType.startsWith('text/html')) {
this.handleHTMLResponse(req, headers['set-cookie']) this.handleHTMLResponse(req, headers['set-cookie'])
} else { } else {
@@ -183,7 +182,7 @@ export class FileDownloader {
} else { } else {
// GDrive specific jazz // GDrive specific jazz
const filenameRegex = /filename="(.*?)"/g const filenameRegex = /filename="(.*?)"/g
let results = filenameRegex.exec(headers['content-disposition']) const results = filenameRegex.exec(headers['content-disposition'])
if (results == null) { if (results == null) {
console.log(`Warning: couldn't find filename in content-disposition header: [${headers['content-disposition']}]`) console.log(`Warning: couldn't find filename in content-disposition header: [${headers['content-disposition']}]`)
return 'unknownFilename' return 'unknownFilename'

View File

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

View File

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

View File

@@ -64,7 +64,7 @@ function createBridgeWindow() {
defaultHeight: 800, defaultHeight: 800,
path: dataPath path: dataPath
}) })
// Create the browser window // Create the browser window
mainWindow = createBrowserWindow(windowState) mainWindow = createBrowserWindow(windowState)

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 { red } from 'cli-color'
import { getRelativeFilepath } from './ElectronUtilFunctions' 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 */ /* SystemJS module definition */
declare var nodeModule: NodeModule declare let nodeModule: NodeModule
interface NodeModule { interface NodeModule {
id: string id: string
} }
// @ts-ignore // @ts-ignore
declare var window: Window declare let window: Window
declare var $: any declare let $: any
interface Window { interface Window {
process: any process: any
require: any require: any