Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Eslint refactoring (#541)

Leendert de Borst0996375c5e8d
diff --git a/browser-extensions/chrome/src/App.tsx b/browser-extensions/chrome/src/App.tsx
index 07bd3f93b..632b20e6b 100644
--- a/browser-extensions/chrome/src/App.tsx
+++ b/browser-extensions/chrome/src/App.tsx
@@ -66,7 +66,6 @@ const App: React.FC = () => {
<Router>
<div className="min-h-screen min-w-[350px] bg-white dark:bg-gray-900 flex flex-col">
<Header
- authContext={authContext}
toggleUserMenu={() => setIsUserMenuOpen(!isUserMenuOpen)}
isUserMenuOpen={isUserMenuOpen}
routes={routes}
diff --git a/browser-extensions/chrome/src/background/VaultMessageHandler.ts b/browser-extensions/chrome/src/background/VaultMessageHandler.ts
index 2310687c1..c7cc7ee05 100644
--- a/browser-extensions/chrome/src/background/VaultMessageHandler.ts
+++ b/browser-extensions/chrome/src/background/VaultMessageHandler.ts
@@ -203,10 +203,7 @@ export async function handleCreateIdentity(
const webApi = new WebApiService(() => {});
await webApi.initializeBaseUrl();
- /*
- * TODO: re-enable
- * await webApi.post('Vault', newVault);
- */
+ await webApi.post('Vault', newVault);
sendResponse({ success: true });
} catch (error) {
@@ -261,9 +258,8 @@ export function handleGetDefaultEmailDomain(
* taking into account vault settings.
*/
- // Function to check if a domain is valid
/**
- *
+ * Check if a domain is valid.
*/
const isValidDomain = (domain: string) : boolean => {
return domain &&
diff --git a/browser-extensions/chrome/src/components/Layout/Header.tsx b/browser-extensions/chrome/src/components/Layout/Header.tsx
index f8b301ca5..aebb2d960 100644
--- a/browser-extensions/chrome/src/components/Layout/Header.tsx
+++ b/browser-extensions/chrome/src/components/Layout/Header.tsx
@@ -1,12 +1,12 @@
import React from 'react';
import { UserMenu } from './UserMenu';
import { useNavigate, useLocation } from 'react-router-dom';
+import { useAuth } from '../../context/AuthContext';
/**
* Header props.
*/
type HeaderProps = {
- authContext: any;
toggleUserMenu: () => void;
isUserMenuOpen: boolean;
routes?: {
@@ -20,9 +20,9 @@ type HeaderProps = {
* Header component.
*/
const Header: React.FC<HeaderProps> = ({
- authContext,
routes = []
}) => {
+ const authContext = useAuth();
const navigate = useNavigate();
const location = useLocation();
@@ -104,9 +104,7 @@ const Header: React.FC<HeaderProps> = ({
</svg>
</button>
) : (
- <UserMenu
- username={authContext.username}
- />
+ <UserMenu />
)}
</div>
</header>
diff --git a/browser-extensions/chrome/src/components/Layout/UserMenu.tsx b/browser-extensions/chrome/src/components/Layout/UserMenu.tsx
index f3a27d315..d14752c62 100644
--- a/browser-extensions/chrome/src/components/Layout/UserMenu.tsx
+++ b/browser-extensions/chrome/src/components/Layout/UserMenu.tsx
@@ -1,21 +1,12 @@
-import { useState, useRef, useEffect } from 'react';
+import React, { useState, useRef, useEffect } from 'react';
import { useAuth } from '../../context/AuthContext';
import { useNavigate } from 'react-router-dom';
import { useLoading } from '../../context/LoadingContext';
-/**
- * User menu props.
- */
-type UserMenuProps = {
- username: string;
-}
-
/**
* User menu component.
*/
-export const UserMenu: React.FC<UserMenuProps> = ({
- username
-}) => {
+export const UserMenu: React.FC = () => {
const authContext = useAuth();
const [isUserMenuOpen, setIsUserMenuOpen] = useState(false);
const menuRef = useRef<HTMLDivElement>(null);
@@ -84,7 +75,7 @@ export const UserMenu: React.FC<UserMenuProps> = ({
>
<div className="px-4 py-3 border-b border-gray-200 dark:border-gray-600">
<span className="block text-sm font-semibold text-gray-900 dark:text-white">
- {username}
+ {authContext.username}
</span>
</div>
<button
diff --git a/browser-extensions/chrome/src/contentscript/Form.ts b/browser-extensions/chrome/src/contentscript/Form.ts
index 1666d55dd..edf24e30e 100644
--- a/browser-extensions/chrome/src/contentscript/Form.ts
+++ b/browser-extensions/chrome/src/contentscript/Form.ts
@@ -204,9 +204,8 @@ export function injectIcon(input: HTMLInputElement): void {
icon.style.opacity = '1';
});
- // Remove icon when input loses focus, except when clicking the icon
/**
- *
+ * Remove icon when input loses focus, except when clicking the icon
*/
const handleBlur = (e: FocusEvent) : void => {
// Don't remove if clicking the icon itself
diff --git a/browser-extensions/chrome/src/contentscript/Popup.ts b/browser-extensions/chrome/src/contentscript/Popup.ts
index e8cd23755..7beb882e5 100644
--- a/browser-extensions/chrome/src/contentscript/Popup.ts
+++ b/browser-extensions/chrome/src/contentscript/Popup.ts
@@ -61,7 +61,7 @@ export function createBasePopup(input: HTMLInputElement) : HTMLElement {
*/
export function createLoadingPopup(input: HTMLInputElement, message: string) : HTMLElement {
/**
- *
+ * Get the loading wrapper HTML.
*/
const getLoadingHtml = (message: string): string => `
<div style="
@@ -347,9 +347,8 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Creden
actionContainer.appendChild(closeButton);
popup.appendChild(actionContainer);
- // Define handleClickOutside
/**
- *
+ * Handle clicking outside the popup.
*/
const handleClickOutside = (event: MouseEvent) : void => {
const popup = document.getElementById('aliasvault-credential-popup');
@@ -797,7 +796,7 @@ export async function createEditNamePopup(defaultName: string): Promise<string |
input.select();
/**
- *
+ * Close the popup.
*/
const closePopup = (value: string | null) : void => {
popup.style.transform = 'scale(0.95)';
@@ -855,9 +854,8 @@ export function openAutofillPopup(input: HTMLInputElement) : void {
if (!forms.length) return;
- // Add keydown event listener for Enter key
/**
- *
+ * Handle the Enter key.
*/
const handleEnterKey = (e: KeyboardEvent) : void => {
if (e.key === 'Enter') {
diff --git a/browser-extensions/chrome/src/context/DbContext.tsx b/browser-extensions/chrome/src/context/DbContext.tsx
index 75fe096ad..f082503fa 100644
--- a/browser-extensions/chrome/src/context/DbContext.tsx
+++ b/browser-extensions/chrome/src/context/DbContext.tsx
@@ -33,12 +33,12 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
/**
* Public email domains.
*/
- const [publicEmailDomains, setPublicEmailDomains] = useState<string[]>([]);
+ const [, setPublicEmailDomains] = useState<string[]>([]);
/**
* Private email domains.
*/
- const [privateEmailDomains, setPrivateEmailDomains] = useState<string[]>([]);
+ const [, setPrivateEmailDomains] = useState<string[]>([]);
const initializeDatabase = useCallback(async (derivedKey: string, vault: string, publicEmailDomains: string[], privateEmailDomains: string[], vaultRevisionNumber: number) => {
const client = new SqliteClient();
diff --git a/browser-extensions/chrome/src/generators/Identity/UsernameEmailGenerator.ts b/browser-extensions/chrome/src/generators/Identity/UsernameEmailGenerator.ts
index 96371df56..a498e35fd 100644
--- a/browser-extensions/chrome/src/generators/Identity/UsernameEmailGenerator.ts
+++ b/browser-extensions/chrome/src/generators/Identity/UsernameEmailGenerator.ts
@@ -1,7 +1,7 @@
import { Identity } from "./types/Identity";
/**
- *
+ * Generate a username or email prefix.
*/
export class UsernameEmailGenerator {
private static readonly MIN_LENGTH = 6;
@@ -9,7 +9,7 @@ export class UsernameEmailGenerator {
private readonly symbols: string[] = ['.', '-'];
/**
- *
+ * Generate a username based on an identity.
*/
public generateUsername(identity: Identity): string {
// Generate username based on email prefix but strip all non-alphanumeric characters
@@ -27,7 +27,7 @@ export class UsernameEmailGenerator {
}
/**
- *
+ * Generate an email prefix based on an identity.
*/
public generateEmailPrefix(identity: Identity): string {
const parts: string[] = [];
@@ -88,7 +88,7 @@ export class UsernameEmailGenerator {
}
/**
- *
+ * Sanitize an email prefix.
*/
private sanitizeEmailPrefix(input: string): string {
// Remove any character that's not a letter, number, dot, underscore, or hyphen including special characters
@@ -104,14 +104,14 @@ export class UsernameEmailGenerator {
}
/**
- *
+ * Get a random symbol.
*/
private getRandomSymbol(): string {
return Math.floor(Math.random() * 3) === 0 ? this.symbols[Math.floor(Math.random() * this.symbols.length)] : '';
}
/**
- *
+ * Generate a random string.
*/
private generateRandomString(length: number): string {
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
diff --git a/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorEn.ts b/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorEn.ts
index b53014f1b..b43e3a623 100644
--- a/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorEn.ts
+++ b/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorEn.ts
@@ -1,11 +1,11 @@
import { BaseIdentityGenerator } from "./base/BaseIdentityGenerator";
/**
- *
+ * Identity generator for English language using English word dictionaries.
*/
export class IdentityGeneratorEn extends BaseIdentityGenerator {
/**
- *
+ * Get the male first names.
*/
protected getFirstNamesMaleJson(): string[] {
/*
@@ -16,7 +16,7 @@ export class IdentityGeneratorEn extends BaseIdentityGenerator {
}
/**
- *
+ * Get the female first names.
*/
protected getFirstNamesFemaleJson(): string[] {
/*
@@ -27,7 +27,7 @@ export class IdentityGeneratorEn extends BaseIdentityGenerator {
}
/**
- *
+ * Get the last names.
*/
protected getLastNamesJson(): string[] {
/*
diff --git a/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorNl.ts b/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorNl.ts
index c49aa3f7a..53ea8b958 100644
--- a/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorNl.ts
+++ b/browser-extensions/chrome/src/generators/Identity/implementations/IdentityGeneratorNl.ts
@@ -1,11 +1,11 @@
import { BaseIdentityGenerator } from "./base/BaseIdentityGenerator";
/**
- *
+ * Identity generator for Dutch language using Dutch word dictionaries.
*/
export class IdentityGeneratorNl extends BaseIdentityGenerator {
/**
- *
+ * Get the male first names.
*/
protected getFirstNamesMaleJson(): string[] {
/*
@@ -16,7 +16,7 @@ export class IdentityGeneratorNl extends BaseIdentityGenerator {
}
/**
- *
+ * Get the female first names.
*/
protected getFirstNamesFemaleJson(): string[] {
/*
@@ -27,7 +27,7 @@ export class IdentityGeneratorNl extends BaseIdentityGenerator {
}
/**
- *
+ * Get the last names.
*/
protected getLastNamesJson(): string[] {
/*
diff --git a/browser-extensions/chrome/src/generators/Password/PasswordGenerator.ts b/browser-extensions/chrome/src/generators/Password/PasswordGenerator.ts
index 0d223b136..d0fc442e7 100644
--- a/browser-extensions/chrome/src/generators/Password/PasswordGenerator.ts
+++ b/browser-extensions/chrome/src/generators/Password/PasswordGenerator.ts
@@ -1,5 +1,5 @@
/**
- *
+ * Generate a random password.
*/
export class PasswordGenerator {
private readonly lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
@@ -14,7 +14,7 @@ export class PasswordGenerator {
private useSpecial: boolean = true;
/**
- *
+ * Set the length of the password.
*/
public setLength(length: number): PasswordGenerator {
this.length = length;
@@ -22,7 +22,7 @@ export class PasswordGenerator {
}
/**
- *
+ * Set if lowercase letters should be used.
*/
public useLowercaseLetters(use: boolean): PasswordGenerator {
this.useLowercase = use;
@@ -30,7 +30,7 @@ export class PasswordGenerator {
}
/**
- *
+ * Set if uppercase letters should be used.
*/
public useUppercaseLetters(use: boolean): PasswordGenerator {
this.useUppercase = use;
@@ -38,7 +38,7 @@ export class PasswordGenerator {
}
/**
- *
+ * Set if numeric characters should be used.
*/
public useNumericCharacters(use: boolean): PasswordGenerator {
this.useNumbers = use;
@@ -46,7 +46,7 @@ export class PasswordGenerator {
}
/**
- *
+ * Set if special characters should be used.
*/
public useSpecialCharacters(use: boolean): PasswordGenerator {
this.useSpecial = use;
@@ -54,7 +54,7 @@ export class PasswordGenerator {
}
/**
- *
+ * Get a random index from the crypto module.
*/
private getUnbiasedRandomIndex(max: number): number {
// Calculate the largest multiple of max that fits within Uint32
@@ -73,7 +73,7 @@ export class PasswordGenerator {
}
/**
- *
+ * Generate a random password.
*/
public generateRandomPassword(): string {
let chars = '';
@@ -114,7 +114,7 @@ export class PasswordGenerator {
this.numberChars[this.getUnbiasedRandomIndex(this.numberChars.length)] +
password.substring(pos + 1);
}
- if (this.useSpecial && !password.match(/[!@#$%^&*()_+\-=\[\]{}|;:,.<>?]/)) {
+ if (this.useSpecial && !password.match(/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/)) {
const pos = this.getUnbiasedRandomIndex(this.length);
password = password.substring(0, pos) +
this.specialChars[this.getUnbiasedRandomIndex(this.specialChars.length)] +
diff --git a/browser-extensions/chrome/src/generators/Password/__tests__/PasswordGenerator.test.ts b/browser-extensions/chrome/src/generators/Password/__tests__/PasswordGenerator.test.ts
index 3aab96a45..637bfbef5 100644
--- a/browser-extensions/chrome/src/generators/Password/__tests__/PasswordGenerator.test.ts
+++ b/browser-extensions/chrome/src/generators/Password/__tests__/PasswordGenerator.test.ts
@@ -18,7 +18,7 @@ describe('PasswordGenerator', () => {
expect(password).toMatch(/[a-z]/); // lowercase
expect(password).toMatch(/[A-Z]/); // uppercase
expect(password).toMatch(/[0-9]/); // numbers
- expect(password).toMatch(/[!@#$%^&*()_+\-=\[\]{}|;:,.<>?]/); // special
+ expect(password).toMatch(/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/); // special
});
it('respects custom length setting', () => {
@@ -44,7 +44,7 @@ describe('PasswordGenerator', () => {
it('respects special characters setting', () => {
const password = generator.useSpecialCharacters(false).generateRandomPassword();
- expect(password).not.toMatch(/[!@#$%^&*()_+\-=\[\]{}|;:,.<>?]/);
+ expect(password).not.toMatch(/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/);
});
it('generates different passwords on subsequent calls', () => {
@@ -62,7 +62,7 @@ describe('PasswordGenerator', () => {
expect(password).toMatch(/[a-z]/);
expect(password).toMatch(/[A-Z]/);
expect(password).toMatch(/[0-9]/);
- expect(password).toMatch(/[!@#$%^&*()_+\-=\[\]{}|;:,.<>?]/);
+ expect(password).toMatch(/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/);
}
});
diff --git a/browser-extensions/chrome/src/pages/UnlockSuccess.tsx b/browser-extensions/chrome/src/pages/UnlockSuccess.tsx
index 5f72eaf3a..25f82deb0 100644
--- a/browser-extensions/chrome/src/pages/UnlockSuccess.tsx
+++ b/browser-extensions/chrome/src/pages/UnlockSuccess.tsx
@@ -1,7 +1,8 @@
import React from 'react';
/**
- *
+ * Unlock success component shown when the vault is successfully unlocked in a separate popup
+ * asking the user if they want to close the popup.
*/
const UnlockSuccess: React.FC<{
onClose: () => void;
diff --git a/browser-extensions/chrome/src/utils/SqliteClient.tsx b/browser-extensions/chrome/src/utils/SqliteClient.tsx
index 1c903fc22..916ae6537 100644
--- a/browser-extensions/chrome/src/utils/SqliteClient.tsx
+++ b/browser-extensions/chrome/src/utils/SqliteClient.tsx
@@ -149,6 +149,7 @@ class SqliteClient {
const results = this.executeQuery(query);
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
return results.map((row: any) => ({
Id: row.Id,
Username: row.Username,
diff --git a/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts b/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts
index f5eeea3c4..22d23bd61 100644
--- a/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts
+++ b/browser-extensions/chrome/src/utils/form-detector/FormDetector.ts
@@ -204,9 +204,8 @@ export class FormDetector {
let primaryEmail: HTMLInputElement | null = null;
let confirmEmail: HTMLInputElement | null = null;
- // Helper function to check if an input is an email field
/**
- *
+ * Check if an input is an email field.
*/
const isEmailField = (input: HTMLInputElement, confirmPatterns: string[] = []): boolean => {
const type = input.type.toLowerCase();
@@ -264,7 +263,7 @@ export class FormDetector {
}
/**
- *
+ * Find the birthdate fields in the form.
*/
private findBirthdateFields(form: HTMLFormElement | null): LoginForm['birthdateField'] {
// First try to find a single date input
@@ -288,7 +287,7 @@ export class FormDetector {
.join(' ')
// Normalize different types of spaces and separators
.replace(/[\s\u00A0]/g, '')
- .replace(/[\/\-]/g, '');
+ .replace(/[/-]/g, '');
// Check for date format patterns
if (/dd.*mm.*jj/i.test(allText) || /dd.*mm.*yyyy/i.test(allText)) {
@@ -301,7 +300,7 @@ export class FormDetector {
// Check placeholder as fallback
if (format === 'yyyy-mm-dd' && singleDateField.placeholder) {
- const placeholder = singleDateField.placeholder.toLowerCase().replace(/[\s\u00A0\-\/]/g, '');
+ const placeholder = singleDateField.placeholder.toLowerCase().replace(/[\s\u00A0\-/]/g, '');
if (/ddmm/.test(placeholder)) {
format = 'dd-mm-yyyy';
} else if (/mmdd/.test(placeholder)) {
@@ -336,7 +335,7 @@ export class FormDetector {
}
/**
- *
+ * Find the gender field in the form.
*/
private findGenderField(form: HTMLFormElement | null): LoginForm['genderField'] {
// Try to find select element first
@@ -363,7 +362,7 @@ export class FormDetector {
const otherPatterns = ['other', 'diverse', 'custom', 'prefer not', 'anders', 'iets', 'unknown', 'gender3'];
/**
- *
+ * Find a radio button by patterns.
*/
const findRadioByPatterns = (patterns: string[], isOther: boolean = false) : HTMLInputElement | null => {
return Array.from(radioButtons).find(radio => {
diff --git a/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts b/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts
index 7c0e4ccbb..75de67dbc 100644
--- a/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts
+++ b/browser-extensions/chrome/src/utils/form-detector/__tests__/FormDetector.test.ts
@@ -5,17 +5,15 @@ import { describe, it, expect } from 'vitest';
import { JSDOM } from 'jsdom';
import { LoginForm } from '../types/LoginForm';
-// Helper function to load HTML test files
/**
- *
+ * Load a test HTML file.
*/
const loadTestHtml = (filename: string): string => {
return readFileSync(join(__dirname, 'test-forms', filename), 'utf-8');
};
-// Helper function to setup form detection test
/**
- *
+ * Setup a form detection test.
*/
const setupFormTest = (htmlFile: string) : { document: Document, result: LoginForm } => {
const html = loadTestHtml(htmlFile);
@@ -91,9 +89,8 @@ const testField = (fieldName: FormField, elementId: string, htmlFile: string) :
});
};
-// New helper function to test birthdate format property
/**
- *
+ * Test the birthdate format.
*/
const testBirthdateFormat = (expectedFormat: string, htmlFile: string) : void => {
it('should detect correct birthdate format', () => {