update, lint, prettify everything

This commit is contained in:
2021-03-11 20:17:23 +00:00
parent 7c06874642
commit 7362571b7a
20 changed files with 3152 additions and 3702 deletions

2
frontend/.eslintignore Normal file
View File

@@ -0,0 +1,2 @@
*.css
*.scss

View File

@@ -1,14 +0,0 @@
module.exports = {
plugins: ["jest", "react", "react-hooks"],
extends: [
'plugin:jest/recommended',
"plugin:react-hooks/recommended",
"plugin:react/recommended",
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
}
};

59
frontend/.eslintrc.json Normal file
View File

@@ -0,0 +1,59 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier",
"import",
"jest",
"react",
"react-hooks",
"html"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:jest/recommended",
"plugin:react-hooks/recommended",
"plugin:react/recommended"
],
"env": {
"browser": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module",
"project": "./tsconfig.json"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [
".ts",
".tsx"
]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": [
"./tsconfig.json"
]
}
}
},
"rules": {
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/unbound-method": "off",
"react/prop-types": "off"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,49 +3,52 @@
"scripts": {
"start": "parcel src/index.html",
"build": "parcel build src/index.html",
"lint": "eslint ./src/** --ext .js,.jsx,.ts,.tsx",
"lint-fix": "eslint ./src/** --ext .js,.jsx,.ts,.tsx --fix",
"test": "jest"
},
"devDependencies": {
"@types/autoprefixer": "^9.7.2",
"@types/enzyme": "^3.10.7",
"@types/enzyme": "^3.10.8",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/highlight.js": "^9.12.4",
"@types/jest": "^26.0.14",
"@types/parcel-bundler": "^1.12.1",
"@types/react": "^16.9.51",
"@types/react-dom": "^16.9.8",
"@types/react-redux": "^7.1.9",
"@types/react-router": "^5.1.8",
"@types/react-router-dom": "^5.1.6",
"@types/jest": "^26.0.20",
"@types/parcel-bundler": "^1.12.3",
"@types/react": "^16",
"@types/react-dom": "^16",
"@types/react-redux": "^7.1.16",
"@types/react-router": "^5.1.12",
"@types/react-router-dom": "^5.1.7",
"@types/sass": "^1.16.0"
},
"dependencies": {
"autoprefixer": "^9.8.6",
"@blueprintjs/core": "^3.41.0",
"@blueprintjs/icons": "^3.25.1",
"autoprefixer": "^10.2.5",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"jest": "^26.5.2",
"enzyme-adapter-react-16": "^1.15.6",
"eslint-plugin-html": "^6.1.2",
"eslint-plugin-jest": "^24.2.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"highlight.js": "^10.6.0",
"jest": "^26.6.3",
"parcel-bundler": "^1.12.4",
"postcss-modules": "^3.2.2",
"redux-devtools-extension": "^2.13.8",
"eslint-plugin-react": "^7.21.3",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-jest": "^24.1.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"sass": "^1.26.12",
"ts-jest": "^26.4.1",
"@blueprintjs/core": "^3.33.0",
"@blueprintjs/icons": "^3.22.0",
"highlight.js": "^10.4.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-markdown": "^4.3.1",
"react-redux": "^7.2.1",
"postcss-modules": "^4.0.0",
"react": "^16",
"react-dom": "^16",
"react-markdown": "^5.0.3",
"react-redux": "^7.2.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-spring": "^8.0.27",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.9",
"redux-persist": "^6.0.0",
"redux-saga": "^1.1.3"
"redux-saga": "^1.1.3",
"sass": "^1.32.8",
"ts-jest": "^26.5.3"
},
"postcss": {
"plugins": {

View File

@@ -176,7 +176,7 @@ export class DocumentEditComponent extends React.PureComponent<
public copyLink() {
const doc = this.props.allDocs[this.state.id];
navigator.clipboard.writeText(
void navigator.clipboard.writeText(
`${webRoot}/shared/${this.props.username}/${doc.id}`,
);
showSharedToast();

View File

@@ -27,7 +27,7 @@ export class DocumentViewComponent extends React.PureComponent<
null
> {
public render() {
const { id } = this.props.match.params as any;
const { id } = this.props.match.params as { id: number };
if (this.props.allDocs) {
const doc = this.props.allDocs[id];

View File

@@ -58,7 +58,7 @@ export class HomeComponent extends React.PureComponent<IHomeProps> {
];
if ((this.props.match.params as any).id && this.props.allDocs) {
const { id } = this.props.match.params as any;
const { id } = this.props.match.params as { id: number };
if (this.props.allDocs[id]) {
breadcrumbs.push({
icon: "document",

View File

@@ -6,24 +6,26 @@ import { fetchJSON, fetchJSONAuth } from "../utils";
export async function fetchRecentDocs(): Promise<
IAPIResponse<IDocumentJSON[]>
> {
return fetchJSONAuth("/docs/list/recent", "GET");
return (fetchJSONAuth("/docs/list/recent", "GET") as unknown) as Promise<
IAPIResponse<IDocumentJSON[]>
>;
}
export async function fetchAllDocs(): Promise<IAPIResponse<IDocumentJSON[]>> {
return fetchJSONAuth("/docs/list", "GET");
return (fetchJSONAuth("/docs/list", "GET") as unknown) as Promise<IAPIResponse<IDocumentJSON[]>>;
}
export async function fetchDoc(
id: number,
): Promise<IAPIResponse<IDocumentJSON>> {
return fetchJSONAuth(`/docs/byID/${id}`, "GET");
return fetchJSONAuth(`/docs/byID/${id}`, "GET") as unknown as Promise<IAPIResponse<IDocumentJSON>>;
}
export async function fetchSharedDoc(
username: string,
id: number,
): Promise<IAPIResponse<IDocumentJSON>> {
return fetchJSON(`/docs/shared/${username}/${id}`, "GET");
return fetchJSON(`/docs/shared/${username}/${id}`, "GET") as unknown as Promise<IAPIResponse<IDocumentJSON>>;
}
export async function patchDoc(
@@ -36,13 +38,13 @@ export async function patchDoc(
name,
content,
shared,
});
}) as unknown as Promise<IAPIResponse<IDocumentJSON>>;
}
export async function deleteDoc(id: number): Promise<IAPIResponse<boolean>> {
return fetchJSONAuth(`/docs/byID/${id}`, "DELETE");
return fetchJSONAuth(`/docs/byID/${id}`, "DELETE") as unknown as Promise<IAPIResponse<boolean>>;
}
export async function createNewDoc(): Promise<IAPIResponse<IDocumentJSON>> {
return fetchJSONAuth(`/docs/new`, "POST", { name: "New Document" });
return fetchJSONAuth(`/docs/new`, "POST", { name: "New Document" }) as unknown as Promise<IAPIResponse<IDocumentJSON>> ;
}

View File

@@ -17,9 +17,9 @@ export function deleteToken(_token: string) {
export async function fetchJSON(
path: string,
method: string,
body?: string | object,
body?: string | Record<string, unknown>,
headers?: Record<string, string>,
) {
): Promise<Record<string, unknown>> {
if (typeof body === "object") {
body = JSON.stringify(body);
}
@@ -31,16 +31,16 @@ export async function fetchJSON(
"Content-Type": "application/json",
},
});
const json = await response.json();
const json = (await response.json()) as Record<string, unknown>;
return json;
}
export async function fetchJSONAuth(
path: string,
method: string,
body?: string | object,
headers?: object,
) {
body?: string | Record<string, unknown>,
headers?: Record<string, unknown>,
): Promise<Record<string, unknown>> {
if (token) {
return fetchJSON(path, method, body, {
...headers,

View File

@@ -39,6 +39,7 @@ export const authReducer: Reducer<IAuthState, AuthAction> = (
if (action.payload.logout) {
return defaultAuthState;
}
break;
case AuthTypes.AUTH_FAIL:
return { ...defaultAuthState, formError: action.payload.error };
break;

View File

@@ -19,9 +19,10 @@ export const localSettingsReducer: Reducer<
action: LocalSettingsAction | UserAction,
) => {
switch (action.type) {
case LocalSettingsTypes.TOGGLE_DARK_MODE:
case LocalSettingsTypes.TOGGLE_DARK_MODE: {
const { darkMode } = state;
return { ...state, darkMode: !darkMode };
}
case UserTypes.USER_LOGOUT:
return defaultLocalSettingsState;
default: