Skip to content

Commit

Permalink
refactor: re-order linter rules, fix linter warnings and misc cleanup
Browse files Browse the repository at this point in the history
* Reorder the linter rules in alphabetical order
* Install types for dependency "follow-redirects"
* Fix 7 linter warnings
* Do misc style changes to make the code look prettier imo
  • Loading branch information
TBubba committed Jun 18, 2020
1 parent ab52bea commit 6286602
Show file tree
Hide file tree
Showing 34 changed files with 109 additions and 117 deletions.
24 changes: 12 additions & 12 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@
"root": true,
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "off",
"@typescript-eslint/ban-types": ["warn", {
"types": {
"{}": false
},
"extendDefaults": true
}],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/indent": ["warn", 2, {
"MemberExpression": 0,
"SwitchCase": 1
}],
"@typescript-eslint/no-empty-function": ["warn", { "allow": ["arrowFunctions"] }],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/prefer-interface": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": ["warn", {
"vars": "all",
"args": "none"
}],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-empty-function": ["warn", { "allow": ["arrowFunctions"] }],
"@typescript-eslint/ban-types": ["warn", {
"types": {
"{}": false
},
"extendDefaults": true
}],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/prefer-interface": "off",
"react/no-unescaped-entities": ["error", {"forbid": [{
"char": ">",
"alternatives": [">"]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@types/enzyme": "3.10.5",
"@types/enzyme-adapter-react-16": "1.0.6",
"@types/enzyme-to-json": "1.5.3",
"@types/follow-redirects": "1.8.0",
"@types/fs-extra": "8.1.0",
"@types/jest": "24.0.17",
"@types/mime": "2.0.1",
Expand Down
12 changes: 6 additions & 6 deletions src/back/ConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import { IAppConfigData } from '@shared/config/interfaces';
import { deepCopy, readJsonFile, stringifyJsonDataFile, readJsonFileSync } from '@shared/Util';
import { getDefaultConfigData, overwriteConfigData } from '@shared/config/util';
import { deepCopy, readJsonFile, readJsonFileSync, stringifyJsonDataFile } from '@shared/Util';
import * as fs from 'fs';

export namespace ConfigFile {
export function readFile(filePath: string, onError?: (error: string) => void): Promise<IAppConfigData> {
Expand All @@ -17,8 +17,8 @@ export namespace ConfigFile {
}

export async function readOrCreateFile(filePath: string, onError?: (error: string) => void): Promise<IAppConfigData> {
let error: Error | undefined,
data: IAppConfigData | undefined;
let error: Error | undefined;
let data: IAppConfigData | undefined;

try {
data = await readFile(filePath, onError);
Expand All @@ -35,8 +35,8 @@ export namespace ConfigFile {
}

export function readOrCreateFileSync(filePath: string, onError?: (error: string) => void): IAppConfigData {
let error: Error | undefined,
data: IAppConfigData | undefined;
let error: Error | undefined;
let data: IAppConfigData | undefined;

try {
data = readFileSync(filePath, onError);
Expand Down
11 changes: 4 additions & 7 deletions src/back/game/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export namespace GameManager {
export async function findGameRow(gameId: string, filterOpts?: FilterGameOpts, orderBy?: GameOrderBy, direction?: GameOrderReverse, index?: PageTuple): Promise<number> {
if (orderBy) { validateSqlName(orderBy); }

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const startTime = Date.now();
// const startTime = Date.now();
const gameRepository = getManager().getRepository(Game);

const subQ = gameRepository.createQueryBuilder('game')
Expand Down Expand Up @@ -92,7 +91,7 @@ export namespace GameManager {
}

export async function findGamePageKeyset(filterOpts: FilterGameOpts, orderBy: GameOrderBy, direction: GameOrderReverse): Promise<GetPageKeysetResult> {
let startTime = Date.now();
// let startTime = Date.now();

validateSqlName(orderBy);
validateSqlOrder(direction);
Expand All @@ -119,8 +118,7 @@ export namespace GameManager {

// Count games
let total = -1;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
startTime = Date.now();
// startTime = Date.now();
query = await getGameQuery('sub', filterOpts, orderBy, direction, 0, undefined, undefined);

query.skip(0);
Expand Down Expand Up @@ -158,8 +156,7 @@ export namespace GameManager {

let query: SelectQueryBuilder<Game> | undefined;
for (let i = 0; i < ranges.length; i++) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const startTime = Date.now();
// const startTime = Date.now();

const range = ranges[i];
query = await getGameQuery('game', opts.filter, opts.orderBy, opts.direction, range.start, range.length, range.index);
Expand Down
10 changes: 4 additions & 6 deletions src/back/importGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export async function importCuration(opts: ImportCurationOpts): Promise<void> {
imageFolderPath: imagePath,
} = opts;

const logMsg = logMessage;

// TODO: Consider moving this check outside importCuration
// Warn if launch command is already present on another game
if (curation.meta.launchCommand) {
Expand Down Expand Up @@ -105,17 +103,17 @@ export async function importCuration(opts: ImportCurationOpts): Promise<void> {
const moveFiles = !saveCuration;
curationLog(log, 'Importing Curation Meta');
// Copy/extract content and image files
GameManager.updateGame(game).then(() => logMsg('Meta Added', curation));
GameManager.updateGame(game).then(() => logMessage('Meta Added', curation));

// Copy Thumbnail
curationLog(log, 'Importing Curation Thumbnail');
await importGameImage(curation.thumbnail, game.id, LOGOS, path.join(fpPath, imagePath), log)
.then(() => { if (log) { logMsg('Thumbnail Copied', curation); } });
.then(() => { if (log) { logMessage('Thumbnail Copied', curation); } });

// Copy Screenshot
curationLog(log, 'Importing Curation Screenshot');
await importGameImage(curation.screenshot, game.id, SCREENSHOTS, path.join(fpPath, imagePath), log)
.then(() => { if (log) { logMsg('Screenshot Copied', curation); } });
.then(() => { if (log) { logMessage('Screenshot Copied', curation); } });

// Copy content and Extra files
curationLog(log, 'Importing Curation Content');
Expand All @@ -142,7 +140,7 @@ export async function importCuration(opts: ImportCurationOpts): Promise<void> {
await copyFolder(getCurationFolder(curation, fpPath), backupPath, true, opts.openDialog, log);
}
if (log) {
logMsg('Content Copied', curation);
logMessage('Content Copied', curation);
}
} catch (error) {
curationLog(log, `Error importing ${curation.meta.title} - Informing user...`);
Expand Down
6 changes: 2 additions & 4 deletions src/back/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ export function registerRequestCallbacks(state: BackState): void {
}
}
newPlaylist.games = existingPlaylist.games;
break;
}
} break;
case 1: {
const newPlaylistId = uuid();
newPlaylist.id = newPlaylistId;
Expand All @@ -391,8 +390,7 @@ export function registerRequestCallbacks(state: BackState): void {
g.playlistId = newPlaylistId;
return g;
});
break;
}
} break;
default:
throw 'User Cancelled';
}
Expand Down
20 changes: 10 additions & 10 deletions src/back/util/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { randomBytes } from 'crypto';

// Work around synchronously seeding of random buffer in the v1
// version of uuid by explicitly only requiring v4. As far as I'm
// aware we cannot use an import statement here without causing webpack
// to load the v1 version as well.
//
// See
// https://github.com/kelektiv/node-uuid/issues/189
const guid = require('uuid/v4') as (options?: { random?: Buffer }) => string;
import * as guid from 'uuid/v4';

/**
* Wrapper function over uuid's v4 method that attempts to source
* entropy using the window Crypto instance rather than through
* Node.JS.
*/
export function uuid() {
return guid({ random: randomBytes(16) });
return guid({ random: bufferToNumbers(randomBytes(16)) });
}

function bufferToNumbers(buffer: Buffer): number[] {
const array: number[] = [];
for (let i = 0; i < buffer.length; i++) {
array[i] = buffer[i];
}
return array;
}
2 changes: 1 addition & 1 deletion src/renderer/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class App extends React.Component<AppProps, AppState> {
case BackOut.TAG_CATEGORIES_CHANGE: {
const resData: TagCategoriesChangeData = res.data;
this.props.setTagCategories(resData);
}
} break;
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/CurateBoxAddApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function CurateBoxAddApp(props: CurateBoxAddAppProps) {
disabled={disabled}
onKeyDown={props.onInputKeyDown} />
</CurateBoxRow>
{specialType ? undefined :
{ specialType ? undefined : (
<CurateBoxRow title={strings.browse.applicationPath + ':'}>
<InputField
text={props.curation && props.curation.meta.applicationPath || ''}
Expand All @@ -89,7 +89,7 @@ export function CurateBoxAddApp(props: CurateBoxAddAppProps) {
disabled={disabled}
onKeyDown={props.onInputKeyDown} />
</CurateBoxRow>
}
) }
<CurateBoxRow title={lcString + ':'}>
<InputField
text={props.curation && props.curation.meta.launchCommand || ''}
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/DropdownInputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ export class DropdownInputField extends React.Component<DropdownInputFieldProps,
if (key === 'ArrowUp' || key === 'ArrowDown') {
const element = document.activeElement;
if (element && checkIfAncestor(element, this.contentRef.current)) {
const next: any = (key === 'ArrowUp') ? element.previousSibling :
element.nextElementSibling;
const next: any = (key === 'ArrowUp')
? element.previousSibling
: element.nextElementSibling;
if (next && next.focus) {
next.focus();
event.preventDefault();
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/GameGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ export class GameGrid extends React.Component<GameGridProps> {
// (If any property is changed the grid is re-rendered, even these)
pass_orderBy={this.props.orderBy}
pass_orderReverse={this.props.orderReverse}
pass_currentGamesCount={this.currentGamesCount}
/>
pass_currentGamesCount={this.currentGamesCount} />
);
}}
</ArrowKeyStepper>
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/GameImageSplit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export class GameImageSplit extends React.Component<GameImageSplitProps, GameIma
onConfirm={this.onRemoveClick}
render={renderDeleteImageButton}
extra={[strings, text, !!disabled]} />
{ showPreview ?
{ showPreview ? (
<ImagePreview
src={this.props.imgSrc}
onCancel={this.onPreviewCancel} />
: undefined }
) : undefined }
</div>
) }
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/GameItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class GameItemContainer extends React.Component<GameItemContainerProps> {
onDoubleClick={this.onDoubleClick}
onContextMenu={this.onContextMenu}
onDragStart={this.onDragStart}
onDragEnd={this.onDragEnd} >
onDragEnd={this.onDragEnd}>
{this.props.children}
</div>
);
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/GameList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export class GameList extends React.Component<GameListProps> {
// (If any property is changed the list is re-rendered, even these)
pass_orderBy={this.props.orderBy}
pass_orderReverse={this.props.orderReverse}
pass_gamesChanged={gamesChanged}
/>
pass_gamesChanged={gamesChanged} />
)}
</ArrowKeyStepper>
);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/OpenIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function OpenIcon (props: IconProps) {

/** An icon from the "Open Iconic" collection. */
export type OpenIconType = (
'account-login'
| 'account-login'
| 'account-logout'
| 'action-redo'
| 'action-undo'
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/ProgressComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export function StatusBar(props: ProgressComponentProps) {
return (
<div className={(props.wrapperClass ? ' ' + props.wrapperClass : '') + 'progress-component__wrapper'}>
<div className='status-bar__top-text'>{props.progressData.text}</div>
{ props.progressData.secondaryText ?
{ props.progressData.secondaryText ? (
<div className='status-bar__bottom-text'>
{props.progressData.secondaryText}
</div>
: undefined }
) : undefined }
</div>
);
}
Expand All @@ -57,11 +57,11 @@ export function ProgressBar(props: ProgressComponentProps) {
<div className='progress-bar__bar'>
<div className='progress-bar__bar__inner' style={barCssProps} />
</div>
{ props.progressData.text ?
{ props.progressData.text ? (
<div className='progress-bar__bottom-text'>
{props.progressData.text}
</div>
: undefined }
) : undefined }
</div>
);
}
6 changes: 3 additions & 3 deletions src/renderer/components/ResizableSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export class ResizableSidebar extends React.Component<ResizableSidebarProps, Res

renderDivider() {
return (
<div className='game-browser__sidebar__divider'
onMouseDown={this.onDividerMouseDown}>
</div>
<div
className='game-browser__sidebar__divider'
onMouseDown={this.onDividerMouseDown} />
);
}

Expand Down
13 changes: 7 additions & 6 deletions src/renderer/components/SplashScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function SplashScreen(props: SplashScreenProps) {
const extraClass = (upgradesLoaded && creditsLoaded && miscLoaded)
? ' splash-screen--fade-out'
: '';

return (
<div className={'splash-screen' + extraClass}>
<div className='splash-screen__logo fp-logo-box'>
Expand All @@ -20,21 +21,21 @@ export function SplashScreen(props: SplashScreenProps) {
<div className='splash-screen__status-header'>
Loading
</div>
{!upgradesLoaded ?
{ !upgradesLoaded ? (
<div className='splash-screen__status'>
Upgrades
</div>
: undefined }
{!creditsLoaded ?
) : undefined }
{ !creditsLoaded ? (
<div className='splash-screen__status'>
Credits
</div>
: undefined }
{!miscLoaded ?
) : undefined }
{ !miscLoaded ? (
<div className='splash-screen__status'>
Misc
</div>
: undefined }
) : undefined }
</div>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/TagAliasInputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class TagAliasInputField extends React.Component<TagAliasInputFieldProps,
return (
<div
className={'input-dropdown' + (this.props.disabled ? ' input-dropdown--disabled' : '')}
ref={this.rootRef} >
ref={this.rootRef}>
{ editable ? inputField : undefined }
<div
className={'tag-input-dropdown__content'}
Expand Down Expand Up @@ -112,7 +112,7 @@ export class TagAliasInputField extends React.Component<TagAliasInputFieldProps,
<p className={'tag-primary__right'} >
Primary
</p>
): undefined }
) : undefined }
{ this.props.editable && tagAlias.id != this.props.primaryAliasId ? (
<div className='tag-alias__buttons'>
<div
Expand Down
Loading

0 comments on commit 6286602

Please sign in to comment.