Swap to eslint (#154)

* 311 problems (173 errors, 138 warnings)

* Make a start...

* swap to react config

* Literally a handful left

* Clean.

* any removal

* Use Record

* Adjust versions

* Update with latest eslint-standard ruleset

* Update defaults.ts
This commit is contained in:
Jaco Greeff
2019-07-12 22:01:19 +02:00
committed by GitHub
parent 7b6a18cbfb
commit fd67ecdf3a
46 changed files with 412 additions and 395 deletions
+8 -8
View File
@@ -2,27 +2,27 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringStore } from '../types';
import { KeyringStore, KeyringJson } from '../types';
import store from 'store';
export default class BrowserStore implements KeyringStore {
all (cb: (key: string, value: any) => void): void {
store.each((value: any, key: string) =>
cb(key, value)
);
public all (cb: (key: string, value: KeyringJson) => void): void {
store.each((value: KeyringJson, key: string): void => {
cb(key, value);
});
}
get (key: string, cb: (value: any) => void): void {
public get (key: string, cb: (value: KeyringJson) => void): void {
cb(store.get(key));
}
remove (key: string, cb?: () => void): void {
public remove (key: string, cb?: () => void): void {
store.remove(key);
cb && cb();
}
set (key: string, value: any, cb?: () => void): void {
public set (key: string, value: KeyringJson, cb?: () => void): void {
store.set(key, value);
cb && cb();
}
+16 -12
View File
@@ -2,10 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringStore } from '../types';
import { KeyringStore, KeyringJson } from '../types';
import extension from 'extensionizer';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type StoreValue = Record<string, any>;
const lastError = (type: string): void => {
const error = extension.runtime.lastError;
@@ -15,33 +18,34 @@ const lastError = (type: string): void => {
};
export default class ExtensionStore implements KeyringStore {
all (cb: (key: string, value: any) => void): void {
extension.storage.local.get(null, (result: { [index: string]: any }) => {
public all (cb: (key: string, value: KeyringJson) => void): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
extension.storage.local.get(null, (result: StoreValue): void => {
lastError('all');
Object.entries(result).forEach(([key, value]) =>
cb(key, value)
);
Object.entries(result).forEach(([key, value]): void => {
cb(key, value);
});
});
}
get (key: string, cb: (value: any) => void): void {
extension.storage.local.get([key], (result: { [index: string]: any }) => {
public get (key: string, cb: (value: KeyringJson) => void): void {
extension.storage.local.get([key], (result: StoreValue): void => {
lastError('get');
cb(result[key]);
});
}
remove (key: string, cb?: () => void): void {
extension.storage.local.remove(key, () => {
public remove (key: string, cb?: () => void): void {
extension.storage.local.remove(key, (): void => {
lastError('remove');
cb && cb();
});
}
set (key: string, value: any, cb?: () => void): void {
public set (key: string, value: KeyringJson, cb?: () => void): void {
// shortcut, don't save testing accounts in extension storage
if (key.indexOf('account:') === 0 && value.meta && value.meta.isTesting) {
cb && cb();
@@ -49,7 +53,7 @@ export default class ExtensionStore implements KeyringStore {
return;
}
extension.storage.local.set({ [key]: value }, () => {
extension.storage.local.set({ [key]: value }, (): void => {
lastError('set');
cb && cb();
+11 -9
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringStore } from '../types';
import { KeyringStore, KeyringJson } from '../types';
import fs from 'fs';
import mkdirp from 'mkdirp';
@@ -12,7 +12,7 @@ import path from 'path';
export default class FileStore implements KeyringStore {
private _path: string;
constructor (path: string) {
public constructor (path: string) {
if (!fs.existsSync(path)) {
mkdirp.sync(path);
}
@@ -20,23 +20,25 @@ export default class FileStore implements KeyringStore {
this._path = path;
}
all (cb: (key: string, value: any) => void): void {
public all (cb: (key: string, value: KeyringJson) => void): void {
fs
.readdirSync(this._path)
.filter((key) => !['.', '..'].includes(key))
.forEach((key) => cb(key, this._readKey(key)));
.filter((key): boolean => !['.', '..'].includes(key))
.forEach((key): void => {
cb(key, this._readKey(key));
});
}
get (key: string, cb: (value: any) => void): void {
public get (key: string, cb: (value: KeyringJson) => void): void {
cb(this._readKey(key));
}
remove (key: string, cb?: () => void): void {
public remove (key: string, cb?: () => void): void {
fs.unlinkSync(this._getPath(key));
cb && cb();
}
set (key: string, value: any, cb?: () => void): void {
public set (key: string, value: KeyringJson, cb?: () => void): void {
fs.writeFileSync(this._getPath(key), Buffer.from(JSON.stringify(value), 'utf-8'));
cb && cb();
}
@@ -45,7 +47,7 @@ export default class FileStore implements KeyringStore {
return path.join(this._path, key);
}
private _readKey (key: string): any {
private _readKey (key: string): KeyringJson {
return JSON.parse(
fs.readFileSync(this._getPath(key)).toString('utf-8')
);