chore: fix linting (#544)

* fix: eslint (server)

* fix: eslint (client)

* commit package lock file

* fix linting
This commit is contained in:
Philip Okugbe 2024-12-09 14:51:31 +00:00 committed by GitHub
parent e6bf4cdd6c
commit 532001fd82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 1076 additions and 245 deletions

View File

@ -1,22 +0,0 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:@tanstack/eslint-plugin-query/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
}

View File

@ -0,0 +1,36 @@
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 pluginQuery from "@tanstack/eslint-plugin-query";
export default tseslint.config(
{ ignores: ["dist"] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ["**/*.{ts,tsx}"],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
"@tanstack/query": pluginQuery,
},
rules: {
...reactHooks.configs.recommended.rules,
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unused-vars": "off",
"react-hooks/exhaustive-deps": "off",
"@typescript-eslint/no-unused-expressions": "off",
"no-useless-escape": "off",
},
},
);

View File

@ -5,8 +5,9 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"lint": "eslint .",
"preview": "vite preview",
"format": "prettier --write \"src/**/*.tsx\" \"src/**/*.ts\""
},
"dependencies": {
"@casl/ability": "^6.7.2",
@ -49,25 +50,27 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.61.4",
"@eslint/js": "^9.16.0",
"@tanstack/eslint-plugin-query": "^5.62.1",
"@types/file-saver": "^2.0.7",
"@types/js-cookie": "^3.0.6",
"@types/katex": "^0.16.7",
"@types/node": "22.10.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.15.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.13.0",
"optics-ts": "^2.4.1",
"postcss": "^8.4.49",
"postcss-preset-mantine": "^1.17.0",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.4.1",
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0",
"vite": "^6.0.0"
}
}

View File

@ -25,7 +25,6 @@ export function useCommentsQuery(
params: ICommentParams,
): UseQueryResult<IPagination<IComment>, Error> {
return useQuery({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: RQ_KEY(params.pageId),
queryFn: () => getPageComments(params),
enabled: !!params.pageId,

View File

@ -40,7 +40,7 @@ export default function DrawioView(props: NodeViewProps) {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => {
let base64data = (reader.result || '') as string;
const base64data = (reader.result || '') as string;
setInitialXML(base64data);
};
}

View File

@ -456,7 +456,7 @@ export const getSuggestionItems = ({
const fuzzyMatch = (query: string, target: string) => {
let queryIndex = 0;
target = target.toLowerCase();
for (let char of target) {
for (const char of target) {
if (query[queryIndex] === char) queryIndex++;
if (queryIndex === query.length) return true;
}

View File

@ -24,7 +24,7 @@ export default function SpaceSettingsModal({
const {data: space, isLoading} = useSpaceQuery(spaceId);
const spaceRules = space?.membership?.permissions;
const spaceAbility = useMemo(() => useSpaceAbility(spaceRules), [spaceRules]);
const spaceAbility = useSpaceAbility(spaceRules);
return (
<>

View File

@ -47,7 +47,7 @@ export function SpaceSidebar() {
const { data: space, isLoading, isError } = useGetSpaceBySlugQuery(spaceSlug);
const spaceRules = space?.membership?.permissions;
const spaceAbility = useMemo(() => useSpaceAbility(spaceRules), [spaceRules]);
const spaceAbility = useSpaceAbility(spaceRules);
if (!space) {
return <></>;

View File

@ -141,7 +141,6 @@ export function useGetInvitationQuery(
invitationId: string,
): UseQueryResult<any, Error> {
return useQuery({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: ["invitations", invitationId],
queryFn: () => getInvitationById({ invitationId }),
enabled: !!invitationId,

View File

@ -23,7 +23,7 @@ export default function Page() {
const { data: space } = useGetSpaceBySlugQuery(page?.space?.slug);
const spaceRules = space?.membership?.permissions;
const spaceAbility = useMemo(() => useSpaceAbility(spaceRules), [spaceRules]);
const spaceAbility = useSpaceAbility(spaceRules);
if (isLoading) {
return <></>;

View File

@ -1,25 +0,0 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};

View File

@ -0,0 +1,34 @@
import js from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import eslintConfigPrettier from 'eslint-config-prettier';
/** @type {import('eslint').Linter.Config[]} */
export default [
js.configs.recommended,
...tseslint.configs.recommended,
eslintConfigPrettier,
{
ignores: ['eslint.config.mjs'],
},
{
languageOptions: {
globals: { ...globals.node, ...globals.jest },
sourceType: 'module',
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'prefer-rest-params': 'off',
'no-useless-catch': 'off',
'no-useless-escape': 'off',
},
},
];

View File

@ -76,6 +76,7 @@
"ws": "^8.18.0"
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@nestjs/cli": "^10.4.8",
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.9",
@ -90,11 +91,9 @@
"@types/pg": "^8.11.10",
"@types/supertest": "^6.0.2",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.13.0",
"jest": "^29.7.0",
"kysely-codegen": "^0.17.0",
"prettier": "^3.4.1",
@ -105,7 +104,8 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.2"
"typescript": "^5.7.2",
"typescript-eslint": "^8.17.0"
},
"jest": {
"moduleFileExtensions": [

View File

@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { customAlphabet } = require('fix-esm').require('nanoid');
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';

View File

@ -52,7 +52,7 @@ export class AttachmentService {
// passing attachmentId to allow for updating diagrams
// instead of creating new files for each save
if (opts?.attachmentId) {
let existingAttachment = await this.attachmentRepo.findById(
const existingAttachment = await this.attachmentRepo.findById(
opts.attachmentId,
);
if (!existingAttachment) {

View File

@ -24,7 +24,9 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
try {
accessToken = JSON.parse(req.cookies?.authTokens)?.accessToken;
} catch {}
} catch {
throw new BadRequestException('Failed to parse access token');
}
return accessToken || this.extractTokenFromHeader(req);
},

View File

@ -5,7 +5,8 @@ import { InjectKysely } from 'nestjs-kysely';
import { KyselyDB } from '@docmost/db/types/kysely.types';
import { sql } from 'kysely';
import { PageRepo } from '@docmost/db/repos/page/page.repo';
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const tsquery = require('pg-tsquery')();
@Injectable()

View File

@ -33,13 +33,13 @@ export async function executeWithPagination<O, DB, TB extends keyof DB>(
.select((eb) => eb.ref(deferredJoinPrimaryKey).as('primaryKey'))
.execute()
// @ts-expect-error TODO: Fix the type here later
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
.then((rows) => rows.map((row) => row.primaryKey));
qb = qb
.where((eb) =>
primaryKeys.length > 0
? // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
?
eb(deferredJoinPrimaryKey, 'in', primaryKeys as any)
: eb(sql`1`, '=', 0),
)

View File

@ -42,7 +42,7 @@ export class ExportService {
content: [{ type: 'text', text: getPageTitle(page.title) }],
};
let prosemirrorJson: any = getProsemirrorContent(page.content);
const prosemirrorJson: any = getProsemirrorContent(page.content);
if (page.title) {
prosemirrorJson.content.unshift(titleNode);

View File

@ -25,7 +25,7 @@ export const mailDriverConfigProvider = {
const driver = environmentService.getMailDriver().toLocaleLowerCase();
switch (driver) {
case MailOption.SMTP:
case MailOption.SMTP: {
let auth = undefined;
if (
environmentService.getSmtpUsername() &&
@ -44,9 +44,10 @@ export const mailDriverConfigProvider = {
connectionTimeout: 30 * 1000, // 30 seconds
auth,
secure: environmentService.getSmtpSecure(),
ignoreTLS: environmentService.getSmtpIgnoreTLS()
ignoreTLS: environmentService.getSmtpIgnoreTLS(),
} as SMTPTransport.Options,
};
}
case MailOption.Postmark:
return {

View File

@ -41,7 +41,7 @@ export const storageDriverConfigProvider = {
};
case StorageOption.S3:
const s3Config = {
{ const s3Config = {
driver,
config: {
region: environmentService.getAwsS3Region(),
@ -68,7 +68,7 @@ export const storageDriverConfigProvider = {
};
}
return s3Config;
return s3Config; }
default:
throw new Error(`Unknown storage driver: ${driver}`);

1141
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff