fix eslint

This commit is contained in:
antelle 2021-05-15 16:54:04 +02:00
parent 093f6e7e25
commit 84ac7568ee
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
14 changed files with 63 additions and 97 deletions

View File

@ -161,8 +161,10 @@
"no-else-return": "off",
"jest/valid-expect": "off",
"jest/expect-expect": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-var-requires": "off"
},
@ -178,14 +180,6 @@
"jsconfig.json"
]
}
},
{
"files": [
"app/test/**/*.ts"
],
"env": {
"mocha": true
}
}
],
"settings": {

View File

@ -147,8 +147,7 @@ module.exports = function (grunt) {
'desktop-darwin-installer-helper-x64': {
cwd: 'tmp/desktop/KeeWeb Installer.app',
src: '**',
dest:
'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Installer/KeeWeb Installer.app',
dest: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Installer/KeeWeb Installer.app',
expand: true,
nonull: true,
options: { mode: true }
@ -156,8 +155,7 @@ module.exports = function (grunt) {
'desktop-darwin-installer-helper-arm64': {
cwd: 'tmp/desktop/KeeWeb Installer.app',
src: '**',
dest:
'tmp/desktop/KeeWeb-darwin-arm64/KeeWeb.app/Contents/Installer/KeeWeb Installer.app',
dest: 'tmp/desktop/KeeWeb-darwin-arm64/KeeWeb.app/Contents/Installer/KeeWeb Installer.app',
expand: true,
nonull: true,
options: { mode: true }
@ -228,43 +226,35 @@ module.exports = function (grunt) {
nonull: true
},
'native-messaging-host-darwin-x64': {
src:
'node_modules/@keeweb/keeweb-native-messaging-host/darwin-x64/keeweb-native-messaging-host',
dest:
'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/MacOS/util/keeweb-native-messaging-host',
src: 'node_modules/@keeweb/keeweb-native-messaging-host/darwin-x64/keeweb-native-messaging-host',
dest: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/MacOS/util/keeweb-native-messaging-host',
nonull: true,
options: { mode: '0755' }
},
'native-messaging-host-darwin-arm64': {
src:
'node_modules/@keeweb/keeweb-native-messaging-host/darwin-arm64/keeweb-native-messaging-host',
dest:
'tmp/desktop/KeeWeb-darwin-arm64/KeeWeb.app/Contents/MacOS/util/keeweb-native-messaging-host',
src: 'node_modules/@keeweb/keeweb-native-messaging-host/darwin-arm64/keeweb-native-messaging-host',
dest: 'tmp/desktop/KeeWeb-darwin-arm64/KeeWeb.app/Contents/MacOS/util/keeweb-native-messaging-host',
nonull: true,
options: { mode: '0755' }
},
'native-messaging-host-linux-x64': {
src:
'node_modules/@keeweb/keeweb-native-messaging-host/linux-x64/keeweb-native-messaging-host',
src: 'node_modules/@keeweb/keeweb-native-messaging-host/linux-x64/keeweb-native-messaging-host',
dest: 'tmp/desktop/keeweb-linux-x64/keeweb-native-messaging-host',
nonull: true,
options: { mode: '0755' }
},
'native-messaging-host-win32-x64': {
src:
'node_modules/@keeweb/keeweb-native-messaging-host/win32-x64/keeweb-native-messaging-host.exe',
src: 'node_modules/@keeweb/keeweb-native-messaging-host/win32-x64/keeweb-native-messaging-host.exe',
dest: 'tmp/desktop/KeeWeb-win32-x64/keeweb-native-messaging-host.exe',
nonull: true
},
'native-messaging-host-win32-ia32': {
src:
'node_modules/@keeweb/keeweb-native-messaging-host/win32-ia32/keeweb-native-messaging-host.exe',
src: 'node_modules/@keeweb/keeweb-native-messaging-host/win32-ia32/keeweb-native-messaging-host.exe',
dest: 'tmp/desktop/KeeWeb-win32-ia32/keeweb-native-messaging-host.exe',
nonull: true
},
'native-messaging-host-win32-arm64': {
src:
'node_modules/@keeweb/keeweb-native-messaging-host/win32-arm64/keeweb-native-messaging-host.exe',
src: 'node_modules/@keeweb/keeweb-native-messaging-host/win32-arm64/keeweb-native-messaging-host.exe',
dest: 'tmp/desktop/KeeWeb-win32-arm64/keeweb-native-messaging-host.exe',
nonull: true
}

View File

@ -171,7 +171,8 @@ const AutoType = {
} else {
if (!windowInfo.url) {
// try to find a URL in the title
const urlMatcher = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\\+.~#?&\/=]*)/;
const urlMatcher =
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\\+.~#?&\/=]*)/;
const urlMatches = urlMatcher.exec(windowInfo.title);
windowInfo.url = urlMatches && urlMatches.length > 0 ? urlMatches[0] : null;
}

View File

@ -74,8 +74,7 @@ class StorageDropbox extends StorageBase {
_getOAuthConfig() {
return {
scope:
'files.content.read files.content.write files.metadata.read files.metadata.write',
scope: 'files.content.read files.content.write files.metadata.read files.metadata.write',
url: 'https://www.dropbox.com/oauth2/authorize',
tokenUrl: 'https://api.dropboxapi.com/oauth2/token',
clientId: this._getKey(),

View File

@ -148,7 +148,7 @@ class Otp {
}
static parseUrl(url: string): Otp {
const match = /^otpauth:\/\/(\w+)\/([^\?]+)\?(.*)/i.exec(url);
const match = /^otpauth:\/\/(\w+)\/([^?]+)\?(.*)/i.exec(url);
if (!match) {
throw new Error('Not OTP url');
}
@ -170,9 +170,9 @@ class Otp {
const secret = otherParams.get('secret');
const algorithm = otherParams.get('algorithm')?.toUpperCase() || 'SHA1';
const digits = Number.parseInt(otherParams.get('digits') || '') || 6;
const counter = Number.parseInt(otherParams.get('counter') || '') || undefined;
const period = Number.parseInt(otherParams.get('period') || '') || 30;
const digits = Number.parseInt(otherParams.get('digits') || '', 10) || 6;
const counter = Number.parseInt(otherParams.get('counter') || '', 10) || undefined;
const period = Number.parseInt(otherParams.get('period') || '', 10) || 30;
if (type !== 'hotp' && type !== 'totp') {
throw new Error(`Bad type: ${type}`);

View File

@ -24,10 +24,7 @@ for (let i = 65 /* 'A' */; i <= 90 /* 'Z' */; i++) {
}
const symbolsPerCharClass = new Uint8Array([
95 /* ASCII symbols */,
10 /* digits */,
26 /* lowercase letters */,
26 /* uppercase letters */
95 /* ASCII symbols */, 10 /* digits */, 26 /* lowercase letters */, 26 /* uppercase letters */
]);
export interface PasswordStrengthResult {

View File

@ -1,4 +1,5 @@
const MobileRegex = /iPhone|iPad|iPod|Android|BlackBerry|Opera Mini|IEMobile|WPDesktop|Windows Phone|webOS/i;
const MobileRegex =
/iPhone|iPad|iPod|Android|BlackBerry|Opera Mini|IEMobile|WPDesktop|Windows Phone|webOS/i;
const MinDesktopScreenWidth = 800;
const isDesktop = !!(window.process && window.process.versions && window.process.versions.electron);

View File

@ -1,4 +1,3 @@
// TODO(ts): remove this
export function escape(str: string): string {
if (!str) {
return str;
@ -23,29 +22,26 @@ export function shuffle<T>(array: T[]): T[] {
return array;
}
// TODO(ts): remove this
export function pick(
obj: Record<string, any> | undefined,
obj: Record<string, unknown> | undefined,
props: string[]
): Record<string, any> | undefined {
): Record<string, unknown> | undefined {
if (!obj) {
return obj;
}
const result: Record<string, any> = {};
const result: Record<string, unknown> = {};
for (const prop of props) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
result[prop] = obj[prop];
}
}
return result;
}
// TODO(ts): remove this
export function omit(
obj: Record<string, any> | undefined,
obj: Record<string, unknown> | undefined,
props: string[]
): Record<string, any> | undefined {
): Record<string, unknown> | undefined {
if (!obj) {
return obj;
}
@ -56,27 +52,28 @@ export function omit(
return result;
}
// TODO(ts): remove this
export function omitEmpty(obj: Record<string, any> | undefined): Record<string, any> | undefined {
export function omitEmpty(
obj: Record<string, unknown> | undefined
): Record<string, unknown> | undefined {
if (!obj) {
return obj;
}
return Object.entries(obj).reduce((result: Record<string, any>, [key, value]) => {
return Object.entries(obj).reduce((result, [key, value]) => {
if (value) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
result[key] = value;
}
return result;
}, {});
}, {} as Record<string, unknown>);
}
// TODO(ts): remove this
export function mapObject(obj: Record<string, any>, fn: (v: any) => any): Record<string, any> {
return Object.entries(obj).reduce((result: Record<string, any>, [key, value]) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
export function mapObject<From, To>(
obj: Record<string, From>,
fn: (v: From) => To
): Record<string, To> {
return Object.entries(obj).reduce((result, [key, value]) => {
result[key] = fn(value);
return result;
}, {});
}, {} as Record<string, To>);
}
export function isEqual<T>(a: T, b: T): boolean {

View File

@ -11,8 +11,7 @@ export const CharRanges: Record<CharRange, string> = {
digits: '123456789',
special: '!@#$%^&*_+-=,./?;:`"~\'\\',
brackets: '(){}[]<>',
high:
'¡¢£¤¥¦§©ª«¬®¯°±²³´µ¶¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ',
high: '¡¢£¤¥¦§©ª«¬®¯°±²³´µ¶¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ',
ambiguous: 'O0oIl'
} as const;

View File

@ -11,7 +11,7 @@ const MaxLogsToSave = 100;
interface LogItem {
level: string;
args: any[];
args: unknown[];
}
const lastLogs: LogItem[] = [];
@ -39,7 +39,7 @@ class Logger {
return new Date().toISOString() + ' [' + this.prefix + '] ';
}
debug(...args: any[]): void {
debug(...args: unknown[]): void {
args[0] = `${this.getPrefix()}${args[0]}`;
if (this.level >= Level.Debug) {
Logger.saveLast('debug', args);
@ -47,7 +47,7 @@ class Logger {
}
}
info(...args: any[]): void {
info(...args: unknown[]): void {
args[0] = `${this.getPrefix()}${args[0]}`;
if (this.level >= Level.Info) {
Logger.saveLast('info', args);
@ -55,7 +55,7 @@ class Logger {
}
}
warn(...args: any[]): void {
warn(...args: unknown[]): void {
args[0] = `${this.getPrefix()}${args[0]}`;
if (this.level >= Level.Warn) {
Logger.saveLast('warn', args);
@ -63,7 +63,7 @@ class Logger {
}
}
error(...args: any[]): void {
error(...args: unknown[]): void {
args[0] = `${this.getPrefix()}${args[0]}`;
if (this.level >= Level.Error) {
Logger.saveLast('error', args);
@ -79,7 +79,7 @@ class Logger {
return this.level;
}
static saveLast(level: string, args: any[]): void {
static saveLast(level: string, args: unknown[]): void {
lastLogs.push({ level, args: Array.prototype.slice.call(args) });
if (lastLogs.length > MaxLogsToSave) {
lastLogs.shift();

View File

@ -27,31 +27,7 @@ class GeneratorView extends View {
};
valuesMap = [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
22,
24,
26,
28,
30,
32,
48,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30, 32, 48,
64
];

14
test/.eslintrc.json Normal file
View File

@ -0,0 +1,14 @@
{
"parserOptions": {
"project": [
"../tsconfig.json",
"../jsconfig.json"
]
},
"env": {
"mocha": true
},
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}

View File

@ -8,11 +8,9 @@ import {
describe('PasswordStrength', () => {
function check(password: string, expected: PasswordStrengthResult): void {
let actual: Record<string, any> = passwordStrength(
kdbxweb.ProtectedValue.fromString(password)
);
const actualResult = passwordStrength(kdbxweb.ProtectedValue.fromString(password));
expected = { onlyDigits: false, ...expected };
actual = { onlyDigits: false, ...actual };
const actual = { onlyDigits: false, ...actualResult } as Record<string, unknown>;
for (const [prop, expVal] of Object.entries(expected)) {
expect(actual[prop]).to.eql(expVal, `${prop} is ${expVal} for password "${password}"`);

View File

@ -6,7 +6,7 @@ import { JSDOM } from 'jsdom';
describe('MdToHtml', () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
const DOMPurify = createDOMPurify((new JSDOM('').window as unknown) as Window);
const DOMPurify = createDOMPurify(new JSDOM('').window as unknown as Window);
createDOMPurify.sanitize = DOMPurify.sanitize.bind(DOMPurify);
});