{"_id":"@digital-rd/eslint-config-conventional","_rev":"3-ca88b802e03f2fd73b6334a55dcd52c9","name":"@digital-rd/eslint-config-conventional","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@digital-rd/eslint-config-conventional","version":"1.0.0","keywords":["eslint","standard","conventional"],"author":{"name":"lefty"},"license":"MIT","_id":"@digital-rd/eslint-config-conventional@1.0.0","maintainers":[{"name":"lefty666","email":"201305863@qq.com"}],"dist":{"shasum":"3a68c74ee1b31c5c1f9b1faef80ae0b5bfea58d0","tarball":"https://registry.npmjs.org/@digital-rd/eslint-config-conventional/-/eslint-config-conventional-1.0.0.tgz","fileCount":8,"integrity":"sha512-d5r2MGMY/BRB+DXha/XtrqS/hkwoeZ5hpyq6G0ec63wXmXqSrUD3rVep7Xvr5hkbn72BCE6jeIMZ6DXyUEaUhw==","signatures":[{"sig":"MEQCIFajm1q3++MKlv+SxG7iEnBr1wI/3SI6KuNfQIh/glDfAiAHqKvkZoKLqeNotch5JVLA4JvUWFq1WsFZj3UrqpkW+Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":74466,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJikICcACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqWGhAAhAFg1ZjVzldQKebFxXZfvBcKdbOfD+YCCDscFucOyD4iFiSK\r\nzn+kxXasNycBQuQDJCwQh36rmnKACfIiLbDDj86w4ElLF02khPGRYamKnLCZ\r\ntNODfubbLsDjvVH8o9y7bjaS5K6NVJKfXOmLOLSYFe12F+UNs95tnWkFiViK\r\nMP/oyaElGHAgoqF44xvHxhrOSbfk96ol6TB5aJPSgBhPfVlw2hQNY35xCIcn\r\nnOYj8T57OXjCnn+ONDL0sDPotxDpYbe2PrD+vgBErHF/gVBCOg37E8yh6Kdn\r\nljmuCJ/ESm+DB3iY+nvY5cF04/C/0iWvOl+ku6r1PtKJMnMa7N7IVwFilpeS\r\nYdRPvhM6CcW3Wu7KcSyMU0XjuLr3nV8HtmO4f2jGhSg4dfGVeZweAWcC2H7p\r\n/ZN2ThWSxpjZayigqYvj+1hfWs0WAvOJzVjQ9dWZAWcn7dt9XMFOIQYRFwMu\r\nmUaQ0+QVyd+m7OhM2D46A++z8RKUBSwa2NhQcsA5qZdxDlkuQR4ADG5BhLMH\r\nA/fE+srtzPTlPPIfybqJdlXFqQhnUVEIFHSO1Yl4IZi6jOA6GCYxSQTFeo7u\r\nu/FdkKF3cVjzy7tfU0djNnyyQPg+32RTMb2b5FYlyZ6jX/+cAiAa20TN6AcS\r\nUojrNM0DaChZckM9FgWmkf9GmPv4yIMIhtI=\r\n=MULq\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"544f1ee94bbfa79d2af0c584140ff64ef5f34e0f","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"lefty666","email":"201305863@qq.com"},"_npmVersion":"8.5.5","description":"eslint-config-conventional","directories":{},"_nodeVersion":"16.15.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^8.16.0","typescript":"^4.6.4","@babel/core":"^7.18.0","eslint-plugin-vue":"^9.0.1","vue-eslint-parser":"^9.0.2","@babel/eslint-parser":"^7.17.0","@typescript-eslint/parser":"^5.25.0","@typescript-eslint/eslint-plugin":"^5.25.0"},"peerDependencies":{"eslint":">= 8.12.0"},"_npmOperationalInternal":{"tmp":"tmp/eslint-config-conventional_1.0.0_1653637275784_0.24966861508539018","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@digital-rd/eslint-config-conventional","version":"1.1.0","keywords":["eslint","standard","conventional"],"author":{"name":"lefty"},"license":"MIT","_id":"@digital-rd/eslint-config-conventional@1.1.0","maintainers":[{"name":"lefty666","email":"201305863@qq.com"}],"dist":{"shasum":"f6e863643ee7ceff7f31daa4510593d43a4262e1","tarball":"https://registry.npmjs.org/@digital-rd/eslint-config-conventional/-/eslint-config-conventional-1.1.0.tgz","fileCount":9,"integrity":"sha512-QFMzrWDnOqd7j2E7S1mBE3CFL7j0CTCxQJeMw0beIyxYoq7BYDby+nOUfVYt5JftfEEZAiLJXOmxJVTP9QbOUQ==","signatures":[{"sig":"MEYCIQCWQ/+DZLJQIY5zcZkc6LCCikqy6t7cIoXqVvGRWPhyTQIhAIK2iz9+NOyaY4OKzPs8uDHM77LG2LHp8eA125wTYIbc","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":97799},"main":"index.js","gitHead":"8883b7ea270c7a628de663c7c98676390c5fbc7b","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"lefty666","email":"201305863@qq.com"},"_npmVersion":"8.19.4","description":"eslint-config-conventional","directories":{},"_nodeVersion":"16.20.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^8.16.0","typescript":"^4.6.4","@babel/core":"^7.18.0","eslint-plugin-vue":"^9.0.1","vue-eslint-parser":"^9.0.2","@babel/eslint-parser":"^7.17.0","@typescript-eslint/parser":"^5.25.0","@typescript-eslint/eslint-plugin":"^5.25.0"},"peerDependencies":{"eslint":">= 8.12.0"},"_npmOperationalInternal":{"tmp":"tmp/eslint-config-conventional_1.1.0_1732004606804_0.6093891479644871","host":"s3://npm-registry-packages"}}},"time":{"created":"2022-05-27T07:41:15.742Z","modified":"2025-05-20T08:13:16.227Z","1.0.0":"2022-05-27T07:41:16.019Z","1.1.0":"2024-11-19T08:23:26.954Z"},"author":{"name":"lefty"},"license":"MIT","keywords":["eslint","standard","conventional"],"description":"eslint-config-conventional","maintainers":[{"email":"201305863@qq.com","name":"lefty666"},{"email":"jaffshark@gmail.com","name":"frank_cheung"}],"readme":"# eslint-config-conventional\n\n一份适用于JavaScript/TypeScript/Vue项目的ESLint配置规范。\n\n\n## 快速开始\n\n根据对应的技术栈选择对应的配置：\n\n- [Base](#Base（built-in）)\n- [Vue](#vue)\n- [TypeScript](#typescript)\n- [Vue TypeScript](#vue-typescript)\n- [Vue3 TypeScript](#vue3-typescript)\n- [Prettier](#prettier)\n\n## 使用方法\n\n### 基础依赖\n\n在开始使用本配置前，请先确认以下基础依赖的版本，不同配置的依赖有所差异。\n\n- eslint >=8.12.0\n- @babel/core >= 7.18.0\n- @babel/eslint-parser >= 7.17.0\n- @typescript-eslint/eslint-plugin >= 5.25.0\n- @typescript-eslint/parser >= 5.25.0\n- eslint-plugin-vue >= 9.0.1\n- typescript >= 4.6.4\n- vue-eslint-parser >= 9.0.2\n\n### Base（built-in）\n\n适用于原生`JavaScript`项目，使用ESLint的规则，parser使用的是[@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser) ，是本规范的默认配置。\n\n#### 依赖\n\n- [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)\n- [eslint-config-conventional](https://www.npmjs.com/package/@digital-rd/eslint-config-conventional)\n\n``` bash\nyarn add -D eslint @babel/eslint-parser @digital-rd/eslint-config-conventional\n```\n\n#### 配置\n\n``` js\n// .eslintrc.js\nmodule.exports = {\n  extends: [\n    'conventional',\n  ],\n  env: {\n    // 你的环境变量（包含多个预定义的全局变量）\n    //\n    // browser: true,\n    // node: true,\n    // mocha: true,\n    // jest: true,\n    // jquery: true\n  },\n  globals: {\n    // 你的全局变量（设置为 false 表示它不允许被重新赋值）\n    //\n    // myGlobal: false\n  },\n  rules: {\n    // 自定义你的规则\n  },\n};\n```\n\n### Vue\n\n适用于 `JS` `Vue2` 的项目，继承了`Base`配置，并启用了 [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue) 插件的规则，parser使用了 [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser) 。\n\n#### 依赖\n\n- [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue) \n- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser) \n- [eslint-config-conventional](https://www.npmjs.com/package/@digital-rd/eslint-config-conventional)\n\n``` bash\nyarn add -D eslint @babel/eslint-parser vue-eslint-parser eslint-plugin-vue @digital-rd/eslint-config-conventional\n```\n\n#### 配置\n\n``` js\n// .eslintrc.js\nmodule.exports = {\n  extends: [\n    'conventional',\n    'conventional/vue'\n  ],\n  env: {\n    // 你的环境变量（包含多个预定义的全局变量）\n    //\n    // browser: true,\n    // node: true,\n    // mocha: true,\n    // jest: true,\n    // jquery: true\n  },\n  globals: {\n    // 你的全局变量（设置为 false 表示它不允许被重新赋值）\n    //\n    // myGlobal: false\n  },\n  rules: {\n    // 自定义你的规则\n  },\n};\n```\n\n### TypeScript\n\n适用于 `TypeScript` 项目，继承了`Base`配置，并启用了 [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) 插件的规则，parser使用了[@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) 。\n\n#### 依赖\n\n- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)\n- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)\n- [eslint-config-conventional](https://www.npmjs.com/package/@digital-rd/eslint-config-conventional)\n\n``` bash\nyarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin @digital-rd/eslint-config-conventional\n```\n\n#### 配置\n\n``` js\n// .eslintrc.js\nmodule.exports = {\n  extends: [\n    'conventional',\n    'conventional/typescript'\n  ],\n  env: {\n    // 你的环境变量（包含多个预定义的全局变量）\n    //\n    // browser: true,\n    // node: true,\n    // mocha: true,\n    // jest: true,\n    // jquery: true\n  },\n  globals: {\n    // 你的全局变量（设置为 false 表示它不允许被重新赋值）\n    //\n    // myGlobal: false\n  },\n  rules: {\n    // 自定义你的规则\n  },\n};\n```\n\n### Vue TypeScript\n\n适用于 `TS` `Vue2` 项目，继承了 `Base` `Vue`的配置，并启用了 [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) 插件的规则，parser使用了 [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) 。\n\n#### 依赖\n\n- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)\n- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)\n- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)\n- [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue)\n- [eslint-config-conventional](https://www.npmjs.com/package/@digital-rd/eslint-config-conventional)\n\n``` bash\nyarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-vue @digital-rd/eslint-config-conventional\n```\n\n#### 配置\n\n``` js\n// .eslintrc.js\nmodule.exports = {\n  extends: [\n    'conventional',\n    'conventional/vue',\n    'conventional/typescript'\n  ],\n  env: {\n    // 你的环境变量（包含多个预定义的全局变量）\n    //\n    // browser: true,\n    // node: true,\n    // mocha: true,\n    // jest: true,\n    // jquery: true\n  },\n  globals: {\n    // 你的全局变量（设置为 false 表示它不允许被重新赋值）\n    //\n    // myGlobal: false\n  },\n  rules: {\n    // 自定义你的规则\n  },\n};\n```\n\n### Vue3 TypeScript\n\n适用于 `TS` `Vue3` 项目，继承了 `Base` `plugin:vue3 `的配置，对于Vue3新增的规则继承插件 [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue)的vue3-recommended ，并启用了 [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) 插件的规则。parser使用了 [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) 。\n\n#### 依赖\n\n- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)\n- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)\n- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)\n- [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue)\n- [eslint-config-conventional](https://www.npmjs.com/package/@digital-rd/eslint-config-conventional)\n\n``` bash\nyarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-vue @digital-rd/eslint-config-conventional\n```\n\n#### 配置\n\n``` js\n// .eslintrc.js\nmodule.exports = {\n  extends: [\n    'conventional',\n    'conventional/vue3',\n    'conventional/typescript'\n  ],\n  env: {\n    // 你的环境变量（包含多个预定义的全局变量）\n    //\n    // browser: true,\n    // node: true,\n    // mocha: true,\n    // jest: true,\n    // jquery: true\n  },\n  globals: {\n    // 你的全局变量（设置为 false 表示它不允许被重新赋值）\n    //\n    // myGlobal: false\n  },\n  rules: {\n    // 自定义你的规则\n  },\n};\n```\n\n### Prettier\n\n> 本规范已经不包含所有样式相关的规则，故不需要引入 `eslint-config-prettier`。只需要安装 `prettier` 及相关 VSCode 插件即可。\n\n#### 依赖\n\n- eslint-config-conventional\n\n#### 配置\n\n``` js\n// .prettierrc.js\nmodule.exports = {\n  ...require('@eslint-config-conventional/prettier')\n}\n```\n\n## 常见问题\n\n### 在 VSCode 中使用\n\n在 VSCode 中，默认 ESLint 并不能识别 `.vue`、`.ts` 或 `.tsx` 文件，需要在「文件 => 首选项 => 设置」里做如下配置\n\n```\n{\n  \"eslint.validate\": [\n    \"javascript\",\n    \"javascriptreact\",\n    \"vue\",\n    \"typescript\",\n    \"typescriptreact\"\n  ]\n}\n```\n\n### 保存格式化中Eslint和Prettier的兼容\n\n在VSCode中，需要设置`Code Actions On Save`，保存文件后自动Prettier格式化后再执行Eslint的修复，这样才能获得更多的体验，打开`./vscode/settings.json`\n\n```json\n{\n  \"editor.defaultFormatter\": \"esbenp.prettier-vscode\",\n  \"eslint.validate\": [\"javascript\", \"javascriptreact\", \"vue\", \"typescript\", \"typescriptreact\"],\n  \"editor.codeActionsOnSave\": {\n    \"source.fixAll.eslint\": true\n  }\n}\n```\n\n\n### VSCode 中的 autoFixOnSave 没有效果\n\n如果需要针对 `.vue`、`.ts` 和 `.tsx` 文件开启 ESLint 的 autoFix，则需要配置成：\n\n```\n{\n  \"editor.codeActionsOnSave\": {\n    \"source.fixAll.eslint\": true\n  },\n  \"eslint.validate\": [\n    \"javascript\",\n    \"javascriptreact\",\n    {\n      \"language\": \"vue\",\n      \"autoFix\": true\n    },\n    {\n      \"language\": \"typescript\",\n      \"autoFix\": true\n    },\n    {\n      \"language\": \"typescriptreact\",\n      \"autoFix\": true\n    }\n  ]\n}\n```\n\n## 迁移指南\n\n1. 按需选择适合的配置\n2. 根据选择配置的说明文档安装对应的依赖\n3. 添加/修改项目的eslint配置文件，原则上尽量减少自定义配置\n\n``` js\n// .eslintrc.js\nmodule.exports = {\n  // 按需选择对应的配置\n  extends: [\n    'conventional',\n  ],\n  // 以下配置酌情处理\n  env: {\n    // 你的环境变量（包含多个预定义的全局变量）\n    //\n    // browser: true,\n    // node: true,\n    // mocha: true,\n    // jest: true,\n    // jquery: true\n  },\n  globals: {\n    // 你的全局变量（设置为 false 表示它不允许被重新赋值）\n    //\n    // myGlobal: false\n  },\n  rules: {\n    // 自定义你的规则\n  },\n};\n```\n\n4. 新增/修改项目的prettier配置文件\n5. 重启eslint、ts等服务\n\n## 参考\n\n- [airbnb](https://github.com/airbnb/javascript)\n- [eslint-config-alloy](https://github.com/AlloyTeam/eslint-config-alloy)\n- [eslint-config-ali](https://github.com/alibaba/f2e-spec/tree/main/packages/eslint-config-ali)\n\n\n","readmeFilename":"README.md"}