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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@digital-rd/eslint-config-conventional

v1.1.0

Published

eslint-config-conventional

Readme

eslint-config-conventional

一份适用于JavaScript/TypeScript/Vue项目的ESLint配置规范。

快速开始

根据对应的技术栈选择对应的配置:

使用方法

基础依赖

在开始使用本配置前,请先确认以下基础依赖的版本,不同配置的依赖有所差异。

  • eslint >=8.12.0
  • @babel/core >= 7.18.0
  • @babel/eslint-parser >= 7.17.0
  • @typescript-eslint/eslint-plugin >= 5.25.0
  • @typescript-eslint/parser >= 5.25.0
  • eslint-plugin-vue >= 9.0.1
  • typescript >= 4.6.4
  • vue-eslint-parser >= 9.0.2

Base(built-in)

适用于原生JavaScript项目,使用ESLint的规则,parser使用的是@babel/eslint-parser ,是本规范的默认配置。

依赖

yarn add -D eslint @babel/eslint-parser @digital-rd/eslint-config-conventional

配置

// .eslintrc.js
module.exports = {
  extends: [
    'conventional',
  ],
  env: {
    // 你的环境变量(包含多个预定义的全局变量)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // 你的全局变量(设置为 false 表示它不允许被重新赋值)
    //
    // myGlobal: false
  },
  rules: {
    // 自定义你的规则
  },
};

Vue

适用于 JS Vue2 的项目,继承了Base配置,并启用了 eslint-plugin-vue 插件的规则,parser使用了 vue-eslint-parser

依赖

yarn add -D eslint @babel/eslint-parser vue-eslint-parser eslint-plugin-vue @digital-rd/eslint-config-conventional

配置

// .eslintrc.js
module.exports = {
  extends: [
    'conventional',
    'conventional/vue'
  ],
  env: {
    // 你的环境变量(包含多个预定义的全局变量)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // 你的全局变量(设置为 false 表示它不允许被重新赋值)
    //
    // myGlobal: false
  },
  rules: {
    // 自定义你的规则
  },
};

TypeScript

适用于 TypeScript 项目,继承了Base配置,并启用了 @typescript-eslint/eslint-plugin 插件的规则,parser使用了@typescript-eslint/parser

依赖

yarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin @digital-rd/eslint-config-conventional

配置

// .eslintrc.js
module.exports = {
  extends: [
    'conventional',
    'conventional/typescript'
  ],
  env: {
    // 你的环境变量(包含多个预定义的全局变量)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // 你的全局变量(设置为 false 表示它不允许被重新赋值)
    //
    // myGlobal: false
  },
  rules: {
    // 自定义你的规则
  },
};

Vue TypeScript

适用于 TS Vue2 项目,继承了 Base Vue的配置,并启用了 @typescript-eslint/eslint-plugin 插件的规则,parser使用了 @typescript-eslint/parser

依赖

yarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-vue @digital-rd/eslint-config-conventional

配置

// .eslintrc.js
module.exports = {
  extends: [
    'conventional',
    'conventional/vue',
    'conventional/typescript'
  ],
  env: {
    // 你的环境变量(包含多个预定义的全局变量)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // 你的全局变量(设置为 false 表示它不允许被重新赋值)
    //
    // myGlobal: false
  },
  rules: {
    // 自定义你的规则
  },
};

Vue3 TypeScript

适用于 TS Vue3 项目,继承了 Base plugin:vue3 的配置,对于Vue3新增的规则继承插件 eslint-plugin-vue的vue3-recommended ,并启用了 @typescript-eslint/eslint-plugin 插件的规则。parser使用了 @typescript-eslint/parser

依赖

yarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-vue @digital-rd/eslint-config-conventional

配置

// .eslintrc.js
module.exports = {
  extends: [
    'conventional',
    'conventional/vue3',
    'conventional/typescript'
  ],
  env: {
    // 你的环境变量(包含多个预定义的全局变量)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // 你的全局变量(设置为 false 表示它不允许被重新赋值)
    //
    // myGlobal: false
  },
  rules: {
    // 自定义你的规则
  },
};

Prettier

本规范已经不包含所有样式相关的规则,故不需要引入 eslint-config-prettier。只需要安装 prettier 及相关 VSCode 插件即可。

依赖

  • eslint-config-conventional

配置

// .prettierrc.js
module.exports = {
  ...require('@eslint-config-conventional/prettier')
}

常见问题

在 VSCode 中使用

在 VSCode 中,默认 ESLint 并不能识别 .vue.ts.tsx 文件,需要在「文件 => 首选项 => 设置」里做如下配置

{
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "vue",
    "typescript",
    "typescriptreact"
  ]
}

保存格式化中Eslint和Prettier的兼容

在VSCode中,需要设置Code Actions On Save,保存文件后自动Prettier格式化后再执行Eslint的修复,这样才能获得更多的体验,打开./vscode/settings.json

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "eslint.validate": ["javascript", "javascriptreact", "vue", "typescript", "typescriptreact"],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

VSCode 中的 autoFixOnSave 没有效果

如果需要针对 .vue.ts.tsx 文件开启 ESLint 的 autoFix,则需要配置成:

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    },
    {
      "language": "typescript",
      "autoFix": true
    },
    {
      "language": "typescriptreact",
      "autoFix": true
    }
  ]
}

迁移指南

  1. 按需选择适合的配置
  2. 根据选择配置的说明文档安装对应的依赖
  3. 添加/修改项目的eslint配置文件,原则上尽量减少自定义配置
// .eslintrc.js
module.exports = {
  // 按需选择对应的配置
  extends: [
    'conventional',
  ],
  // 以下配置酌情处理
  env: {
    // 你的环境变量(包含多个预定义的全局变量)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // 你的全局变量(设置为 false 表示它不允许被重新赋值)
    //
    // myGlobal: false
  },
  rules: {
    // 自定义你的规则
  },
};
  1. 新增/修改项目的prettier配置文件
  2. 重启eslint、ts等服务

参考