diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..f92efec --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,29 @@ +{ + "parser": "@typescript-eslint/parser", + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended", + "plugin:react-hooks/recommended", + "plugin:prettier/recommended" + ], + "plugins": ["react", "@typescript-eslint", "prettier"], + "env": { + "browser": true, + "node": true, + "es2021": true + }, + "settings": { + "react": { + "version": "detect" + } + }, + "rules": { + "react/react-in-jsx-scope": "off", + "react/prop-types": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], + "prettier/prettier": "error", + "@typescript-eslint/no-empty-function": "off" + } +} \ No newline at end of file diff --git a/.github/workflows/vite-react-ts-setup.yml b/.github/workflows/vite-react-ts-setup.yml new file mode 100644 index 0000000..ff95823 --- /dev/null +++ b/.github/workflows/vite-react-ts-setup.yml @@ -0,0 +1,47 @@ +name: Setup Vite React TS Project + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 'lts/*' + + - name: Install Yarn + run: npm install -g yarn + + - name: Create Vite Project + run: npx create-vite . --template react-ts + + - name: Install ESlint and Prettier + run: | + yarn add --dev eslint prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react @typescript-eslint/eslint-plugin @typescript-eslint/parser husky lint-staged + + - name: Copy ESLint and Prettier Configuration + run: | + cp .eslintrc.json .eslintrc.json + cp .prettierrc .prettierrc + cp lint-staged.config.json lint-staged.config.json + + - name: Update package.json scripts + run: | + npx json -I -f package.json -e 'this.scripts.prettier="prettier \\"src/**/*.{js,jsx,ts,tsx,css,scss,md}\\" --write"; this.scripts["format:check"]="yarn prettier -- --check"; this.scripts["format:write"]="yarn prettier -- --write"; this.scripts["types:check"]="tsc --noEmit --pretty"; this.scripts.lint="eslint --ext .js,.jsx,.ts,.tsx src --no-error-on-unmatched-pattern"; this.scripts["lint:fix"]="eslint --ext .js,.jsx,.ts,.tsx src --fix --no-error-on-unmatched-pattern"; this.scripts.fix="yarn format:write && yarn lint:fix";' + + - name: Commit and Push + run: | + git config --global user.name "JKlancer" + git config --global user.email "jasonzhuyq@outlook.com" + git add . + git commit -m "Setup project with Vite, React-TS, ESLint, and Prettier" + git push diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..4c75dc8 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,13 @@ +{ + "arrowParens": "avoid", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 80, + "quoteProps": "as-needed", + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false +} \ No newline at end of file diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 0000000..9cf3a2f --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,8 @@ +module.exports = { + '*.json': ['npm run format:check'], + '*.{ts,tsx,js,jsx}': [ + 'npm run lint', + "bash -c 'npm run types:check'", + 'npm run format:check', + ], +};