Skip to content

Commit

Permalink
Linting fixes, npm scripts (#698)
Browse files Browse the repository at this point in the history
* .gitignore: Ignore `/.idea`, added by IntelliJ IDEA

* package.json: add `check:lint` task

* lint: auto-fix multiple issues

* lint: manually fix multiple issues. Ignore some lint warnings.

* package.json: specify `engines`, NodeJS v14.

* package.json: enhance `check:lint` npm script, to check files via each tsconfig file. Fix resulting identified issues.

* package.json: add npm script `check:tsc`, checking for compilation errors.

* package.json: add npm script to execute all checks
  • Loading branch information
laurence-myers authored Sep 14, 2021
1 parent 26fb13b commit 6f36eb6
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/out-tsc
/app-builds
/remote
/.idea

*.js
*.js.map
Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as path from 'path';

const fs = require('fs');
const electron = require('electron');
const { nativeTheme } = require('electron')
const { nativeTheme } = require('electron');
import { app, protocol, BrowserWindow, screen, dialog, systemPreferences, ipcMain } from 'electron';
const windowStateKeeper = require('electron-window-state');

Expand Down
6 changes: 5 additions & 1 deletion node/main-extract-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ function thumbQueueRunner(element: ImageElement, done): void {
done();
})
.catch(() => {
sendCurrentProgress(thumbsDone, thumbsDone + thumbQueue.length() + 1, 'importingScreenshots'); // TODO check whether sending data off by 1
sendCurrentProgress( // TODO check whether sending data off by 1
thumbsDone,
thumbsDone + thumbQueue.length() + 1,
'importingScreenshots'
);
thumbsDone++;

extractAll(
Expand Down
10 changes: 5 additions & 5 deletions node/main-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
function notifyFileDeleted(event, fileToDelete, item) {
fs.access(fileToDelete, fs.constants.F_OK, (err: any) => {
if (err) {
console.log('FILE DELETED SUCCESS !!!')
console.log('FILE DELETED SUCCESS !!!');
event.sender.send('file-deleted', item);
}
});
Expand Down Expand Up @@ -269,10 +269,10 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
/**
* Stop watching a particular folder
*/
ipc.on('start-watching-folder', (event, watchedFolderIndex: string, path: string, persistent: boolean) => {
ipc.on('start-watching-folder', (event, watchedFolderIndex: string, path2: string, persistent: boolean) => {
// annoyingly it's not a number : ^^^^^^^^^^^^^^^^^^ -- because object keys are strings :(
console.log('start watching:', watchedFolderIndex, path, persistent);
startWatcher(parseInt(watchedFolderIndex, 10), path, persistent);
console.log('start watching:', watchedFolderIndex, path2, persistent);
startWatcher(parseInt(watchedFolderIndex, 10), path2, persistent);
});

/**
Expand All @@ -293,7 +293,7 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
const allHashes: Map<string, 1> = new Map();

finalArray
.filter((element: ImageElement) => { return !element.deleted })
.filter((element: ImageElement) => { return !element.deleted; })
.forEach((element: ImageElement) => {
allHashes.set(element.hash, 1);
});
Expand Down
15 changes: 8 additions & 7 deletions node/main-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ function getFileDuration(metadata): number {
function getFps(metadata): number {
if (metadata?.streams?.[0]?.r_frame_rate) {
const fps = metadata.streams[0].r_frame_rate;
const evalFps = eval(fps.toString()); // `eval` because FPS is a fraction like `24000/1001`
const fpsParts = fps.split('/');
const evalFps = Number(fpsParts[0]) / Number(fpsParts[1]); // FPS is a fraction like `24000/1001`
return Math.round(evalFps);
} else {
return 0;
Expand Down Expand Up @@ -384,21 +385,21 @@ function hashFileAsync(pathToFile: string, stats: Stats): Promise<string> {
let data: Buffer;

if (fileSize < sampleThreshold) {
data = fs.readFile(pathToFile, (err, data) => {
fs.readFile(pathToFile, (err, data2) => {
if (err) { throw err; }
// append the file size to the data
const buf = Buffer.concat([data, Buffer.from(fileSize.toString())]);
const buf = Buffer.concat([data2, Buffer.from(fileSize.toString())]);
// make the magic happen!
const hash = hasher('md5').update(buf.toString('hex')).digest('hex');
resolve(hash);
}); // too small, just read the whole file
} else {
data = Buffer.alloc(sampleSize * 3);
fs.open(pathToFile, 'r', (err, fd) => {
fs.read(fd, data, 0, sampleSize, 0, (err, bytesRead, buffer) => { // read beginning of file
fs.read(fd, data, sampleSize, sampleSize, fileSize / 2, (err, bytesRead, buffer) => {
fs.read(fd, data, sampleSize * 2, sampleSize, fileSize - sampleSize, (err, bytesRead, buffer) => {
fs.close(fd, (err) => {
fs.read(fd, data, 0, sampleSize, 0, (err2, bytesRead, buffer) => { // read beginning of file
fs.read(fd, data, sampleSize, sampleSize, fileSize / 2, (err3, bytesRead2, buffer2) => {
fs.read(fd, data, sampleSize * 2, sampleSize, fileSize - sampleSize, (err4, bytesRead3, buffer3) => {
fs.close(fd, (err5) => {
// append the file size to the data
const buf = Buffer.concat([data, Buffer.from(fileSize.toString())]);
// make the magic happen!
Expand Down
14 changes: 7 additions & 7 deletions node/server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { GLOBALS } from "./main-globals";
import { GLOBALS } from './main-globals';

import * as path from 'path';

const express = require('express');
// const bodyParser = require('body-parser'); ----------------------------- disabled
const WebSocket = require('ws');

import { ImageElement } from "../interfaces/final-object.interface";
import { ImageElement } from '../interfaces/final-object.interface';

const args = process.argv.slice(1);
const serve: boolean = args.some(val => val === '--serve');

import { RemoteSettings } from "../interfaces/settings-object.interface";
import { RemoteSettings } from '../interfaces/settings-object.interface';

// =================================================================================================

Expand Down Expand Up @@ -149,24 +149,24 @@ const socketMessageHandler = (message: string): void => {
} catch {
console.log('ERROR: message was not JSON encoded');
}
}
};

/**
* Shut down the Express and WebSocket servers
*/
function stopTheServers(): void {
if (serverRef && typeof serverRef.close === "function") {
if (serverRef && typeof serverRef.close === 'function') {
serverRef.close();
console.log('closed Express server');
}
if (wss && typeof wss.close === "function") {
if (wss && typeof wss.close === 'function') {
wss.close();
console.log('closed Socket server');
}
}

const { networkInterfaces, hostname } = require('os');
const ip = require("ip");
const ip = require('ip');

/**
* Log the user's IP
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
],
"main": "main.js",
"license": "MIT",
"engines": {
"node": ">=v14"
},
"scripts": {
"start": "npm-run-all -p electron:serve ng:serve",
"build": "npm run electron:serve-tsc && ng build --base-href ./",
"build:prod": "npm run build -- -c production",
"buildsize": "sh ./bin/buildSizeCheck.sh",
"check": "npm run check:tsc && npm run check:lint",
"check:lint": "tslint --project ./tsconfig.json && tslint --project ./tsconfig-serve.json && tslint --project ./tsconfig.worker.json",
"check:tsc": "tsc --project ./tsconfig.json --noEmit && tsc --project ./tsconfig-serve.json --noEmit && tsc --project ./tsconfig.worker.json --noEmit",
"hasRemote": "sh ./bin/hasRemoteCheck.sh",
"electron": "npm run hasRemote && npm run build:prod && electron-builder build && npm run buildsize",
"electron:serve": "wait-on tcp:4200 && npm run electron:serve-tsc && npx electron . --serve",
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/languages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SupportedLanguage } from "./app-state";
import { SupportedLanguage } from './app-state';

// Languages
const Arabic = require('../../../i18n/ar.json');
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/settings-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,4 +855,4 @@ export const SettingsButtons: SettingsButtonsType = {
title: 'BUTTONS.videoNotesHint',
toggled: false
}
}
};
2 changes: 1 addition & 1 deletion src/app/components/button/button-style.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ButtonStylePipe implements PipeTransform {

defaultSettingsButtonDark: !flatIcons && darkMode,
defaultSettingsButtonDarkToggled: !flatIcons && darkMode && toggled
}
};

}

Expand Down
4 changes: 2 additions & 2 deletions src/app/components/button/button.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, EventEmitter, Input, Output } from "@angular/core";
import { Component, EventEmitter, Input, Output } from '@angular/core';

import { SettingsButtonKey, SettingsButtonsType } from "../../common/settings-buttons";
import { SettingsButtonKey, SettingsButtonsType } from '../../common/settings-buttons';

@Component({
selector: 'app-button',
Expand Down
17 changes: 10 additions & 7 deletions src/app/components/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
@ViewChild('magicSearch', { static: false }) magicSearch: ElementRef;
@ViewChild('searchRef', { static: false }) searchRef: ElementRef;

@ViewChild(SortOrderComponent) sortOrderRef:SortOrderComponent;
@ViewChild(SortOrderComponent) sortOrderRef: SortOrderComponent;

@ViewChild(VirtualScrollerComponent, { static: false }) virtualScroller: VirtualScrollerComponent;

Expand Down Expand Up @@ -445,7 +445,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
this.electronService.ipcRenderer.on('file-not-found', (event) => {
this.zone.run(() => {
this.modalService.openSnackbar(this.translate.instant('SETTINGS.fileNotFound'));
})
});
});

// when `remote-control` requests to open video
Expand All @@ -459,7 +459,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
wifi: ip,
host: hostname,
port: port
}
};

console.log(serverDetails);
this.serverDetailsBehaviorSubject.next(serverDetails);
Expand Down Expand Up @@ -597,7 +597,8 @@ export class HomeComponent implements OnInit, AfterViewInit {
let somethingDeleted: boolean = false;

this.imageElementService.imageElements
.filter((element: ImageElement) => { return element.inputSource == sourceIndex })
// tslint:disable-next-line:triple-equals
.filter((element: ImageElement) => { return element.inputSource == sourceIndex; })
// notice the loosey-goosey comparison! this is because number ^^ string comparison happening here!
.forEach((element: ImageElement) => {
// console.log(element.fileName);
Expand All @@ -618,7 +619,8 @@ export class HomeComponent implements OnInit, AfterViewInit {
// mark the element in `imageElements[]` as `deleted`
this.electronService.ipcRenderer.on('single-file-deleted', (event, sourceIndex: number, partialPath: string) => {
this.imageElementService.imageElements
.filter((element: ImageElement) => { return element.inputSource == sourceIndex })
// tslint:disable-next-line:triple-equals
.filter((element: ImageElement) => { return element.inputSource == sourceIndex; })
// notice the loosey-goosey comparison! this is because number ^^ string comparison happening here!
.forEach((element: ImageElement) => {
if (
Expand Down Expand Up @@ -806,7 +808,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
// important for when user renames a folder for example
this.imageElementService.imageElements
.filter((currentElements: ImageElement) => {
return currentElements.deleted
return currentElements.deleted;
})
.forEach((deletedElement: ImageElement) => {
if (deletedElement.hash === element.hash) {
Expand Down Expand Up @@ -890,7 +892,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
this.resetFinalArrayRef();
} else {
this.newVideoImportTimeout = setTimeout(() => {
this.resetFinalArrayRef()
this.resetFinalArrayRef();
}, 3000);
}
}
Expand All @@ -910,6 +912,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
*/
deleteInputSourceFiles(sourceIndex: number): void {
this.imageElementService.imageElements.forEach((element: ImageElement) => {
// tslint:disable-next-line:triple-equals
if (element.inputSource == sourceIndex) { // TODO -- stop the loosey goosey `==` and figure out `string` vs `number`
element.deleted = true;
this.imageElementService.finalArrayNeedsSaving = true;
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/meta/meta.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MetaComponent implements OnInit, OnDestroy {
@Input() showVideoNotes: boolean;
@Input() star: StarRating;

@Input() renameResponse: Observable<RenameFileResponse>
@Input() renameResponse: Observable<RenameFileResponse>;

starRatingHack: StarRating;
yearHack: number;
Expand Down Expand Up @@ -214,7 +214,7 @@ export class MetaComponent implements OnInit, OnDestroy {
event.target.blur();
this.renamingWIP = this.video.cleanName;
event.stopPropagation();
this.renameError = false
this.renameError = false;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/app/components/modal/welcome.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component } from '@angular/core';

@Component({
// tslint:disable-next-line:component-selector
selector: 'welcome-component',
templateUrl: './welcome.component.html',
styleUrls: ['./welcome.component.scss'],
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/rename-file/rename-file.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class RenameFileComponent implements OnInit, OnDestroy {
@Input() macVersion: boolean;
@Input() selectedSourceFolder: string;

@Input() renameResponse: Observable<RenameFileResponse>
@Input() renameResponse: Observable<RenameFileResponse>;

renamingWIP: string;
renamingExtension: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/shortcuts/shortcuts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ShortcutsComponent {

// 'quit', // w - hardcoded in template
// 'quit', // q - hardcoded in template
]
];

constructor(
public shortcutService: ShortcutsService
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/shortcuts/shortcuts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class ShortcutsService {
['toggleSettings', 'o'],
// quit -> q
// quit -> w
])
]);

constructor() { }

Expand All @@ -99,7 +99,7 @@ export class ShortcutsService {
this.actionToKeyMap.clear();
this.keyToActionMap.clear();

for (let [key, value] of Object.entries(keyToAction)) {
for (const [key, value] of Object.entries(keyToAction)) {
this.actionToKeyMap.set(value, <any>key);
this.keyToActionMap.set(<any>key, value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/statistics/statistics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class StatisticsComponent implements OnInit, OnDestroy {
if (data) { // first emit from subscription is `undefined`
this.handleOldFolderReconnected(data.source, data.path);
}
}))
}));

this.eventSubscriptionMap.set('numberOfScreenshotsDeleted', this.numberScreenshotsDeleted.subscribe((deleted: number) => {
if (deleted !== undefined) { // first emit from subscription is `undefined`
Expand Down Expand Up @@ -155,10 +155,10 @@ export class StatisticsComponent implements OnInit, OnDestroy {

this.numberOfScreensDeleted = numDeleted;
this.showNumberDeleted = true;
this.cd.detectChanges()
this.cd.detectChanges();
setTimeout(() => {
this.showNumberDeleted = false;
this.cd.detectChanges()
this.cd.detectChanges();
}, 3000);

}, 1000); // make sure it doesn't appear instantly -- feels like an error if it happens to quickly :P
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/tags-auto/tags.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function received(message: any): void {
postMessage(getCleanTwoWordMap(message.data.potentialTwoWordMap, message.data.onlyFileNames));

}
};
}

/**
* Create the `twoWordFreqMap` by using the `potentialTwoWordMap` word map
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/views/file-path.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class FilePathService {
' ': '%20',
'(': '%28',
')': '%29',
}
};

constructor(
public sourceFolderService: SourceFolderService,
Expand All @@ -36,7 +36,7 @@ export class FilePathService {
subfolder,
hash + (video ? '.mp4' : '.jpg')
)).replace(/\\/g, '/')
.replace(/[ \(\)]/g, (match) => { return this.replaceMap[match] })
.replace(/[ \(\)]/g, (match) => { return this.replaceMap[match]; });
// ^^^^^ replace the ` ` (space) as well as parentheses `(` and `)` with URL encoding from the `replaceMap`
}

Expand All @@ -46,15 +46,15 @@ export class FilePathService {
*/
getFileNameWithoutExtension(fileName: string): string {
return fileName.slice().substr(0, fileName.lastIndexOf('.'));
};
}

/**
* return extension without file name
* e.g. `video.mp4` => `.mp4`
*/
getFileNameExtension(fileName: string): string {
return fileName.slice().split('.').pop();
};
}

/**
* Return full filesystem path to video file
Expand Down
Loading

0 comments on commit 6f36eb6

Please sign in to comment.