npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

linter-config

v1.0.2

Published

> 项目开发规范配置,包含代码规范、Git 提交规范、样式规范、流程规范

Downloads

33

Readme

Linter config

项目开发规范配置,包含代码规范、Git 提交规范、样式规范、流程规范

🔥 集成了项目开发规范相关的配置:eslint、prettier、stylelint、commitlint 等,简易、快速配置,无需安装相关依赖。

代码规范

推荐使用 AlloyTeam 的eslint-config-alloy配置规范,内置支持了 typescript/vue/react。

其设计理念:

  • 样式相关的规则交于 prettier 管理
  • eslint 负责它更擅长的代码逻辑

Prettier

在项目目录下创建.prettierrc.js

module.exports = require('linter-config/prettier.js')

Eslint

在项目目录下创建.eslintrc.js

// 内置规则
module.exports = {
  extends: ['./node_modules/linter-config/base'],
}
// Typescript
module.exports = {
  extends: ['./node_modules/linter-config/typescript'],
}
// Vue
module.exports = {
  extends: ['./node_modules/linter-config/vue'],
}
// React
module.exports = {
  extends: ['./node_modules/linter-config/react'],
}

vscode 格式化

结合 vscode 实现在保存文件时自动修复 eslint 和 prettier 错误。

通过配置 .vscode/settings.json

{
  "files.eol": "\n",
  "editor.tabSize": 2,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "eslint.validate": ["javascript", "javascriptreact", "vue", "typescript", "typescriptreact"],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

Git 提交规范

这里使用 commitlint 来规范提交信息,通过配置.commitlintrc.js

module.export = require('linter-config/commitlint')

完成了配置还不够,还需要利用husky通过git hooks来校验提交信息,在package.json中配置:

{
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -e $GIT_PARAMS"
    }
  }
}

Angular 规范

推荐使用Angular 规范,提交格式如下:

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

每次提交可以包含headerbodyfooter,并且必须包含header,提交的信息不能超过 100 字符。

header的格式包含提交类型(type)、作用用(scope)和主题(subject)。

提交类型
  • feat:增加新功能
  • fix:修复 bug
  • docs:对文档进行了修改
  • refactor:既不是修复 bug 也不是添加特征的代码重构
  • style:不影响代码运行的修改,比如空格、格式化、缺失的分号等
  • test:增加确实的测试或者矫正已存在的测试
  • chore:构建过程或辅助工具的变动
作用域

范围可以是任何指定提交更改位置的内容

主题

主题包括了对本次修改的简洁描述,有以下准则:

  • 使用命令式,现在时态:change不是changed也不是changes
  • 首字母不要大写
  • 不在末尾添加句号.
引用提交的问题

如果本次提交目的是修改 issue 的话,需要在页脚引用该 issue

以关键字ClosesFixesResolves开头,比如

Closes #234

如果修改了多个 bug,以逗号隔开

Closes #123, #245, #992

样式规范

这里使用 stylelint 来规范样式,通过配置.stylelintrc.js

module.exports = require('linter-config/stylelint')

lint-staged

使用lint-staged在每次提交 commit 信息之前自动修复stylelint错误。在package.json中配置:

{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.js": ["eslint --fix"],
    "*.[c|sc|le]ss": ["stylelint"]
  }
}