feat: 添加 ESLint 和 Prettier 配置,集成自动格式化工作流

This commit is contained in:
2025-12-19 19:37:29 +08:00
parent 6b05f7c74e
commit 618723a689
6 changed files with 261 additions and 121 deletions

80
.github/workflows/lint-format.yml vendored Normal file
View File

@@ -0,0 +1,80 @@
name: Lint and Format
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
jobs:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run ESLint
run: pnpm lint
- name: Run Prettier check
run: pnpm format:check
format:
name: Auto-format (eslint --fix)
runs-on: ubuntu-latest
needs: lint
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run Prettier --write
run: pnpm format
- name: Run ESLint --fix
run: pnpm lint:fix
- name: Commit & push fixes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet; then
git add -A
git commit -m "chore: auto format by GitHub Actions" || echo "No changes to commit"
git push
else
echo "No formatting changes"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

18
.prettierignore Normal file
View File

@@ -0,0 +1,18 @@
node_modules/
.output/
.nuxt/
dist/
build/
public/build/
.vscode/
.pnp.*
coverage/
*.log
*.lock
pnpm-lock.yaml
.env
.env.*
.DS_Store
# ignore generated images
public/images/generated/

12
.prettierrc Normal file
View File

@@ -0,0 +1,12 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css"
}

View File

@@ -1,6 +1,19 @@
// @ts-check
import withNuxt from './.nuxt/eslint.config.mjs'
import withNuxt from "./.nuxt/eslint.config.mjs";
// import simpleImportSort from "eslint-plugin-simple-import-sort";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
export default withNuxt(
// Your custom configs here
)
export default withNuxt([eslintPluginPrettierRecommended], {
files: ["src/**/*.ts", "src/**/*.vue"],
ignores: [".nuxt/", "node_modules/"],
language: "vue",
// plugins: {
// prettier: prettierPlugin,
// },
// rules: {
// "prettier/prettier": "error",
// "simple-import-sort/imports": "error",
// "simple-import-sort/exports": "error",
// },
});

View File

@@ -7,6 +7,17 @@ export default defineNuxtConfig({
srcDir: "app/",
modules: ["@nuxt/image", "@nuxt/eslint"],
// eslint: {
// config: {
// extends: ["plugin:nuxt/recommended", "prettier"],
// plugins: ["prettier"],
// rules: {
// "prettier/prettier": "error",
// },
// stylistic: true
// },
// },
// 禁用 Vue Router 的非关键警告
vue: {
compilerOptions: {

View File

@@ -8,23 +8,29 @@
"generate": "nuxt generate",
"preview": "nuxt preview",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"dependencies": {
"@giscus/vue": "^3.1.1",
"@jaseeey/vue-umami-plugin": "^1.4.0",
"@nuxt/eslint": "1.12.1",
"@nuxt/image": "2.0.0",
"eslint": "^9.39.2",
"nodemailer": "^7.0.11",
"nuxt": "^4.2.2",
"vite-tsconfig-paths": "^6.0.1"
},
"devDependencies": {
"@nuxt/eslint": "1.12.1",
"@tailwindcss/vite": "^4.1.18",
"@types/node": "^24.10.1",
"@types/nodemailer": "^7.0.4",
"@typescript-eslint/parser": "^8.50.0",
"autoprefixer": "^10.4.22",
"eslint": "^9.39.2",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"prettier": "^3.7.4",
"tailwindcss": "^4.1.18",
"typescript": "^5.9.3"
}