洛南网站建设黑龙江省公共资源

张小明 2026/1/13 8:55:50
洛南网站建设,黑龙江省公共资源,国内如何做国外网站的兼职项目,温州网站建设wmwl第4章#xff1a;统一的代码风格与严格的代码质量检查#xff0c;为项目安装配置ESLint和Prettier在现代前端项目中#xff0c;ESLint 与 Prettier 的工程化整合非常关键#xff0c;它决定了#xff1a;团队代码是否统一自动化格式化是否生效是否能在 VSCode Git Hooks 中…第4章统一的代码风格与严格的代码质量检查为项目安装配置ESLint和Prettier在现代前端项目中ESLint 与 Prettier 的工程化整合非常关键它决定了团队代码是否统一自动化格式化是否生效是否能在 VSCode Git Hooks 中自动检查是否能在持续集成CI中保证质量本章将带你建立一套完全现代化的代码规范体系基于ESLint 9Flat ConfigPrettier 3TypeScriptReact 19Tailwind CSSShadCN UI最终项目具备✔ 统一代码风格✔ VSCode 自动格式化✔ Git 提交自动检查✔ Tailwind class 排序✔ import 顺序优化✔ 生产工程可复用4.1 为什么需要 ESLint 与 PrettierESLint用于检查代码中潜在的错误与不规范用法例如未使用的变量React Hook 用法错误类型错误TypeScriptimport 顺序问题逻辑潜在危险代码Prettier用于格式化代码使团队代码风格统一例如换行策略引号单双尾随逗号缩进格式化JSX 排版为什么要一起使用ESLint 负责“正确性”Prettier 负责“风格格式化”。二者如果配置不当会冲突需要通过插件让它们协同工作。4.2 安装 ESLint 依赖运行pnpm add -D eslint eslint/js eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh eslint-plugin-jsx-a11y typescript-eslint/parser typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript eslint-plugin-tailwindcss typescript必要说明包名说明eslint让 ESLint 能解析 TS/TSXeslint/jsTypeScript 规则集typescript-eslinteslint-plugin-reactReact 专用规则eslint-plugin-react-hooksHook 规则非常重要eslint-plugin-react-refreshVite react-refresh 热更新规则eslint-plugin-reacteslint-plugin-importimport 语法检查eslint-plugin-tailwindcssTailwind 类名排序与错误提示4.3 安装 Prettier 及其插件pnpm add -D prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-tailwindcss说明包名功能prettier代码格式化工具eslint-plugin-prettiereslint-config-prettier关闭 ESLint 中与 Prettier 冲突的规则prettier-plugin-tailwindcssTailwind class 自动排序强烈推荐4.4 修改eslint.config.js配置文件在项目根目录找到.eslint.config.jsimport js from eslint/js import globals from globals import reactHooks from eslint-plugin-react-hooks import reactRefresh from eslint-plugin-react-refresh import tseslint from typescript-eslint import { defineConfig, globalIgnores } from eslint/config export default defineConfig([ globalIgnores([dist]), { files: [**/*.{ts,tsx}], extends: [ js.configs.recommended, tseslint.configs.recommended, reactHooks.configs.flat.recommended, reactRefresh.configs.vite, ], languageOptions: { ecmaVersion: 2020, globals: globals.browser, }, }, ])改为import js from eslint/js import globals from globals import reactHooks from eslint-plugin-react-hooks import reactRefresh from eslint-plugin-react-refresh import tseslint from typescript-eslint import pluginReact from eslint-plugin-react import jsxA11y from eslint-plugin-jsx-a11y import importPlugin from eslint-plugin-import export default [ { ignores: [dist] }, js.configs.recommended, ...tseslint.configs.recommended, { files: [**/*.{ts,tsx}], plugins: { react: pluginReact, react-hooks: reactHooks, react-refresh: reactRefresh, jsx-a11y: jsxA11y, import: importPlugin }, languageOptions: { ecmaVersion: 2020, sourceType: module, globals: globals.browser, parser: tseslint.parser, parserOptions: { project: ./tsconfig.app.json, ecmaFeatures: { jsx: true } } }, settings: { react: { version: detect }, import/resolver: { typescript: { project: ./tsconfig.app.json } } }, rules: { // React 19 不需要 React in scope react/react-in-jsx-scope: off, // React Hook 规则 react-hooks/rules-of-hooks: error, react-hooks/exhaustive-deps: warn, // TypeScript typescript-eslint/no-unused-vars: [warn, { argsIgnorePattern: ^_ }], // import 规则 import/order: [ warn, { groups: [builtin, external, internal, parent, sibling, index], alphabetize: { order: asc, caseInsensitive: true } } ] } } ]4.5 创建.prettierrc{ semi: true, singleQuote: true, printWidth: 100, tabWidth: 2, trailingComma: all, jsxSingleQuote: false, arrowParens: always }4.6 创建.prettierignoredist node_modules pnpm-lock.yaml .env* *.png *.svg4.7 配置 VS Code 自动格式化关键在.vscode/settings.json中配置{ // Editor settings editor.formatOnSave: true, editor.codeActionsOnSave: { source.fixAll: explicit, source.fixAll.eslint: explicit }, editor.defaultFormatter: esbenp.prettier-vscode, // ESLint settings eslint.enable: true, eslint.validate: [javascript, javascriptreact, typescript, typescriptreact], eslint.run: onType, eslint.workingDirectories: [{ mode: auto }] }4.8package.json 脚本lint format在package.json{ scripts: { // Lint 检查 lint: eslint \src/**/*.{ts,tsx}\, lint:fix: eslint \src/**/*.{ts,tsx}\ --fix, // Prettier 格式化 format: prettier --write \src/**/*.{ts,tsx,js,jsx,css,md,html,json}\, format:check: prettier --check \src/**/*.{ts,tsx,js,jsx,css,md,html,json}\ } }4.9 Tailwind 与 ESLint 的联动自动排序 classNames以下规则来自eslint-plugin-tailwindcsstailwindcss/classnames-order: warn,效果div classNamep-4 flex bg-red-500 text-center /会自动变成div classNameflex p-4 bg-red-500 text-center /对 ShadCN UI 组件场景尤为重要。4.10 Git 提交强制检查可选如果你的工程使用 Husky lint-staged安装pnpm add -D husky lint-staged npx husky init建立.lintstagedrc{ src/**/*.{ts,tsx}: [ eslint --fix, prettier --write ] }现在 commit 时会自动 lint 格式化。4.11 CI 检查可选用于 GitHub Actions- name: Lint run: pnpm lint - name: Prettier Check run: pnpm format:check4.12 最终文件结构新增部分. ├── .vscode/ │ └── settings.json ├── src/ ├── .lintstagedrc ├── .prettierrc ├── .prettierignore ├── .eslint.config.js ├── package.json └── ...4.12 本章总结本章构建了完整的现代化 ESLint Prettier 工程体系✔ ESLint Flat Config✔ TypeScript 全量规则✔ React 19 最佳实践✔ React Hooks / Refresh✔ Tailwind class 排序✔ import 顺序优化✔ Prettier 集成✔ VSCode 格式化✔ Git 提交检查✔ CI 流程即日起你的项目将获得统一的代码风格即时错误提示自动排版含 Tailwindimport 顺序自动规范化React Hook 误用自动警告这套体系完全适用于企业级后台大型前端团队协作现代 SPA 工程现代 React包括 Server Components
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

网站多少钱一米什么软件做网站好

还在为网关升级可能导致的业务中断而担忧吗?🚀 Higress v2版本带来了30多项重大改进,通过本文的四阶段渐进式迁移方案,你将实现平滑升级,全程保障业务连续性。作为下一代云原生网关,Higress v2在AI能力集成…

张小明 2025/12/31 16:51:29 网站建设

dw制作企业网站thinkphp 做网站如何

Cartographer SLAM建图系统:从零开始掌握实时定位与地图构建 【免费下载链接】cartographer 项目地址: https://gitcode.com/gh_mirrors/car/cartographer 想要让机器人自主导航却不知从何入手?Cartographer作为业界领先的SLAM建图系统&#xff…

张小明 2025/12/29 22:18:39 网站建设

博览局网站建设宝安网站制作哪里好

还在为3D模型的复杂拓扑结构而头疼吗?想要轻松获得高质量的四边形网格却不知从何入手?今天,我将为你详细介绍一款革命性的Blender插件——QRemeshify,它将彻底改变你对网格重构的认知,让拓扑优化变得如此简单高效&…

张小明 2026/1/6 6:57:30 网站建设

18款禁用网站app破解版app开发费用一般多少钱

在数字化学术时代,查重已成为保障学术成果原创性的标准流程。选择一款合适的在线查重软件,不仅能有效检测文本相似度,还能提供修改建议,帮助学生和研究者提升论文质量。面对市场上众多的查重工具,了解它们的特点和适用…

张小明 2026/1/8 7:19:33 网站建设

域名没备案如何建设网站代理网页浏览器

还在为暗黑3中频繁的技能按键感到手酸吗?还在因为操作失误错过最佳输出时机而懊恼吗?D3KeyHelper正是为你量身打造的游戏操作自动化神器!这款完全免费的辅助工具能够解放你的双手,让你专注于战斗策略,享受更流畅的游戏…

张小明 2025/12/30 19:49:02 网站建设

网站建设软件dwhtml个人简历代码

StyleGAN深度解析:从原理到实战的终极指南 【免费下载链接】stylegan StyleGAN - Official TensorFlow Implementation 项目地址: https://gitcode.com/gh_mirrors/st/stylegan 在当今AI生成内容爆发的时代,StyleGAN以其惊人的图像质量和灵活的控…

张小明 2026/1/4 1:52:11 网站建设