Skip to content

Commit

Permalink
Replaced tslint with eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Mar 19, 2022
1 parent ee6bde0 commit 9eae416
Show file tree
Hide file tree
Showing 75 changed files with 668 additions and 237 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
webpack.config.js
29 changes: 29 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"root": true,
"rules": {
"@typescript-eslint/explicit-module-boundary-types": 0
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
{
"files": "*.ts",
"parser": "@typescript-eslint/parser"
},
{
"files": "*.vue",
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser"
}
}
],
"env": {
"browser": true,
"node": true
}
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
],
"main": "./bundle/main.js",
"scripts": {
"lint": "./node_modules/.bin/eslint \"src/**/*{ts,vue}\"",
"bundle": "./node_modules/.bin/webpack --config webpack.config.js",
"start": "./node_modules/.bin/electron . --remote-debugging-port=9223",
"lint": "./node_modules/.bin/tslint --project tsconfig.json --config tslint.json",
"lint:fix": "./node_modules/.bin/tslint --project tsconfig.json --config tslint.json --fix",
"test": "./node_modules/.bin/jest --config jest.json --silent .",
"package:dir": "./node_modules/.bin/electron-builder --dir --config electron-builder-config.yml --publish never",
"package": "./node_modules/.bin/electron-builder --config electron-builder-config.yml --publish never",
Expand All @@ -44,12 +43,15 @@
"@types/node-powershell": "^3.1.0",
"@types/sqlite3": "^3.1.8",
"@types/vue-color": "^2.4.2",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"axios": "^0.26.1",
"color": "^4.0.1",
"electron": "^17.1.2",
"electron-builder": "^22.14.13",
"electron-store": "^8.0.1",
"electron-updater": "4.3.9",
"eslint": "^8.11.0",
"fuse.js": "^6.4.6",
"jest": "^27.5.1",
"mathjs": "^9.5.0",
Expand All @@ -58,10 +60,10 @@
"simple-plist": "1.1.1",
"ts-jest": "^27.1.3",
"ts-loader": "^9.2.8",
"tslint": "^6.1.3",
"typescript": "^4.6.2",
"vue": "^2.6.12",
"vue-color": "^2.7.1",
"vue-eslint-parser": "^8.3.0",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",
"winston": "^3.3.3"
Expand Down
2 changes: 1 addition & 1 deletion src/common/config/commandline-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCurrentOperatingSystem } from "../helpers/operating-system-helpers";
import { platform } from "os";
import { WindowsShell, MacOsShell } from "../../main/plugins/commandline-plugin/shells";
import { MacOsShell, WindowsShell } from "../../main/plugins/commandline-plugin/shells";
import { OperatingSystem } from "../operating-system";

export interface CommandlineOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/common/config/user-config-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { SimpleFolderSearchOptions, defaultSimpleFolderSearchOptions } from "./s
import { UwpSearchOptions, defaultUwpSearchOptions } from "./uwp-search-options";
import { ColorConverterOptions, defaultColorConverterOptions } from "./color-converter-options";
import { ApplicationSearchOptions, defaultApplicationSearchOptions } from "./application-search-options";
import { defaultDictionaryOptions, DictionaryOptions } from "./dictionary-options";
import { DictionaryOptions, defaultDictionaryOptions } from "./dictionary-options";
import { BrowserBookmarksOptions, defaultBrowserBookmarksOptions } from "./browser-bookmarks-options";
import { ControlPanelOptions, defaultControlPanelOptions } from "./control-panel-options";
import { WeatherOptions, defaultWeatherOptions } from "./weather-options";
Expand Down
2 changes: 2 additions & 0 deletions src/common/global-hot-key/global-hot-key-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { GlobalHotKeyModifier } from "./global-hot-key-modifier";

export function isValidHotKey(hotKey: GlobalHotKey) {
return (
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Object.values(GlobalHotKeyModifier).includes(hotKey.modifier!) &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Object.values(GlobalHotKeyModifier).includes(hotKey.secondModifier!) &&
Object.values(GlobalHotKeyKey).includes(hotKey.key)
);
Expand Down
2 changes: 2 additions & 0 deletions src/common/helpers/config-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { UserConfigOptions } from "../config/user-config-options";
import { GlobalHotKeyModifier } from "../global-hot-key/global-hot-key-modifier";
import { deepCopy } from "./object-helpers";
Expand All @@ -7,6 +8,7 @@ export function mergeUserConfigWithDefault(userConfig: any, defaultUserConfig: U

Object.keys(defaultUserConfig).forEach((key: string) => {
const merged =
// eslint-disable-next-line no-prototype-builtins
userConfig !== undefined && userConfig.hasOwnProperty(key)
? Object.assign(result[key], userConfig[key])
: result[key];
Expand Down
2 changes: 1 addition & 1 deletion src/common/helpers/email-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export function isValidEmailAddress(emailAddress: string | undefined | null): bo
}

return new RegExp(
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
).test(emailAddress);
}
2 changes: 1 addition & 1 deletion src/common/helpers/file-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stats, readdir, lstat, unlink, exists, writeFile, existsSync, mkdirSync, readFile } from "fs";
import { Stats, exists, existsSync, lstat, mkdirSync, readFile, readdir, unlink, writeFile } from "fs";
import { join } from "path";

interface FileStat {
Expand Down
2 changes: 1 addition & 1 deletion src/common/helpers/file-path-validators.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isValidWindowsFilePath, isValidMacOsFilePath } from "./file-path-validators";
import { isValidMacOsFilePath, isValidWindowsFilePath } from "./file-path-validators";

const validWindowsFilePaths = [
"C:\\Program Files (x86)\\Some Folder\\some-file.ext",
Expand Down
2 changes: 1 addition & 1 deletion src/common/helpers/object-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export function deepCopy<T>(value: T): T {
return JSON.parse(JSON.stringify(value));
}

export function isEqual(a: any, b: any): boolean {
export function isEqual<T>(a: T, b: T): boolean {
return JSON.stringify(a) === JSON.stringify(b);
}
2 changes: 1 addition & 1 deletion src/common/icon/icon-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isValidIconType, isValidIcon } from "./icon-helpers";
import { isValidIcon, isValidIconType } from "./icon-helpers";
import { IconType } from "./icon-type";
import { Icon } from "./icon";

Expand Down
2 changes: 1 addition & 1 deletion src/common/logger/production-logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from "./logger";
import Winston from "winston";
import { dirname, basename } from "path";
import { basename, dirname } from "path";
import { logFormat } from "../helpers/logger-helpers";

export class ProductionLogger implements Logger {
Expand Down
1 change: 1 addition & 0 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Typescript type declarations

declare module "simple-plist" {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function readFile(filePath: string, callback: (err: string, data: any) => void): void;
}
1 change: 0 additions & 1 deletion src/main/executors/application-searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { OperatingSystemVersion } from "../../common/operating-system";
export function searchWindowsApplications(
applicationSearchOptions: ApplicationSearchOptions,
logger: Logger,
operatingSystemVersion: OperatingSystemVersion,
): Promise<string[]> {
return new Promise((resolve, reject) => {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/main/executors/commandline-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const windowsCommandLineExecutor = (command: string, shell: WindowsShell)
case WindowsShell.PowerShellInWT:
return executeCommand(`start wt.exe powershell -NoExit -Command "&${command}"`);
case WindowsShell.WSLInWT:
return executeCommand(`start wt.exe wsl sh -c "${command} && exec \$SHELL"`);
return executeCommand(`start wt.exe wsl sh -c "${command} && exec $SHELL"`);
default:
return unsupportedShellRejection(shell);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/executors/file-searchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function macosFileSearcher(option: FileSearchOption): Promise<string[]> {
return new Promise((resolve, reject) => {
const recurse = option.recursive ? "" : "-maxdepth 1 ";
executeCommandWithOutput(
`find "${option.folderPath}" ${recurse}-not -path '*/\.*' | grep -v "^${option.folderPath}$" | head -n 1000`,
`find "${option.folderPath}" ${recurse}-not -path '*/.*' | grep -v "^${option.folderPath}$" | head -n 1000`,
)
.then((data) => {
const result = data
Expand Down
1 change: 1 addition & 0 deletions src/main/executors/websearch-suggestion-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getWebearchSuggestions(url: string): Promise<any> {
return new Promise((resolve, reject) => {
axios
Expand Down
2 changes: 1 addition & 1 deletion src/main/favorites/favorites-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class FavoriteManager {
}

public increaseCount(searchResultItem: SearchResultItem): Promise<void> {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
const favorite = this.favoriteRepository.get(searchResultItem);
if (favorite) {
favorite.executionCount++;
Expand Down
13 changes: 7 additions & 6 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {
app,
BrowserWindow,
dialog,
globalShortcut,
ipcMain,
Menu,
MenuItemConstructorOptions,
screen,
Tray,
WebContents,
app,
dialog,
globalShortcut,
ipcMain,
screen,
} from "electron";
import { autoUpdater } from "electron-updater";
import { platform, release } from "os";
import { join } from "path";
import { AppearanceOptions } from "../common/config/appearance-options";
import { ElectronStoreConfigRepository } from "../common/config/electron-store-config-repository";
import { defaultGeneralOptions } from "../common/config/general-options";
import { defaultUserConfigOptions, UserConfigOptions } from "../common/config/user-config-options";
import { UserConfigOptions, defaultUserConfigOptions } from "../common/config/user-config-options";
import { getErrorSearchResultItem } from "../common/error-search-result-item";
import { GlobalHotKey } from "../common/global-hot-key/global-hot-key";
import { isValidHotKey } from "../common/global-hot-key/global-hot-key-helpers";
Expand Down Expand Up @@ -838,6 +838,7 @@ function registerAllIpcListeners() {
event.sender.send(IpcChannels.userInputUpdated, newUserInput, true);
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
ipcMain.on(IpcChannels.ueliCommandExecuted, (command: any) => {
command = command as UeliCommand;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join, basename, extname } from "path";
import { basename, extname, join } from "path";
import { createHash } from "crypto";
import { ueliTempFolder } from "../../../common/helpers/ueli-helpers";
import { replaceWhitespace } from "../../../common/helpers/string-helpers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function generateWindowsAppIcons(applicationFilePaths: string[]): Promise
});
}

function generateIcons(icons: Icon[], followShortcuts?: boolean): Promise<void> {
function generateIcons(icons: Icon[]): Promise<void> {
return new Promise((resolve, reject) => {
const ps = new Shell({
executionPolicy: "Bypass",
Expand Down Expand Up @@ -65,7 +65,7 @@ function generateIcons(icons: Icon[], followShortcuts?: boolean): Promise<void>

ps.addCommand(powershellCommand)
.then(() => ps.invoke())
.then((r) => resolve())
.then(() => resolve())
.catch((err) => reject(err))
.finally(() => ps.dispose());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class BrowserBookmarksPlugin implements SearchPlugin {
return this.config.isEnabled;
}

public execute(searchResultItem: SearchResultItem, privileged: boolean): Promise<void> {
public execute(searchResultItem: SearchResultItem): Promise<void> {
return this.urlExecutor(searchResultItem.executionArgument);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class FirefoxBookmarkRepository implements BrowserBookmarkRepository {
);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private getAbsoluteProfilePath(profilesIni: { [key: string]: any }): string | undefined {
const profiles: { Default: string; Path: string; IsRelative: string }[] = Object.keys(profilesIni)
.filter((iniSection) => iniSection.startsWith("Profile"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { BrowserBookmarkRepository } from "./browser-bookmark-repository";
import { BrowserBookmark } from "./browser-bookmark";
import { FileHelpers } from "../../../common/helpers/file-helpers";
Expand Down
8 changes: 4 additions & 4 deletions src/main/plugins/calculator-plugin/calculator-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class CalculatorPlugin implements ExecutionPlugin {
this.clipboardCopier = clipboardCopier;
}

public isValidUserInput(userInput: string, fallback?: boolean | undefined): boolean {
public isValidUserInput(userInput: string): boolean {
return Calculator.isValidInput(userInput, this.generalConfig.decimalSeparator, this.getArgumentSeparator());
}

Expand All @@ -37,8 +37,8 @@ export class CalculatorPlugin implements ExecutionPlugin {
return ";";
}

public getSearchResults(userInput: string, fallback?: boolean | undefined): Promise<SearchResultItem[]> {
return new Promise((resolve, reject) => {
public getSearchResults(userInput: string): Promise<SearchResultItem[]> {
return new Promise((resolve) => {
const result = Calculator.calculate(
userInput,
Number(this.config.precision),
Expand All @@ -63,7 +63,7 @@ export class CalculatorPlugin implements ExecutionPlugin {
return this.config.isEnabled;
}

public execute(searchResultItem: SearchResultItem, privileged: boolean): Promise<void> {
public execute(searchResultItem: SearchResultItem): Promise<void> {
return this.clipboardCopier(searchResultItem.executionArgument);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/plugins/calculator-plugin/calculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe(Calculator.name, () => {
describe(Calculator.calculate.name, () => {
it("should return the correct result", () => {
const precision = 16;
const inputOutputCombinations: InputOutputCombination[] = [
const inputOutputCombinations: InputOutputCombination<string, string>[] = [
{
input: "1.1 - 1",
output: "0.1",
Expand All @@ -29,7 +29,7 @@ describe(Calculator.name, () => {

it("should use specified precision", () => {
const calculation = "1/3";
const inputOutputCombinations: InputOutputCombination[] = [
const inputOutputCombinations: InputOutputCombination<number, string>[] = [
{ input: 1, output: "0.3" },
{ input: 16, output: "0.3333333333333333" },
];
Expand Down
18 changes: 5 additions & 13 deletions src/main/plugins/calculator-plugin/calculator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { create, all, evaluate, typeOf } from "mathjs";
import { all, create, evaluate, typeOf } from "mathjs";

export class Calculator {
public static isValidInput(
input: string,
decimalSeparator: string = ".",
argumentSeparator: string = ",",
): boolean {
public static isValidInput(input: string, decimalSeparator = ".", argumentSeparator = ","): boolean {
const blackListInputs = ["version", "i"];

if (input.length === 0) {
Expand Down Expand Up @@ -37,12 +33,7 @@ export class Calculator {
);
}

public static calculate(
input: string,
precision: number,
decimalSeparator: string = ".",
argumentSeparator: string = ",",
): string {
public static calculate(input: string, precision: number, decimalSeparator = ".", argumentSeparator = ","): string {
precision = Number(precision);

if (precision > 64 || precision < 0) {
Expand All @@ -55,13 +46,14 @@ export class Calculator {
throw new Error("Failed to instantiate math js static");
}

const result: string = String(math.evaluate(this.normalizeInput(input, decimalSeparator, argumentSeparator)));
const result = String(math.evaluate(this.normalizeInput(input, decimalSeparator, argumentSeparator)));

return result.replace(new RegExp(",|\\.", "g"), (match) =>
match === "." ? decimalSeparator : argumentSeparator,
);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static isValidMathType(input: any): boolean {
const mathType = typeOf(input);

Expand Down
Loading

0 comments on commit 9eae416

Please sign in to comment.