From 0b4e50174d1749f8ad5c7c3baf0b84817729ead8 Mon Sep 17 00:00:00 2001 From: Geomitron <22552797+Geomitron@users.noreply.github.com> Date: Sat, 14 Mar 2020 17:33:07 -0400 Subject: [PATCH] Fixed eslint errors --- .eslintignore | 1 + eslintrc.json => .eslintrc.json | 5 +++- angular.json | 2 +- src/app/components/browse/browse.component.ts | 4 ++-- .../chart-sidebar/chart-sidebar.component.ts | 18 ++++++--------- .../result-table/result-table.component.ts | 6 ++--- .../browse/search-bar/search-bar.component.ts | 2 +- .../browse/status-bar/status-bar.component.ts | 20 ++++++++-------- src/app/core/services/search.service.ts | 2 +- src/app/core/tab-persist.strategy.ts | 2 +- src/electron/ipc/SettingsHandler.ipc.ts | 3 ++- src/electron/ipc/download/ChartDownload.ts | 6 ++--- src/electron/ipc/download/DownloadHandler.ts | 4 +--- src/electron/ipc/download/FileDownloader.ts | 23 +++++++++---------- src/electron/ipc/download/FileExtractor.ts | 18 +++++++-------- src/electron/ipc/download/GoogleTimer.ts | 3 +-- src/electron/main.ts | 2 +- src/electron/shared/ErrorMessages.ts | 1 + src/typings.d.ts | 7 +++--- 19 files changed, 63 insertions(+), 66 deletions(-) create mode 100644 .eslintignore rename eslintrc.json => .eslintrc.json (92%) diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..66d8513 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +src/assets/semantic/** \ No newline at end of file diff --git a/eslintrc.json b/.eslintrc.json similarity index 92% rename from eslintrc.json rename to .eslintrc.json index a7e5774..99fc6bb 100644 --- a/eslintrc.json +++ b/.eslintrc.json @@ -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": { diff --git a/angular.json b/angular.json index e72ce7d..7f3f7c1 100644 --- a/angular.json +++ b/angular.json @@ -90,7 +90,7 @@ "lint": { "builder": "@angular-eslint/builder:lint", "options": { - "eslintConfig": "./eslintrc.json", + "eslintConfig": "./.eslintrc.json", "tsConfig": [ "./tsconfig.json" ], diff --git a/src/app/components/browse/browse.component.ts b/src/app/components/browse/browse.component.ts index 265759d..ca389e5 100644 --- a/src/app/components/browse/browse.component.ts +++ b/src/app/components/browse/browse.component.ts @@ -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() } diff --git a/src/app/components/browse/chart-sidebar/chart-sidebar.component.ts b/src/app/components/browse/chart-sidebar/chart-sidebar.component.ts index f42b0b4..63402ac 100644 --- a/src/app/components/browse/chart-sidebar/chart-sidebar.component.ts +++ b/src/app/components/browse/chart-sidebar/chart-sidebar.component.ts @@ -111,13 +111,9 @@ export class ChartSidebarComponent implements OnInit { * Converts 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) { @@ -182,10 +178,10 @@ export class ChartSidebarComponent implements OnInit { onDownloadClicked() { this.downloadService.addDownload( this.selectedVersion.versionID, { - avTagName: this.selectedVersion.avTagName, - artist: this.songResult.artist, - charter: this.selectedVersion.charters, //TODO: get the charter name associated with this particular version - links: JSON.parse(this.selectedVersion.downloadLink) - }) + avTagName: this.selectedVersion.avTagName, + artist: this.songResult.artist, + charter: this.selectedVersion.charters, // TODO: get the charter name associated with this particular version + links: JSON.parse(this.selectedVersion.downloadLink) + }) } } \ No newline at end of file diff --git a/src/app/components/browse/result-table/result-table.component.ts b/src/app/components/browse/result-table/result-table.component.ts index 5d48fb4..e3b35f8 100644 --- a/src/app/components/browse/result-table/result-table.component.ts +++ b/src/app/components/browse/result-table/result-table.component.ts @@ -10,14 +10,14 @@ import { SearchService } from 'src/app/core/services/search.service' styleUrls: ['./result-table.component.scss'] }) export class ResultTableComponent implements OnInit { - + @Output() rowClicked = new EventEmitter() @Output() songChecked = new EventEmitter() @Output() songUnchecked = new EventEmitter() - + @ViewChild(CheckboxDirective, { static: true }) checkboxColumn: CheckboxDirective @ViewChildren('tableRow') tableRows: QueryList - + results: SongResult[] constructor(private searchService: SearchService) { } diff --git a/src/app/components/browse/search-bar/search-bar.component.ts b/src/app/components/browse/search-bar/search-bar.component.ts index f35b35d..9c6ecb8 100644 --- a/src/app/components/browse/search-bar/search-bar.component.ts +++ b/src/app/components/browse/search-bar/search-bar.component.ts @@ -14,7 +14,7 @@ export class SearchBarComponent implements AfterViewInit { $('.ui.dropdown').dropdown() } - async onSearch(query: string) { + onSearch(query: string) { this.searchService.newSearch(query) } } \ No newline at end of file diff --git a/src/app/components/browse/status-bar/status-bar.component.ts b/src/app/components/browse/status-bar/status-bar.component.ts index ac3ed25..c85f656 100644 --- a/src/app/components/browse/status-bar/status-bar.component.ts +++ b/src/app/components/browse/status-bar/status-bar.component.ts @@ -78,11 +78,11 @@ export class StatusBarComponent { const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID) this.downloadService.addDownload( downloadVersion.versionID, { - avTagName: downloadVersion.avTagName, - artist: downloadSong.artist, - charter: downloadVersion.charters, - links: JSON.parse(downloadVersion.downloadLink) - }) + avTagName: downloadVersion.avTagName, + artist: downloadSong.artist, + charter: downloadVersion.charters, + links: JSON.parse(downloadVersion.downloadLink) + }) } } else { $('#selectedModal').modal('show') @@ -96,11 +96,11 @@ export class StatusBarComponent { const downloadSong = this.selectedResults.find(song => song.id == version.songID) this.downloadService.addDownload( version.versionID, { - avTagName: version.avTagName, - artist: downloadSong.artist, - charter: version.charters, - links: JSON.parse(version.downloadLink) - }) + avTagName: version.avTagName, + artist: downloadSong.artist, + charter: version.charters, + links: JSON.parse(version.downloadLink) + }) } } diff --git a/src/app/core/services/search.service.ts b/src/app/core/services/search.service.ts index b50b4b8..08bbace 100644 --- a/src/app/core/services/search.service.ts +++ b/src/app/core/services/search.service.ts @@ -63,4 +63,4 @@ export class SearchService { get allResultsVisible() { return this._allResultsVisible } -} +} \ No newline at end of file diff --git a/src/app/core/tab-persist.strategy.ts b/src/app/core/tab-persist.strategy.ts index 2a23bf9..16350ea 100644 --- a/src/app/core/tab-persist.strategy.ts +++ b/src/app/core/tab-persist.strategy.ts @@ -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 } } \ No newline at end of file diff --git a/src/electron/ipc/SettingsHandler.ipc.ts b/src/electron/ipc/SettingsHandler.ipc.ts index 70f8fb1..f136578 100644 --- a/src/electron/ipc/SettingsHandler.ipc.ts +++ b/src/electron/ipc/SettingsHandler.ipc.ts @@ -88,4 +88,5 @@ class SetSettingsHandler implements IPCEmitHandler<'set-settings'> { } export const getSettingsHandler = new GetSettingsHandler() -export const setSettingsHandler = new SetSettingsHandler() \ No newline at end of file +export const setSettingsHandler = new SetSettingsHandler() +export function getSettings() { return getSettingsHandler.getSettings() } \ No newline at end of file diff --git a/src/electron/ipc/download/ChartDownload.ts b/src/electron/ipc/download/ChartDownload.ts index 834cdee..4b57105 100644 --- a/src/electron/ipc/download/ChartDownload.ts +++ b/src/electron/ipc/download/ChartDownload.ts @@ -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 = this.beginDownload + run: () => void | Promise = 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 } diff --git a/src/electron/ipc/download/DownloadHandler.ts b/src/electron/ipc/download/DownloadHandler.ts index cb7ecd9..4bd3ca0 100644 --- a/src/electron/ipc/download/DownloadHandler.ts +++ b/src/electron/ipc/download/DownloadHandler.ts @@ -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) } diff --git a/src/electron/ipc/download/FileDownloader.ts b/src/electron/ipc/download/FileDownloader.ts index 02ca915..b957674 100644 --- a/src/electron/ipc/download/FileDownloader.ts +++ b/src/electron/ipc/download/FileDownloader.ts @@ -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`. @@ -36,7 +35,7 @@ export class FileDownloader { * @param expectedHash The hash header value that is expected for this file. */ constructor(private url: string, private destinationFolder: string, private expectedHash?: string) { } - + /** * 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()) return } - + this.requestDownload() } @@ -64,17 +63,17 @@ 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': '*/*', 'Postman-Token': uuid }, - (cookieHeader ? { 'Cookie': cookieHeader } : undefined) + (cookieHeader ? { 'Cookie': cookieHeader } : undefined) ) }) @@ -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' diff --git a/src/electron/ipc/download/FileExtractor.ts b/src/electron/ipc/download/FileExtractor.ts index 5ef1874..d3e5483 100644 --- a/src/electron/ipc/download/FileExtractor.ts +++ b/src/electron/ipc/download/FileExtractor.ts @@ -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 } type Callbacks = { [E in keyof EventCallback]: EventCallback[E] } @@ -68,11 +67,9 @@ export class FileExtractor { await extractRar(source, this.sourceFolder) } catch (err) { this.callbacks.error({ - header: 'Extract Failed.', - body: `Unable to extract [${filename}]: ${err}` - }, - () => this.extract(filename, extname(filename) == '.rar') - ) + header: 'Extract Failed.', + body: `Unable to extract [${filename}]: ${err}` + }, () => 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,9 +104,10 @@ 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 { - + // Create destiniation folder if it doesn't exist const destinationFolder = join(this.libraryFolder, this.destinationFolderName) this.callbacks.transfer(destinationFolder) diff --git a/src/electron/ipc/download/GoogleTimer.ts b/src/electron/ipc/download/GoogleTimer.ts index efd3b3b..8e7e173 100644 --- a/src/electron/ipc/download/GoogleTimer.ts +++ b/src/electron/ipc/download/GoogleTimer.ts @@ -1,5 +1,4 @@ -import { getSettingsHandler } from '../SettingsHandler.ipc' -const getSettings = getSettingsHandler.getSettings +import { getSettings } from '../SettingsHandler.ipc' class GoogleTimer { diff --git a/src/electron/main.ts b/src/electron/main.ts index 07ca6f8..94b8000 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -64,7 +64,7 @@ function createBridgeWindow() { defaultHeight: 800, path: dataPath }) - + // Create the browser window mainWindow = createBrowserWindow(windowState) diff --git a/src/electron/shared/ErrorMessages.ts b/src/electron/shared/ErrorMessages.ts index 63e3088..3bbeccb 100644 --- a/src/electron/shared/ErrorMessages.ts +++ b/src/electron/shared/ErrorMessages.ts @@ -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' diff --git a/src/typings.d.ts b/src/typings.d.ts index 4e2ed13..6e17b8d 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -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