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

View File

@@ -1,36 +0,0 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "prettier", "import"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
env: {
browser: true,
node: true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": [
"./tsconfig.json",
"./frontend/tsconfig.json"
]
},
}
}
};

46
.eslintrc.json Normal file
View File

@@ -0,0 +1,46 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier",
"import"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"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"
}
}

10
.vscode/settings.json vendored
View File

@@ -1,2 +1,12 @@
{
"cSpell.words": [
"typeorm"
],
"eslint.workingDirectories": [
".",
"./frontend"
],
"search.exclude": {
"**/package-lock.json": true
}
}

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:

View File

@@ -1,6 +1,6 @@
{
"type": "mariadb",
"host": "localhost",
"host": "dbtest",
"port": 3306,
"username": "writer",
"password": "writer",

2677
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,61 +2,61 @@
"name": "writer-backend",
"devDependencies": {
"@types/bcrypt": "^3.0.0",
"@types/chai": "^4.2.13",
"@types/concurrently": "^5.2.1",
"@types/eslint": "^7.2.3",
"@types/chai": "^4.2.15",
"@types/concurrently": "^6.0.1",
"@types/eslint": "^7.2.7",
"@types/eslint-plugin-prettier": "^3.1.0",
"@types/jsonwebtoken": "^8.5.0",
"@types/koa": "^2.11.4",
"@types/koa": "^2.13.1",
"@types/koa-logger": "^3.1.1",
"@types/koa-router": "^7.4.1",
"@types/koa-send": "^4.1.2",
"@types/koa-sslify": "^4.0.1",
"@types/koa-static": "^4.0.1",
"@types/koa__cors": "^3.0.2",
"@types/lodash": "^4.14.161",
"@types/mocha": "^8.0.3",
"@types/mysql": "^2.15.15",
"@types/node": "^14.11.5",
"@types/prettier": "^2.1.1",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.2.1",
"@types/mysql": "^2.15.18",
"@types/node": "^14.14.33",
"@types/prettier": "^2.2.2",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"chai": "^4.2.0",
"eslint": "^7.10.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.12.0",
"eslint-import-resolver-typescript": "^2.3.0",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"chai": "^4.3.3",
"eslint": "^7.21.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"mocha": "^8.1.3",
"prettier": "^2.1.2",
"supertest": "^5.0.0",
"ts-node-dev": "^1.0.0-pre.63"
"eslint-plugin-mocha": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.1.3",
"mocha": "^8.3.1",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-node-dev": "^1.1.6"
},
"dependencies": {
"@koa/cors": "^3.1.0",
"bcrypt": "^5.0.0",
"concurrently": "^5.3.0",
"cross-env": "^7.0.2",
"bcrypt": "^5.0.1",
"concurrently": "^6.0.0",
"cross-env": "^7.0.3",
"jsonwebtoken": "^8.5.1",
"koa": "^2.13.0",
"koa": "^2.13.1",
"koa-body": "^4.2.0",
"koa-jwt": "^4.0.0",
"koa-logger": "^3.2.1",
"koa-router": "^9.4.0",
"koa-router": "^10.0.0",
"koa-send": "^5.0.1",
"koa-sslify": "^4.0.3",
"koa-static": "^5.0.0",
"lodash": "^4.17.20",
"lodash": "^4.17.21",
"mysql": "^2.18.1",
"reflect-metadata": "^0.1.13",
"ts-node": "9.0.0",
"ts-node": "9.1.1",
"tsconfig-paths": "^3.9.0",
"typeorm": "0.2.28",
"typescript": "^4.0.3"
"typeorm": "0.2.31",
"typescript": "^4.2.3"
},
"cacheDirectories": [
"frontend/node_modules",
@@ -71,7 +71,14 @@
"frontend": "cd frontend && npm start",
"dev": "cross-env NODE_ENV=development concurrently npm:ts-node-dev npm:frontend -c 'blue,green'",
"test": "cross-env NODE_ENV=test mocha --timeout 15000 -r ts-node/register -r tsconfig-paths/register 'src/tests/**/*.ts' ",
"lint": "eslint ./src/** ./frontend/src/** --ext .js,.jsx,.ts,.tsx",
"lint": "eslint ./src/** --ext .js,.jsx,.ts,.tsx && tsc --noEmit",
"lint-fix": "eslint ./src/** --ext .js,.jsx,.ts,.tsx --fix",
"lint-frontend": "cd frontend && npm run lint",
"lint-frontend-fix": "cd frontend && npm run lint-fix",
"lint-all": "npm run lint && npm run lint-frontend",
"lint-all-fix": "npm run lint-fix && npm run lint-frontend-fix",
"prettier-check": "prettier src/**/*.ts frontend/src/**/*.ts frontend/src/**/*.tsx --check",
"prettify": "prettier src/**/*.ts frontend/src/**/*.ts frontend/src/**/*.tsx --write",
"typeorm-dev": "cross-env NODE_ENV=development ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"typeorm": "cross-env NODE_ENV=production ts-node -T -r tsconfig-paths/register ./node_modules/typeorm/cli.js"
},

View File

@@ -1,4 +0,0 @@
module.exports = {
plugins: ["mocha"],
extends: ["plugin:mocha/recommended"],
};

View File

@@ -0,0 +1,4 @@
{
"plugins": ["mocha"],
"extends": ["plugin:mocha/recommended"]
}