From 41e893b337c06c5d6ceb8e42c932c933a8de7386 Mon Sep 17 00:00:00 2001 From: abhijithvijayan <34790378+abhijithvijayan@users.noreply.github.com> Date: Sun, 4 Jan 2026 03:19:26 +0530 Subject: [PATCH] fix: linting issues --- .eslintignore | 5 - .eslintrc.json | 34 ----- eslint.config.mjs | 48 +++++++ source/Background/index.ts | 3 +- source/History/History.tsx | 16 ++- source/History/Modal.tsx | 11 +- source/History/Table.tsx | 115 +++++++-------- source/Options/Footer.tsx | 28 +++- source/Options/Form.tsx | 134 +++++++++++++----- source/Options/Header.tsx | 6 +- source/Options/Options.tsx | 19 ++- source/Popup/Form.tsx | 103 +++++++++----- source/Popup/Header.tsx | 3 +- source/Popup/Popup.tsx | 36 ++--- source/Popup/ResponseBody.tsx | 25 ++-- source/components/BodyWrapper.tsx | 4 +- source/components/Icon/ChevronDown.tsx | 30 ++-- source/components/Icon/Clock.tsx | 34 +++-- source/components/Icon/Copy.tsx | 34 +++-- source/components/Icon/Cross.tsx | 32 ++--- source/components/Icon/Eye.tsx | 34 +++-- source/components/Icon/EyeClosed.tsx | 32 ++--- source/components/Icon/Icon.tsx | 6 +- source/components/Icon/Info.tsx | 34 +++-- source/components/Icon/QRCode.tsx | 32 ++--- source/components/Icon/Refresh.tsx | 34 +++-- source/components/Icon/Settings.tsx | 34 +++-- source/components/Icon/Spinner.tsx | 54 ++++--- source/components/Icon/StarWhite.tsx | 32 ++--- source/components/Icon/StarYellow.tsx | 32 ++--- source/components/Icon/Tick.tsx | 32 ++--- source/components/Icon/Zap.tsx | 32 ++--- source/components/Loader.tsx | 3 +- .../contexts/extension-settings-context.tsx | 6 +- source/contexts/request-status-context.tsx | 8 +- source/contexts/shortened-links-context.tsx | 8 +- source/util/browser.ts | 2 +- source/util/settings.ts | 1 - 38 files changed, 625 insertions(+), 511 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json create mode 100644 eslint.config.mjs diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 912010f..0000000 --- a/.eslintignore +++ /dev/null @@ -1,5 +0,0 @@ -node_modules/ -dist/ -extension/ -.yarn/ -.pnp.js \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index f1ee212..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "env": { - "webextensions": true - }, - "extends": [ - "@abhijithvijayan/eslint-config/typescript", - "@abhijithvijayan/eslint-config/node", - "@abhijithvijayan/eslint-config/react" - ], - "parserOptions": { - "project": "./tsconfig.json", - "sourceType": "module" - }, - "rules": { - "no-console": "off", - "no-shadow": ["error", { - "builtinGlobals": false, - "hoist": "functions", - "allow": [] - }], - "react/jsx-props-no-spreading": "off", - "jsx-a11y/label-has-associated-control": "off", - "@typescript-eslint/no-explicit-any": "warn", - "react/no-array-index-key": "warn", - "node/no-unsupported-features/es-syntax": ["error", { - "ignores": ["modules"] - }] - }, - "settings": { - "node": { - "tryExtensions": [".tsx"] // append tsx to the list as well - } - } -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..9cfa513 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,48 @@ +import nodeConfig from '@abhijithvijayan/eslint-config/node'; +import tsConfig from '@abhijithvijayan/eslint-config/typescript'; +import reactConfig from '@abhijithvijayan/eslint-config/react'; + +export default [ + { + ignores: [ + 'node_modules/**', + 'dist/**', + 'extension/**', + '.yarn/**', + '.pnp.js', + '*.js', + '*.mjs', + 'vite.config.ts', + ], + }, + ...nodeConfig({ + files: ['**/*.ts', '**/*.tsx'], + }), + ...tsConfig({ + files: ['**/*.ts', '**/*.tsx'], + }), + ...reactConfig({ + files: ['**/*.tsx'], + }), + { + files: ['**/*.ts', '**/*.tsx'], + rules: { + 'no-console': 'off', + '@typescript-eslint/no-use-before-define': 'warn', + '@typescript-eslint/no-explicit-any': 'warn', + // Disable due to resolver issues in ESM + 'import-x/no-duplicates': 'off', + // Browser extension code uses browser APIs, not Node.js + 'n/no-unsupported-features/node-builtins': 'off', + }, + }, + { + files: ['**/*.tsx'], + rules: { + 'react/jsx-props-no-spreading': 'off', + 'react/react-in-jsx-scope': 'off', + 'react/no-array-index-key': 'warn', + 'jsx-a11y/label-has-associated-control': 'off', + }, + }, +]; diff --git a/source/Background/index.ts b/source/Background/index.ts index 8cab093..29e8656 100644 --- a/source/Background/index.ts +++ b/source/Background/index.ts @@ -340,8 +340,7 @@ type MessageRequest = { browser.runtime.onMessage.addListener( (message: unknown, _sender: Runtime.MessageSender): void | Promise => { const request = message as MessageRequest; - // eslint-disable-next-line consistent-return - // eslint-disable-next-line default-case + switch (request.action) { case constants.CHECK_API_KEY: { return checkApiKey(request.params); diff --git a/source/History/History.tsx b/source/History/History.tsx index ba053b0..62ed20e 100644 --- a/source/History/History.tsx +++ b/source/History/History.tsx @@ -1,3 +1,4 @@ +import type {JSX} from 'react'; import {useEffect, useState} from 'react'; import { @@ -31,7 +32,7 @@ import Table from './Table'; import styles from './History.module.scss'; -function History() { +function History(): JSX.Element { const [, shortenedLinksDispatch] = useShortenedLinks(); const [, extensionSettingsDispatch] = useExtensionSettings(); const [requestStatusState, requestStatusDispatch] = useRequestStatus(); @@ -54,11 +55,12 @@ function History() { (advancedSettings && (settings?.host as string) && isValidUrl(settings.host as string) && { - hostDomain: (settings.host as string) - .replace('http://', '') - .replace('https://', '') - .replace('www.', '') - .split(/[/?#]/)[0] || '', // extract domain + hostDomain: + (settings.host as string) + .replace('http://', '') + .replace('https://', '') + .replace('www.', '') + .split(/[/?#]/)[0] || '', // extract domain hostUrl: (settings.host as string).endsWith('/') ? (settings.host as string).slice(0, -1) : (settings.host as string), // slice `/` at the end @@ -137,7 +139,7 @@ function History() {
- {/* eslint-disable-next-line no-nested-ternary */} + {} {!requestStatusState.loading ? ( !errored.error ? ( diff --git a/source/History/Modal.tsx b/source/History/Modal.tsx index 657c4a2..4efb755 100644 --- a/source/History/Modal.tsx +++ b/source/History/Modal.tsx @@ -1,4 +1,5 @@ import {QRCodeSVG} from 'qrcode.react'; +import type {JSX} from 'react'; import {Dispatch, SetStateAction} from 'react'; import styles from './Modal.module.scss'; @@ -8,16 +9,24 @@ type Props = { setModalView: Dispatch>; }; -function Modal({link, setModalView}: Props) { +function Modal({link, setModalView}: Props): JSX.Element { return ( <>
setModalView(false)} + onKeyDown={(e): void => { + if (e.key === 'Escape') setModalView(false); + }} + role="button" + tabIndex={0} >
e.stopPropagation()} + onKeyDown={(e): void => e.stopPropagation()} + role="button" + tabIndex={0} >
diff --git a/source/History/Table.tsx b/source/History/Table.tsx index 92f31be..44e803c 100644 --- a/source/History/Table.tsx +++ b/source/History/Table.tsx @@ -1,4 +1,5 @@ import CopyToClipboard from 'react-copy-to-clipboard'; +import type {JSX} from 'react'; import {useEffect, useState} from 'react'; import clsx from 'clsx'; @@ -13,7 +14,7 @@ import Modal from './Modal'; import styles from './Table.module.scss'; -function Table() { +function Table(): JSX.Element { const [shortenedLinksState, shortenedLinksDispatch] = useShortenedLinks(); const [QRView, setQRView] = useState(false); const [copied, setCopied] = useState(false); @@ -72,76 +73,70 @@ function Table() {
{!(shortenedLinksState.total === 0) ? ( - shortenedLinksState.items.map((item) => { - return ( - - + + + + + + + + + + )} - - - ); - }) + {/* // **** QR CODE MODAL **** // */} + {QRView && + shortenedLinksState.selected?.id === item.id && ( + + )} + + + )) ) : ( diff --git a/source/Options/Footer.tsx b/source/Options/Footer.tsx index 4bce935..ec8c841 100644 --- a/source/Options/Footer.tsx +++ b/source/Options/Footer.tsx @@ -1,3 +1,4 @@ +import type {JSX} from 'react'; import {memo} from 'react'; import clsx from 'clsx'; @@ -8,7 +9,7 @@ import Icon from '../components/Icon'; import styles from './Footer.module.scss'; -function Footer() { +function Footer(): JSX.Element { return ( <>
+ shortenedLinksState.items.map((item) => ( +
+ + {item.target} + + + {copied && + shortenedLinksState.selected?.id === item.id && ( +
+ Copied to clipboard! +
+ )} + +
+
+ {/* // **** COPY TO CLIPBOARD **** // */} -
{copied && - shortenedLinksState.selected?.id === item.id && ( -
- Copied to clipboard! -
- )} - - -
-
- {/* // **** COPY TO CLIPBOARD **** // */} + handleQRCodeViewToggle(item.id)} + className={styles.actionIcon} + name="qrcode" + /> +
- {copied && - shortenedLinksState.selected?.id === item.id ? ( - - ) : ( - { - return handleCopyToClipboard(item.id); - }} - > - - - )} - - - handleQRCodeViewToggle(item.id) - } - className={styles.actionIcon} - name="qrcode" - /> - - - {/* // **** QR CODE MODAL **** // */} - {QRView && - shortenedLinksState.selected?.id === item.id && ( - - )} -
No URLs History