From 4318a57a613e9cf880404f616a141c780bdbc753 Mon Sep 17 00:00:00 2001 From: Simon Skoczylas Date: Wed, 21 Jan 2026 18:29:30 +0100 Subject: [PATCH 1/4] Fix ESLint errors --- .prettierignore | 1 + eslint.config.js | 21 +++++++++------------ src/App.tsx | 12 ++++++------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.prettierignore b/.prettierignore index 17b03f7..c41b4e7 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,4 @@ dist node_modules docs *.html +coverage diff --git a/eslint.config.js b/eslint.config.js index 092408a..342511a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,11 +1,11 @@ -import js from '@eslint/js' -import globals from 'globals' -import reactHooks from 'eslint-plugin-react-hooks' -import reactRefresh from 'eslint-plugin-react-refresh' -import tseslint from 'typescript-eslint' +import js from '@eslint/js'; +import globals from 'globals'; +import reactHooks from 'eslint-plugin-react-hooks'; +import reactRefresh from 'eslint-plugin-react-refresh'; +import tseslint from 'typescript-eslint'; export default tseslint.config( - { ignores: ['dist'] }, + { ignores: ['dist', 'coverage'] }, { extends: [js.configs.recommended, ...tseslint.configs.recommended], files: ['**/*.{ts,tsx}'], @@ -19,10 +19,7 @@ export default tseslint.config( }, rules: { ...reactHooks.configs.recommended.rules, - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], + 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], }, - }, -) + } +); diff --git a/src/App.tsx b/src/App.tsx index 8444d4a..340d02b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,6 +21,11 @@ interface Mark { label: string; } +const gcd = (a: number, b: number): number => { + if (b === 0) return a; + return gcd(b, a % b); +}; + function App() { const defaultLength = 16; const minLength = 4; @@ -38,7 +43,7 @@ function App() { const password = useMemo(() => { return genPassword(length, lowercase, uppercase, digits, special, excludeAmbiguous); - }, [toggle, length, lowercase, uppercase, digits, special, excludeAmbiguous]); + }, [length, lowercase, uppercase, digits, special, excludeAmbiguous]); const handleSliderChange = (_event: Event, newValue: number | number[]) => { if (Array.isArray(newValue)) { @@ -74,11 +79,6 @@ function App() { }); }; - const gcd = (a: number, b: number): number => { - if (b === 0) return a; - return gcd(b, a % b); - }; - const marks = useMemo(() => { const result: Mark[] = []; From 425c6f4f30b67ca667e44e5169f26c1ff4403c04 Mon Sep 17 00:00:00 2001 From: Simon Skoczylas Date: Wed, 21 Jan 2026 18:41:30 +0100 Subject: [PATCH 2/4] Improve code and remove toggle --- src/App.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 340d02b..26551b9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import { Box, Button, @@ -31,7 +31,6 @@ function App() { const minLength = 4; const maxLength = 64; - const [toggle, setToggle] = useState(false); const [copied, setCopied] = useState(false); const [length, setLength] = useState(defaultLength); @@ -41,10 +40,19 @@ function App() { const [special, setSpecial] = useState(false); const [excludeAmbiguous, setExcludeAmbiguous] = useState(true); - const password = useMemo(() => { - return genPassword(length, lowercase, uppercase, digits, special, excludeAmbiguous); + const [password, setPassword] = useState(() => + genPassword(defaultLength, true, true, true, false, true) + ); + + const regeneratePassword = useCallback(() => { + setPassword(genPassword(length, lowercase, uppercase, digits, special, excludeAmbiguous)); }, [length, lowercase, uppercase, digits, special, excludeAmbiguous]); + // Regenerate whenever inputs change + useEffect(() => { + regeneratePassword(); + }, [regeneratePassword]); + const handleSliderChange = (_event: Event, newValue: number | number[]) => { if (Array.isArray(newValue)) { setLength(defaultLength); @@ -175,7 +183,7 @@ function App() {