feat: configure prettier and eslint and format the code

This commit is contained in:
Guoqi Sun 2024-11-26 20:15:33 +08:00
parent 1ecd6217a6
commit fd94ca8604
12 changed files with 1797 additions and 30 deletions

2
.eslintignore Normal file
View file

@ -0,0 +1,2 @@
# tailwind
tailwind.config.ts

6
.prettierignore Normal file
View file

@ -0,0 +1,6 @@
# lockfiles
package-lock.json
pnpm-lock.yaml
# dependencies
node_modules

16
.prettierrc.mjs Normal file
View file

@ -0,0 +1,16 @@
/** @type {import("prettier").Config} */
export default {
semi: false,
singleQuote: false,
trailingComma: "all",
endOfLine: "lf",
plugins: ["prettier-plugin-astro", "prettier-plugin-tailwindcss"],
overrides: [
{
files: "*.astro",
options: {
parser: "astro",
},
},
],
}

6
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "always"
}
}

View file

@ -1,12 +1,12 @@
// @ts-check // @ts-check
// @ts-check // @ts-check
import { defineConfig } from "astro/config"; import { defineConfig } from "astro/config"
import react from "@astrojs/react"; import react from "@astrojs/react"
import tailwind from "@astrojs/tailwind"; import tailwind from "@astrojs/tailwind"
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
integrations: [react(), tailwind()], integrations: [react(), tailwind()],
}); })

41
eslint.config.cjs Normal file
View file

@ -0,0 +1,41 @@
const eslintPluginAstro = require("eslint-plugin-astro")
module.exports = [
// add more generic rule sets here, such as:
// js.configs.recommended,
...eslintPluginAstro.configs["flat/recommended"], // In CommonJS, the `flat/` prefix is required.
{
rules: {
// override/add rules settings here, such as:
// "astro/no-set-html-directive": "error"
// JavaScript rules
"prefer-const": "error",
// TypeScript rules
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/consistent-type-imports": [
"warn",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
},
],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: {
attributes: false,
},
},
],
// React rules
"react/self-closing-comp": ["error"],
},
},
]

View file

@ -6,7 +6,8 @@
"dev": "astro dev", "dev": "astro dev",
"build": "astro check && astro build", "build": "astro check && astro build",
"preview": "astro preview", "preview": "astro preview",
"astro": "astro" "astro": "astro",
"format": "prettier --write ."
}, },
"dependencies": { "dependencies": {
"@astrojs/check": "^0.9.4", "@astrojs/check": "^0.9.4",
@ -19,5 +20,14 @@
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
"tailwindcss": "^3.4.15", "tailwindcss": "^3.4.15",
"typescript": "^5.7.2" "typescript": "^5.7.2"
},
"devDependencies": {
"@typescript-eslint/parser": "^8.16.0",
"eslint": "^9.15.0",
"eslint-plugin-astro": "^1.3.1",
"eslint-plugin-jsx-a11y": "^6.10.2",
"prettier": "^3.4.0",
"prettier-plugin-astro": "^0.14.1",
"prettier-plugin-tailwindcss": "^0.6.9"
} }
} }

1707
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
export function Test() { export function Test() {
return ( return (
<div className="text-3xl text-blue-500">Test React and TailwindCSS</div> <div className="text-3xl text-blue-500">Test React and TailwindCSS</div>
); )
} }

View file

@ -1,6 +1,6 @@
--- ---
import Layout from "../layouts/layout.astro"; import Layout from "../layouts/layout.astro"
import { Test } from "../components/test"; import { Test } from "../components/test"
--- ---
<Layout> <Layout>

View file

@ -1,8 +1,8 @@
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
export default { export default {
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
theme: { theme: {
extend: {}, extend: {},
}, },
plugins: [], plugins: [],
} }

View file

@ -1,12 +1,7 @@
{ {
"extends": "astro/tsconfigs/strict", "extends": "astro/tsconfigs/strict",
"include": [ "include": [".astro/types.d.ts", "**/*", "eslint.config.cjs"],
".astro/types.d.ts", "exclude": ["dist"],
"**/*"
],
"exclude": [
"dist"
],
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx",
"jsxImportSource": "react", "jsxImportSource": "react",
@ -16,5 +11,5 @@
"paths": { "paths": {
"~/*": ["./src/*"] "~/*": ["./src/*"]
} }
}, }
} }