Blog
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)

HiuZing

🍑
首页
文档
收藏
关于
  • 在线转换时间戳 (opens new window)
  • 在线压缩图片 (opens new window)
  • Float-Double转二进制 (opens new window)
  • 文件转Hex字符串 (opens new window)
  • Git常用命令
  • Git和SVN的区别
  • Git使用规范
  • Git提交规范
  • 代码规范
    • Prettier
      • Pre-commit Hook
  • ssh
  • Git
HiuZing
2023-05-12
目录

代码规范

# Prettier

  • 地址:Prettier 中文网 · Prettier 是一个“有态度”的代码格式化工具 (opens new window)
  • 代码格式化工具

安装

npm install --save-dev --save-exact prettier
1

创建文件

echo {}> .prettierrc.json
1

# Pre-commit Hook

代码提交之前,自动格式化

npx mrm@2 lint-staged
1

Prettier和eslint一起工作冲突

npm i eslint-config-prettier
1

加上最后一句

"eslintConfig": {
    "extends": [
        "react-app",
        "react-app/jest",
        "prettier"
    ]
},
1
2
3
4
5
6
7

安装

npm install husky --save-dev
1

在package.json

"husky": {
    "hooks": {
        "pre-commit": "npm run lint && npm run format"
    }
}
1
2
3
4
5

代码消息检查

# For Windows:
npm install --save-dev @commitlint/config-conventional @commitlint/cli

# Configure commitlint to use conventional config
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
1
2
3
4
5

将commitlint.config.js修改为

module.exports = {
  // 继承的规则
  extends: ['@commitlint/config-conventional'],
  // 定义规则类型
  rules: {
    // type 类型定义,表示 git 提交的 type 必须在以下类型范围内
    'type-enum': [
      2,
      'always',
      [
        'feat', // 新功能 feature
        'fix', // 修复 bug
        'docs', // 文档注释
        'style', // 代码格式(不影响代码运行的变动)
        'refactor', // 重构(既不增加新功能,也不是修复bug)
        'perf', // 性能优化
        'test', // 增加测试
        'chore', // 构建过程或辅助工具的变动
        'revert', // 回退
        'build' // 打包
      ]
    ],
    // subject 大小写不做校验
    'subject-case': [0]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

确保保存为 UTF-8 的编码格式,否则可能会出现错误

husky

npm install [email protected] --save-dev
1

添加hooks

// 该指令(npx --no-install commitlint --edit "$1")在commit-msg的hooks下执行
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
1
2
上次更新: 2024/08/14, 04:14:33
Git提交规范
ssh

← Git提交规范 ssh→

最近更新
01
React Native 使用SVG
08-13
02
Docker基础命令
08-04
03
算数逻辑单元
07-30
更多文章>
Theme by Vdoing | Copyright © 2021-2024 WeiXiaojing | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式