From 46380b9ec3117efb4f11d6271f05d29918aab315 Mon Sep 17 00:00:00 2001 From: Arman Hashemi Date: Wed, 10 Aug 2022 10:46:07 +0430 Subject: [PATCH] chore: install and configure eslint, prettier and husky --- .eslintignore | 3 + .eslintrc.json | 23 + .husky/pre-commit | 4 + .lintstagedrc.json | 4 + .prettierignore | 3 + .prettierrc.json | 10 + package.json | 11 +- postcss.config.js | 2 +- src/editor/RichTextEditor.tsx | 6 +- src/editor/TitleEditor.tsx | 1 + src/editor/Toolbar.tsx | 20 +- src/editor/extensions/CodeBlock.tsx | 1 + src/editor/extensions/Figure.tsx | 4 +- src/editor/extensions/TextDirection.tsx | 2 +- src/main.tsx | 2 +- src/stores/useEditorStore.ts | 10 +- yarn.lock | 1101 ++++++++++++++++++++++- 17 files changed, 1178 insertions(+), 29 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.json create mode 100755 .husky/pre-commit create mode 100644 .lintstagedrc.json create mode 100644 .prettierignore create mode 100644 .prettierrc.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..939e822 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules/ +build/ +dist/ diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..a9a2250 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json.schemastore.org/eslintrc", + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, + "plugins": ["@typescript-eslint"], + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking", + "plugin:@typescript-eslint/strict", + "prettier" + ], + "env": { + "node": true, + "es6": true + }, + "rules": { + "@typescript-eslint/no-unsafe-assignment": "off" + }, + "ignorePatterns": ["node_modules/", "build/", "dist/"] +} diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..f0f0b10 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +yarn run lint:staged diff --git a/.lintstagedrc.json b/.lintstagedrc.json new file mode 100644 index 0000000..e6f8f54 --- /dev/null +++ b/.lintstagedrc.json @@ -0,0 +1,4 @@ +{ + "src/**/*.{ts,tsx}": ["prettier --write", "eslint --fix"], + "*.{json}": ["prettier --write"] +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..6dad811 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +node_modules +build/ +dist/ diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..aa89c11 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/prettierrc", + "arrowParens": "always", + "printWidth": 80, + "singleQuote": false, + "jsxSingleQuote": false, + "semi": true, + "trailingComma": "all", + "tabWidth": 2 +} diff --git a/package.json b/package.json index 7f8cb01..490a628 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", - "preview": "vite preview" + "preview": "vite preview", + "lint:staged": "lint-staged", + "prepare": "husky install" }, "dependencies": { "@radix-ui/react-popover": "^1.0.0", @@ -39,10 +41,17 @@ "@types/lodash.debounce": "^4.0.7", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", + "@typescript-eslint/eslint-plugin": "^5.33.0", + "@typescript-eslint/parser": "^5.33.0", "@vitejs/plugin-react": "^1.3.0", "autoprefixer": "^10.4.7", + "eslint": "^8.21.0", + "eslint-config-prettier": "^8.5.0", + "husky": "^8.0.0", + "lint-staged": "^13.0.3", "postcss": "^8.4.14", "postcss-import": "^14.1.0", + "prettier": "^2.7.1", "tailwindcss": "^3.1.6", "typescript": "^4.6.3", "vite": "^2.9.9", diff --git a/postcss.config.js b/postcss.config.js index fa35cd6..a5a6ff8 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,6 +1,6 @@ module.exports = { plugins: { - 'postcss-import': {}, + "postcss-import": {}, tailwindcss: {}, autoprefixer: {}, }, diff --git a/src/editor/RichTextEditor.tsx b/src/editor/RichTextEditor.tsx index 3676304..c08d777 100644 --- a/src/editor/RichTextEditor.tsx +++ b/src/editor/RichTextEditor.tsx @@ -44,10 +44,11 @@ const BubbleMenu = ({ editor }: { editor: Editor }) => { + {/* eslint-disable-next-line */} {editor.getAttributes("link").href?.substring(0, 15) + "..."} @@ -108,11 +109,12 @@ export const RichTextEditor = () => { "mt-6 mx-auto px-1 sm:px-2 pb-4", "prose prose-sm sm:prose-base md:prose-md prose-stone", "prose-img:mb-2 prose-img:rounded prose-figcaption:text-center", - "prose-a:text-rose-500" + "prose-a:text-rose-500", )} >
+ {/* eslint-disable-next-line */} {editor.storage.characterCount.words()} کلمه
diff --git a/src/editor/TitleEditor.tsx b/src/editor/TitleEditor.tsx index 8e78c62..401fba4 100644 --- a/src/editor/TitleEditor.tsx +++ b/src/editor/TitleEditor.tsx @@ -54,6 +54,7 @@ export const TitleEditor = () => {
{/* TODO: use farsi digits */} + {/* eslint-disable-next-line */} {editor.storage.characterCount.characters()}/{CHAR_LIMIT} کاراکتر
diff --git a/src/editor/Toolbar.tsx b/src/editor/Toolbar.tsx index 732a572..70e1fa8 100644 --- a/src/editor/Toolbar.tsx +++ b/src/editor/Toolbar.tsx @@ -41,7 +41,7 @@ const ToolbarButton = React.forwardRef( "flex items-center justify-center", "outline-none rounded font-bold border-transparent hover:border-rose-500 hover:border", "ease-in-out transition duration-200", - isActive ? "bg-rose-500" : "bg-black" + isActive ? "bg-rose-500" : "bg-black", ); return ( @@ -50,7 +50,7 @@ const ToolbarButton = React.forwardRef( {children} ); - } + }, ); interface ButtonGroupProps extends React.HTMLAttributes { @@ -119,7 +119,7 @@ const ToolbarLinkToggler = ({ editor }: { editor: Editor }) => {
setLink(e.target.value)} className="w-full py-2 pl-2 pr-14 text-sm text-black border-2 border-gray-200 rounded-lg" onKeyDown={(e) => { @@ -153,15 +153,19 @@ const ToolbarImageInput = ({ editor }: { editor: Editor }) => { } // TODO: filter file type - const file = e.target?.files[0]!; + const file = e.target.files[0]; + + if (!file) { + return; + } if (imageInputRef.current) { imageInputRef.current.value = ""; } - if (file && file.size > MAX_IMAGE_SIZE_IN_MB * 1000000) { + if (file.size > MAX_IMAGE_SIZE_IN_MB * 1000000) { toast.error( - `حجم تصاویر حداکثر میتواند ${MAX_IMAGE_SIZE_IN_MB} مگابایت باشد` + `حجم تصاویر حداکثر میتواند ${MAX_IMAGE_SIZE_IN_MB} مگابایت باشد`, ); return; @@ -172,7 +176,7 @@ const ToolbarImageInput = ({ editor }: { editor: Editor }) => { success: (result) => { const reader = new FileReader(); - reader.onload = async (e: ProgressEvent) => { + reader.onload = (e: ProgressEvent) => { if (e.target?.result) { editor .chain() @@ -208,7 +212,7 @@ const ToolbarImageInput = ({ editor }: { editor: Editor }) => { className={cn( "w-full py-2 px-4", "hidden rounded rounded-8 border focus:outline-none bg-gray-100", - "placeholder:text-right" + "placeholder:text-right", )} /> diff --git a/src/editor/extensions/CodeBlock.tsx b/src/editor/extensions/CodeBlock.tsx index d8a3555..3a50c96 100644 --- a/src/editor/extensions/CodeBlock.tsx +++ b/src/editor/extensions/CodeBlock.tsx @@ -27,6 +27,7 @@ const CodeBlockWrapper = ({ updateAttributes, extension }: NodeViewProps) => { onChange={(event) => updateAttributes({ language: event.target.value })} > + {/* eslint-disable-next-line */} {extension.options.lowlight .listLanguages() .map((lang: string, index: number) => ( diff --git a/src/editor/extensions/Figure.tsx b/src/editor/extensions/Figure.tsx index ae08e22..dae4737 100644 --- a/src/editor/extensions/Figure.tsx +++ b/src/editor/extensions/Figure.tsx @@ -176,7 +176,7 @@ const FigureWrapper = ({ node, deleteNode }: NodeViewProps) => { return (
- {node.attrs.src && Image} + {node.attrs.src && Image} {/* TODO: sync alt with caption */}