From fdc721ebd0499937a87027f011fca20164176bac Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 23 Jan 2024 19:32:57 +0300 Subject: [PATCH] linted --- .eslintignore | 3 +- .eslintrc.cjs | 150 +++++++++--------- .stylelintrc | 2 + src/components/Article/FullArticle.tsx | 4 +- src/components/AuthGuard/AuthGuard.tsx | 6 +- src/components/Discours/Donate.tsx | 4 +- src/components/Editor/extensions/Iframe.ts | 2 +- .../Editor/extensions/ToggleTextWrap.ts | 2 +- .../FeedArticlePopup/FeedArticlePopup.tsx | 2 +- .../Feed/Sidebar/Sidebar.module.scss | 4 - .../Nav/AuthModal/SocialProviders.module.scss | 2 + .../Nav/SearchModal/SearchModal.module.scss | 6 +- .../_shared/Lightbox/Lightbox.module.scss | 2 - .../_shared/SolidSwiper/Swiper.module.scss | 5 +- src/components/_shared/TimeAgo/TimeAgo.tsx | 2 +- src/context/connect.tsx | 3 +- src/context/reactions.tsx | 15 +- src/context/session.tsx | 2 +- src/renderer/types.ts | 3 +- src/styles/app.scss | 2 + src/utils/pageLoadManager.ts | 4 +- 21 files changed, 113 insertions(+), 112 deletions(-) diff --git a/.eslintignore b/.eslintignore index 338ea90a..9261a192 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ node_modules public *.cjs -src/graphql/schema/*.gen.ts dist/ .vercel/ +src/graphql/client/* +src/graphql/schema/* diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 7dfc69c2..1d64686f 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,106 +1,108 @@ module.exports = { - plugins: ["@typescript-eslint", "import", "sonarjs", "unicorn", "promise", "solid", "jest"], + plugins: ['@typescript-eslint', 'import', 'sonarjs', 'unicorn', 'promise', 'solid', 'jest'], extends: [ - "eslint:recommended", - "plugin:import/recommended", - "plugin:import/typescript", - "prettier", - "plugin:sonarjs/recommended", - "plugin:unicorn/recommended", - "plugin:promise/recommended", - "plugin:solid/recommended", - "plugin:jest/recommended" + 'eslint:recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'prettier', + 'plugin:sonarjs/recommended', + 'plugin:unicorn/recommended', + 'plugin:promise/recommended', + 'plugin:solid/recommended', + 'plugin:jest/recommended', ], overrides: [ { - files: ["**/*.ts", "**/*.tsx"], - parser: "@typescript-eslint/parser", + files: ['**/*.ts', '**/*.tsx'], + parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 2021, ecmaFeatures: { jsx: true }, - sourceType: "module", - project: "./tsconfig.json" + sourceType: 'module', + project: './tsconfig.json', }, extends: [ - "plugin:@typescript-eslint/recommended" - // Maybe one day... - // 'plugin:@typescript-eslint/recommended-requiring-type-checking' + 'plugin:@typescript-eslint/recommended', + // 'plugin:@typescript-eslint/recommended-requiring-type-checking', // 23-01-2024 896 problems ], rules: { - "@typescript-eslint/no-unused-vars": [ - "warn", + '@typescript-eslint/no-unused-vars': [ + 'warn', { - argsIgnorePattern: "^_" - } + argsIgnorePattern: '^_', + }, ], - "@typescript-eslint/no-non-null-assertion": "error", - // TODO: Remove any usage and enable - "@typescript-eslint/no-explicit-any": "off" - } - } + '@typescript-eslint/no-non-null-assertion': 'error', + '@typescript-eslint/no-explicit-any': 'warn', + }, + }, ], env: { browser: true, node: true, - mocha: true + mocha: true, }, globals: {}, rules: { // Solid - "solid/reactivity": "off", // FIXME - "solid/no-innerhtml": "off", + 'solid/reactivity': 'off', // too many 'should be used within JSX' + 'solid/no-innerhtml': 'off', /** Unicorn **/ - "unicorn/no-null": "off", - "unicorn/filename-case": "off", - "unicorn/no-array-for-each": "off", - "unicorn/no-array-reduce": "off", - "unicorn/prefer-string-replace-all": "warn", - "unicorn/prevent-abbreviations": "off", - "unicorn/prefer-module": "off", - "unicorn/import-style": "off", - "unicorn/numeric-separators-style": "off", - "unicorn/prefer-node-protocol": "off", - "unicorn/prefer-dom-node-append": "off", // FIXME - "unicorn/prefer-top-level-await": "warn", - "unicorn/consistent-function-scoping": "warn", - "unicorn/no-array-callback-reference": "warn", - "unicorn/no-array-method-this-argument": "warn", - "unicorn/no-for-loop": "off", + 'unicorn/no-null': 'off', + 'unicorn/filename-case': 'off', + 'unicorn/no-array-for-each': 'off', + 'unicorn/no-array-reduce': 'off', + 'unicorn/prefer-string-replace-all': 'warn', + 'unicorn/prevent-abbreviations': 'off', + 'unicorn/prefer-module': 'off', + 'unicorn/import-style': 'off', + 'unicorn/numeric-separators-style': 'off', + 'unicorn/prefer-node-protocol': 'off', + 'unicorn/prefer-dom-node-append': 'off', // FIXME + 'unicorn/prefer-top-level-await': 'warn', + 'unicorn/consistent-function-scoping': 'warn', + 'unicorn/no-array-callback-reference': 'warn', + 'unicorn/no-array-method-this-argument': 'warn', + 'unicorn/no-for-loop': 'off', - "sonarjs/no-duplicate-string": ["warn", { threshold: 5 }], + 'sonarjs/no-duplicate-string': ['warn', { threshold: 5 }], + 'sonarjs/prefer-immediate-return': 'warn', // Promise - // 'promise/catch-or-return': 'off', // Should be enabled - "promise/always-return": "off", + 'promise/catch-or-return': 'off', + 'promise/always-return': 'off', - eqeqeq: "error", - "no-param-reassign": "error", - "no-nested-ternary": "error", - "no-shadow": "error", + eqeqeq: 'error', + 'no-param-reassign': 'error', + 'no-nested-ternary': 'error', + 'no-shadow': 'error', - "import/order": ["warn", { - groups: ["type", "builtin", "external", "internal", "parent", "sibling", "index"], - distinctGroup: false, - pathGroups: [ - { - pattern: "*.scss", - patternOptions: { matchBase: true }, - group: "index", - position: "after" - } - ], - "newlines-between": "always", - alphabetize: { - order: "asc", - caseInsensitive: true - } - }] + 'import/order': [ + 'warn', + { + groups: ['type', 'builtin', 'external', 'internal', 'parent', 'sibling', 'index'], + distinctGroup: false, + pathGroups: [ + { + pattern: '*.scss', + patternOptions: { matchBase: true }, + group: 'index', + position: 'after', + }, + ], + 'newlines-between': 'always', + alphabetize: { + order: 'asc', + caseInsensitive: true, + }, + }, + ], }, settings: { - "import/resolver": { + 'import/resolver': { typescript: true, - node: true - } - } -}; + node: true, + }, + }, +} diff --git a/.stylelintrc b/.stylelintrc index 6630d052..5923b87b 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -7,6 +7,8 @@ "stylelint-scss" ], "rules": { + "keyframes-name-pattern": null, + "declaration-block-no-redundant-longhand-properties": null, "selector-class-pattern": null, "no-descending-specificity": null, "scss/function-no-unknown": null, diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index d956b58b..3d16c043 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -300,8 +300,8 @@ export const FullArticle = (props: Props) => { const originalWidth = iframe.getAttribute('width') || style.width.replace('px', '') const originalHeight = iframe.getAttribute('height') || style.height.replace('px', '') - const width = Number(originalWidth) - const height = Number(originalHeight) + const width: IframeSize['width'] = Number(originalWidth) + const height: IframeSize['height'] = Number(originalHeight) if (containerWidth < width) { const aspectRatio = width / height diff --git a/src/components/AuthGuard/AuthGuard.tsx b/src/components/AuthGuard/AuthGuard.tsx index 5cfa404f..a7ef1ff8 100644 --- a/src/components/AuthGuard/AuthGuard.tsx +++ b/src/components/AuthGuard/AuthGuard.tsx @@ -12,11 +12,7 @@ type Props = { } export const AuthGuard = (props: Props) => { - const { - isAuthenticated, - isSessionLoaded, - actions: { loadSession }, - } = useSession() + const { isAuthenticated, isSessionLoaded } = useSession() const { changeSearchParams } = useRouter() createEffect(async () => { diff --git a/src/components/Discours/Donate.tsx b/src/components/Discours/Donate.tsx index 0264fce7..6f5ea453 100644 --- a/src/components/Discours/Donate.tsx +++ b/src/components/Discours/Donate.tsx @@ -30,9 +30,7 @@ export const Donate = () => { const initiated = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { - cp: { CloudPayments }, - } = window as any // Checkout(cpOptions) + const CloudPayments = window['cp'] // Checkout(cpOptions) setWidget(new CloudPayments()) console.log('[donate] payments initiated') setCustomerReciept({ diff --git a/src/components/Editor/extensions/Iframe.ts b/src/components/Editor/extensions/Iframe.ts index 95cd0bd7..3c73371d 100644 --- a/src/components/Editor/extensions/Iframe.ts +++ b/src/components/Editor/extensions/Iframe.ts @@ -3,7 +3,7 @@ import { Node } from '@tiptap/core' export interface IframeOptions { allowFullscreen: boolean HTMLAttributes: { - [key: string]: any + [key: string]: string | number } } diff --git a/src/components/Editor/extensions/ToggleTextWrap.ts b/src/components/Editor/extensions/ToggleTextWrap.ts index 574f9321..5c8dc0f0 100644 --- a/src/components/Editor/extensions/ToggleTextWrap.ts +++ b/src/components/Editor/extensions/ToggleTextWrap.ts @@ -16,7 +16,7 @@ export const ToggleTextWrap = Extension.create({ return { addTextWrap: (attributes) => - ({ commands, state }) => { + ({ commands, state: _s }) => { return commands.setMark('span', attributes) }, diff --git a/src/components/Feed/FeedArticlePopup/FeedArticlePopup.tsx b/src/components/Feed/FeedArticlePopup/FeedArticlePopup.tsx index 6fb66509..98e8822f 100644 --- a/src/components/Feed/FeedArticlePopup/FeedArticlePopup.tsx +++ b/src/components/Feed/FeedArticlePopup/FeedArticlePopup.tsx @@ -1,7 +1,7 @@ import type { PopupProps } from '../../_shared/Popup' import { clsx } from 'clsx' -import { createEffect, createSignal, onMount, Show } from 'solid-js' +import { createSignal, Show } from 'solid-js' import { useLocalize } from '../../../context/localize' import { Popup } from '../../_shared/Popup' diff --git a/src/components/Feed/Sidebar/Sidebar.module.scss b/src/components/Feed/Sidebar/Sidebar.module.scss index 4459a7eb..e6675249 100644 --- a/src/components/Feed/Sidebar/Sidebar.module.scss +++ b/src/components/Feed/Sidebar/Sidebar.module.scss @@ -33,10 +33,6 @@ margin-right: 1.2rem; } - .userpic { - margin-right: 1.2rem; - } - .selected { font-weight: 700; } diff --git a/src/components/Nav/AuthModal/SocialProviders.module.scss b/src/components/Nav/AuthModal/SocialProviders.module.scss index 26605606..04ffa279 100644 --- a/src/components/Nav/AuthModal/SocialProviders.module.scss +++ b/src/components/Nav/AuthModal/SocialProviders.module.scss @@ -38,12 +38,14 @@ a { border: none !important; } + .facebook, .google, .vk, .telegram { border: none; } + .github:hover { img { filter: invert(1); diff --git a/src/components/Nav/SearchModal/SearchModal.module.scss b/src/components/Nav/SearchModal/SearchModal.module.scss index 8fb9acc5..0f996e24 100644 --- a/src/components/Nav/SearchModal/SearchModal.module.scss +++ b/src/components/Nav/SearchModal/SearchModal.module.scss @@ -1,4 +1,4 @@ -@mixin searchFilterControl { +@mixin search-filter-control { background: rgb(64 64 64 / 50%); border-radius: 10rem; color: #fff; @@ -69,7 +69,7 @@ } .topTopic { - @include searchFilterControl; + @include search-filter-control; } .filterSwitcher { @@ -99,5 +99,5 @@ } .filterResultsControl { - @include searchFilterControl; + @include search-filter-control; } diff --git a/src/components/_shared/Lightbox/Lightbox.module.scss b/src/components/_shared/Lightbox/Lightbox.module.scss index fe78452e..cf1ab04f 100644 --- a/src/components/_shared/Lightbox/Lightbox.module.scss +++ b/src/components/_shared/Lightbox/Lightbox.module.scss @@ -93,12 +93,10 @@ align-items: center; justify-content: center; z-index: 10001; - font-size: 1.2rem; border-radius: 6px; background-color: rgb(0 0 0 / 80%); color: #fff; - pointer-events: none; } diff --git a/src/components/_shared/SolidSwiper/Swiper.module.scss b/src/components/_shared/SolidSwiper/Swiper.module.scss index 3e9cdf82..b8e5b990 100644 --- a/src/components/_shared/SolidSwiper/Swiper.module.scss +++ b/src/components/_shared/SolidSwiper/Swiper.module.scss @@ -52,7 +52,7 @@ } .thumbs { - //overflow: hidden; + // overflow: hidden; box-sizing: border-box; margin: 0; position: relative; @@ -87,6 +87,7 @@ &.mobileView { .container { padding: 0; + .thumbs { & swiper-slide { // bind to html element @@ -228,7 +229,7 @@ margin-top: 24px; * { - color: var(--default-color-invert) !important; //Force fix migration errors with inline styles + color: var(--default-color-invert) !important; // Force fix migration errors with inline styles } @include media-breakpoint-up(md) { diff --git a/src/components/_shared/TimeAgo/TimeAgo.tsx b/src/components/_shared/TimeAgo/TimeAgo.tsx index 20177335..055b8e39 100644 --- a/src/components/_shared/TimeAgo/TimeAgo.tsx +++ b/src/components/_shared/TimeAgo/TimeAgo.tsx @@ -6,7 +6,7 @@ import { useLocalize } from '../../../context/localize' import styles from './TimeAgo.module.scss' type Props = { - date: any + date: string | number | Date class?: string } diff --git a/src/context/connect.tsx b/src/context/connect.tsx index 5999cd9d..fea126d5 100644 --- a/src/context/connect.tsx +++ b/src/context/connect.tsx @@ -11,7 +11,8 @@ export interface SSEMessage { id: string entity: string // follower | shout | reaction action: string // create | delete | update | join | follow | seen - payload: any // Author | Shout | Reaction | Message + // eslint-disable-next-line @typescript-eslint/no-explicit-any + payload: any // Author Shout Message Reaction Chat created_at?: number // unixtime x1000 seen?: boolean } diff --git a/src/context/reactions.tsx b/src/context/reactions.tsx index 226c408f..5011fd9a 100644 --- a/src/context/reactions.tsx +++ b/src/context/reactions.tsx @@ -43,10 +43,13 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => { offset?: number }): Promise => { const reactions = await apiClient.getReactionsBy({ by, limit, offset }) - const newReactionEntities = reactions.reduce((acc, reaction) => { - acc[reaction.id] = reaction - return acc - }, {}) + const newReactionEntities = reactions.reduce( + (acc: { [reaction_id: number]: Reaction }, reaction: Reaction) => { + acc[reaction.id] = reaction + return acc + }, + {}, + ) setReactionEntities(newReactionEntities) return reactions } @@ -79,9 +82,9 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => { } const deleteReaction = async (reaction_id: number): Promise => { - const _reaction = await apiClient.destroyReaction(reaction_id) + const r = await apiClient.destroyReaction(reaction_id) setReactionEntities({ - [reaction_id]: undefined, + [r.id]: undefined, }) } diff --git a/src/context/session.tsx b/src/context/session.tsx index 490b09ab..0b872ab4 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -83,7 +83,7 @@ const EMPTY_SUBSCRIPTIONS = { } export const SessionProvider = (props: { - onStateChangeCallback(state: any): unknown + onStateChangeCallback(state: AuthToken): unknown children: JSX.Element }) => { const { t } = useLocalize() diff --git a/src/renderer/types.ts b/src/renderer/types.ts index 7f97c7ca..4948f2a7 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -7,8 +7,7 @@ export type PageContext = PageContextBuiltInClientWithClientRouting & { Page: (pageProps: PageProps) => Component pageProps: PageProps lng: string - // FIXME typing - cookies: any + cookies: { [key: string]: string | number | undefined } | null documentProps?: { title?: string description?: string diff --git a/src/styles/app.scss b/src/styles/app.scss index 0977d95a..f3fae241 100644 --- a/src/styles/app.scss +++ b/src/styles/app.scss @@ -595,7 +595,9 @@ figure { figure { figcaption { color: rgb(0 0 0 / 60%); + @include font-size(1.2rem); + line-height: 1.5; } } diff --git a/src/utils/pageLoadManager.ts b/src/utils/pageLoadManager.ts index a25ff347..2f8a1798 100644 --- a/src/utils/pageLoadManager.ts +++ b/src/utils/pageLoadManager.ts @@ -1,10 +1,10 @@ const pageLoadManager: { - promise: Promise + promise: Promise } = { promise: Promise.resolve() } export const getPageLoadManagerPromise = () => { return pageLoadManager.promise } -export const setPageLoadManagerPromise = (promise: Promise) => { +export const setPageLoadManagerPromise = (promise: Promise) => { pageLoadManager.promise = promise }