惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
爱范儿
爱范儿
Y
Y Combinator Blog
T
Tor Project blog
V
Visual Studio Blog
U
Unit 42
B
Blog RSS Feed
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
G
Google Developers Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
Microsoft Azure Blog
Microsoft Azure Blog
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
博客园_首页
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
P
Proofpoint News Feed
Jina AI
Jina AI
博客园 - 【当耐特】
S
Security @ Cisco Blogs
I
Intezer
MyScale Blog
MyScale Blog
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
腾讯CDC
T
Tenable Blog
A
Arctic Wolf
T
Threat Research - Cisco Blogs
S
Securelist
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
C
Check Point Blog
NISL@THU
NISL@THU
Microsoft Security Blog
Microsoft Security Blog
V
Vulnerabilities – Threatpost

Java不加糖的Blog

假设, AI 把我代替的那一刻真的到来 | szhshp 的第三边境研究所 小傻瓜都能懂的 AstrBot QQ 机器人集成 MCP 功能实战指南 | szhshp 的第三边境研究所 《智人之上: 从石器时代到 AI 时代的信息网络简史》阅读笔记 | szhshp 的第三边境研究所 iPadOS 26 无法设置空间场景图片壁纸的解决方法 | szhshp 的第三边境研究所 《一路云海》(终) | szhshp 的第三边境研究所 《一路云海》(四): 如何不按套路旅行 | szhshp 的第三边境研究所 《一路云海》(三): In Ya Mellow Tone | szhshp 的第三边境研究所 《一路云海》(二): 关西世博参观纪实 | szhshp 的第三边境研究所 《一路云海》(一): 新的征程 | szhshp 的第三边境研究所 2025 大阪世博会 [ 3 天前-先到先得 ] 阶段 场馆预约必中独家攻略 | szhshp 的第三边境研究所 Hackathon 随想 | szhshp 的第三边境研究所 一杯双皮奶 | szhshp 的第三边境研究所 Armbian + CasaOS + NAS 配置指南 | szhshp 的第三边境研究所 Docker 构建镜像报错: error getting credentials - err: exit status 1, out: `` | szhshp 的第三边境研究所 Disqus RIP! 论过高的维护成本如何治疗固执的坏习惯 | szhshp 的第三边境研究所 炸弹猫桌游变体规则 | szhshp 的第三边境研究所 《小岛经济学》阅读笔记 | szhshp 的第三边境研究所 《金钱心理学》阅读笔记 | szhshp 的第三边境研究所 为知笔记 RIP: 迁移剩余的笔记 | szhshp 的第三边境研究所 2025 博客第十年展望 - 再见我的过去 | szhshp 的第三边境研究所 我在独立游戏里面致敬的作品 | szhshp 的第三边境研究所 《How to make thing faster》阅读笔记 | szhshp 的第三边境研究所 《The Art of Clean Code》阅读笔记 | szhshp 的第三边境研究所 《Clean Architecture: A Craftsman Guide to Software Structure and Design》阅读笔记 | szhshp 的第三边境研究所 《How AI Works》阅读笔记 | szhshp 的第三边境研究所 游戏策划废案 - Project Uranus | szhshp 的第三边境研究所 游戏策划废案 - Project X | szhshp 的第三边境研究所 人生第一款独立游戏开发复盘 | szhshp 的第三边境研究所 Trap of Life | szhshp 的第三边境研究所 wireguard折腾记录 DSB in SBG 如果我用手搓了个暗物质雏形 | szhshp 的第三边境研究所 ODE常微分方程总结 《Rust Programming Language》- EX - Cheatsheet | szhshp 的第三边境研究所 新的播放器上线了 | szhshp 的第三边境研究所 Cypress - End-to-End Testing: OKTA Authentication with MFA | szhshp 的第三边境研究所 Windows分应用跳过管理员弹窗 docker配置wikijs VSC x VIM - 反正多学几个快捷键没有坏处 | szhshp 的第三边境研究所 使用socket代理解决企业微信可信ip问题 PowerShell美化 Kaggle比赛RSNA-2022骨折检测 CloudComPy库安装 Pandas的数据操作 齐次坐标系的理解 NgeNet论文理解 2023年必装的Windows软件 两小时 Docker 速成 - Getting Started | szhshp 的第三边境研究所 《The Joy of Javascript》- 5 - Data | szhshp 的第三边境研究所 《The Joy of Javascript》- 4 - Meta Programming | szhshp 的第三边境研究所 《The Joy of Javascript》- 3 - ADT(Algebraic Data Type) | szhshp 的第三边境研究所 Web-Automation Testing | szhshp 的第三边境研究所 《The Joy of Javascript》- 2 - Functor/Monad | szhshp 的第三边境研究所 《The Joy of Javascript》- 1 - Object/Function | szhshp 的第三边境研究所 EvalError: Possible side-effect in debug-evaluate | szhshp 的第三边境研究所 效率工具 & 软件推荐 | szhshp 的第三边境研究所 站点开源 Project Titan | szhshp 的第三边境研究所 cmd/powershell-命令速查-Cheatsheet | szhshp 的第三边境研究所 Git-命令速查与相关问题解决-Cheatsheet & Troubleshooting | szhshp 的第三边境研究所 Tailwind.css not included in NextJS Production | szhshp 的第三边境研究所 Github GraphQL API - Data Integration | szhshp 的第三边境研究所 尝试 Windows Terminal + z.lua | szhshp 的第三边境研究所 StrokePlus.net - Powerful Hotkey Boost | szhshp 的第三边境研究所 优雅地 Hack 一台黑苹果 | szhshp 的第三边境研究所 一杯关东煮 | szhshp 的第三边境研究所 Gitee x PicGo 管理图床 | szhshp 的第三边境研究所 Create Your Own Redux (Typescript) | szhshp 的第三边境研究所 Getting Started: Ionic + Capacitor + React + Typescript + Android | szhshp 的第三边境研究所 GraphQL: File Upload & Troubleshooting | szhshp 的第三边境研究所 吉祥航空随心飞刷票工具循环查票工具 | szhshp 的第三边境研究所 NVM Windows Portable Installation | szhshp 的第三边境研究所 NextJS x Typescript - Integration & Troubleshooting | szhshp 的第三边境研究所 全站点升级 - Project Titan | szhshp 的第三边境研究所 AWS-EC2-常见问题解决-Troubleshooting | szhshp 的第三边境研究所 Workbox-Getting Started | szhshp 的第三边境研究所 《时间简史》阅读笔记 | szhshp 的第三边境研究所 《时间的秩序》阅读笔记 | szhshp 的第三边境研究所 ESLint-常见问题解决-Troubleshooting | szhshp 的第三边境研究所 站点索引 | szhshp 的第三边境研究所 个人知识库搭建 - Hexo 实现 Github/Coding 持续集成 | szhshp 的第三边境研究所 BMOB-常见问题解决-Troubleshooting | szhshp 的第三边境研究所 React + Typescript: 开启 HMR/Hot Loader | szhshp 的第三边境研究所 Yarn & NPM | szhshp 的第三边境研究所 ESLint: Typescript + React + TSX 集成 | szhshp 的第三边境研究所 《10101》EP15:过年 2020 | szhshp 的第三边境研究所 Cmder-Usage | szhshp 的第三边境研究所 Redux-DOM not refreshed | szhshp 的第三边境研究所 React Semantic UI-CheatSheet | szhshp 的第三边境研究所 Typescript: Getting Started | szhshp 的第三边境研究所 Flutter-Getting Started | szhshp 的第三边境研究所 Typescript: Access window object with type check | szhshp 的第三边境研究所 VSC Extension Development-Create A Code Formatter Extension | szhshp 的第三边境研究所 OneNote Extension-Main API | szhshp 的第三边境研究所 TortoiseGit Win10 Icon not showing correctly | szhshp 的第三边境研究所 Mongoose: aggregate() 方法实现聚合函数 | szhshp 的第三边境研究所 React In Depth - React 源码解析 - render() & Fiber | szhshp 的第三边境研究所 MongoDB x Mongoose: 实现类似 Join 的功能 | szhshp 的第三边境研究所 Disqus 评论框改造工程-实现 Disqus 代理的 Serverless 服务 | szhshp 的第三边境研究所 GUI, CLI, Terminal, Shell, TTY, Console, Bash | szhshp 的第三边境研究所 Jest Async Best Practise: No Nested Async | szhshp 的第三边境研究所
前端 QA 工具链指南 - husky,commitlint,commitizen,eslint,typescript,express | szhshp 的第三边境研究所
2022-04-03 · via Java不加糖的Blog

Meta

目录

Code QA 工具链配置-主要流程

  1. 其他工具配置 (Typescript, Webpack, etc)
  2. 配置 Prettier 实现快捷键格式化本地代码
    1. VSC 安装 prettier 插件
    2. 本地安装 Prettier 包
    3. 使用时通过 ctrl+shift+P 选择 Format Document with... 然后选择 Prettier
    4. 添加 Prettier 配置文件并 设定配置详细
  3. 配置 eslint 并实现 yarn lint 格式化
    1. 安装 eslint 包
    2. 使用 eslint --init 创建一套基础配置, 这里选择了 airbnb 的配置
    3. package.json 添加一个 lint 的 script
  4. 配置 commitlint
    1. 本地会新建一个配置文件 commitlint.config.js
  5. 配置 husky
    1. Husky 会新建一个 Hook, 随后可以详细设置一下所需要的 Hooks: 详细配置 husky Hooks
  6. 配置 commitizen 并设置 cz 作为工具
    1. 安装完毕之后可以使用 yarn commit 来调用 cz 以实现格式化 commit
  7. 安装 lint-staged 以配置 pre commit hook 进行检查
    1. 安装 lint-staged 并给 package.json 添加脚本
    2. Commit 的时候激活两个 Hooks:
      1. 先用 prettier 格式化: prettier --write src/**/*.{js, ts}
      2. 用 eslint 修复和检查问题: eslint src/**/*.{js, ts} --fix
  8. 添加兼容包以通过 eslint 修复 Prettier 问题
    1. eslint-config-prettier 处理冲突的规则
    2. eslint-plugin-prettier 以使用 eslint 来修复 Prettier 的问题, 并且会直接套用 .prettierrc.json 的配置
    3. eslint 配置文件 .eslintrc.json 里面不需要再设置 prettier/prettier 规则
      • 仅仅使用 prettier 自己的配置文件 .prettierrc.json 来定制 prettier 的规则
      • IDE 插件会直接读取 .prettierrc.json 文件
      • eslint 会通过上述插件将 .prettierrc.json 的配置和 prettier/prettier 规则合并并使用
      • 若维护两份不一致的规则将会出现冲突的情况, 导致 eslint --fix 和本地 Format Document 后代码不一致的情况
      • 为减少维护成本直接删除 prettier/prettier 规则, 如此就能保证两边规则一致
    4. 注意: VSC 在修改 .prettierrc.json 配置文件之后很可能需要重启 VSC 才能生效
  9. 以后使用格式化快捷键将会自动使用 eslint 修复格式问题
    1. 尝试一下运行 prettier --write src/**/*.{js, ts}eslint src/**/*.{js, ts} --fix 之后结果是否相同

配置 Prettier

项目根目录放一个 .prettierrc.json 文件:

echo {}> .prettierrc.json

里面放上一些基础配置

.prettierrc.json:

{
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "none",
  "endOfLine": "auto"
}

安装 lint-staged

这部分会进行:

  1. lint-stage 的安装和配置

https://www.npmjs.com/package/lint-staged

记得到 package.json 编辑一下 lint 的脚本:

"lint-staged": {
  "*.{ts,js}": [
    "prettier --write src/**/*.{js,ts}",
    "eslint src/**/*.{js,ts} --fix"
  ]
}

详细的配置参考: https://prettier.io/docs/en/options.html

配置 commitlint

这部分会进行:

配置 husky

这部分会进行:

  • 可以简单地将 commit-msg 的 Hook 先设置起来
  • commitizen 初始化之后应该可以看到 cz 被添加到了 package.jsonscripts

配置 commitizen 并设置 cz 作为工具

这部分会进行:

详细配置 husky Hooks

这部分会进行:

  1. husky 的安装
  2. husky 的 Hooks 的详细配置
  1. Husky 主页
  2. 安装 husky (如果 上文commitlint 的教程里面已经包含了 husky 的安装部分, 则忽略此步骤)
  3. .husky 文件夹下面添加两个文件, 没有扩展名

pre-commit:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo '#######################################'
echo '# Pre Commit Check: Lint Staged'
npx lint-staged
echo '# Finished'
echo '#######################################'

commit-msg:

#!/bin/sh

# shellcheck source=./_/husky.sh
. "$(dirname "$0")/_/husky.sh"

echo '#######################################'
echo '# Pre Commit Check: Lint Commit Message' 
npx --no-install commitlint --edit "$1"
echo '# Finished'
echo '#######################################'

Reference

Typescript Express eslint 配置

{
  "env": {
    "browser": true, 
    "es2021": true
  }, 
  /* airbnb 基础包 + 2 个 prettier 的兼容包 */
  "extends": ["airbnb-base", "plugin:prettier/recommended", "prettier"], 
  "parser": "@typescript-eslint/parser", 
  "parserOptions": {
    "ecmaVersion": 12, 
    "sourceType": "module"
  }, 
  /* prettier 也要加到 plugin */
  "plugins": ["@typescript-eslint", "prettier"], 
  "settings": {
    /* 处理 import 的 issue */
    "import/resolver": {
      "node": {
        "extensions": [".ts", ".js"]
      }
    }
  }, 
  "rules": {
    /* 不再需要这个 rule 了 */
    /* 
    "prettier/prettier": [
      2, 
      {
      }
    ], 
    */

    /* Other Rules */
  }
}

Package.json 完全配置后的脚本

{
  "name": "szhshp-qa",
  "version": "2.0.0",
  "private": true,
  "scripts": {
    "lint": "eslint . --ext .tsx,.ts --fix", /* 主要 lint 命令 */
    "lint-error": "eslint . --ext .tsx,.ts --fix --quite",
    "check": "eslint . --ext .tsx,.ts",
    "check-error": "eslint . --ext .tsx,.ts --quite",
    "format": "prettier --write **/*.{js,ts,tsx,json}",   /* 主要 prettier 命令 */
    "prepare": "husky install",
    "commit": "cz"
  },
  "dependencies": {
    /* .... */
  },
  "devDependencies": {
    /* .... */
  },
  "lint-staged": {
    /* 对于任何 staged ts,tsx,js 文件都进行 Prettier 和 eslint */
    "*.{ts,tsx,js}": ["yarn format", "yarn lint"]
  },
  "config": {
    /* 对于使用 cz 进行 commit 的必要配置文件 */
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}

Troubleshooting

hint: The '.husky/pre-commit' hook was ignored because it's not set as executable.
hint: You can disable this warning with `git config advice.ignoredHook false`.

Solution: chmod +x .husky