woocommerce/packages/js/eslint-plugin/zh-cn/README.md
2026-04-15 10:18:01 +08:00

47 lines
No EOL
2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ESLint 插件
这是一个 [ESLint](https://eslint.org/) 插件,包含用于 WooCommerce 开发的配置和自定义规则。
**注意:** 此插件主要扩展了 [`@wordpress/eslint-plugin/recommended`](https://github.com/WordPress/gutenberg/tree/trunk/packages/eslint-plugin) 规则集,并且不会更改该插件公开的任何规则。作为基础,所有 WooCommerce 项目都应遵循 WordPress JavaScript 代码风格。
但是,此规则集确实实现了以下内容(这些内容与 WordPress 标准不冲突):
- 使用 typescript eslint 解析器以支持 eslint Import[参见问题](https://github.com/gajus/eslint-plugin-jsdoc/issues/604#issuecomment-653962767)
- prettier 格式化(使用 `wp-prettier`
- JavaScript 文件中依赖项的分组(外部和内部)
- 不使用 yoda 条件语句
- `parseInt` 需要 Radix 参数
## 安装
安装模块
```bash
pnpm install @woocommerce/eslint-plugin --save-dev
```
## 使用
要选择默认配置,请扩展您自己项目的 `.eslintrc.js` 文件:
```js
module.exports = {
"extends": [ "plugin:@woocommerce/eslint-plugin/recommended" ]
}
```
有关更多信息,请参阅 [ESLint 关于可共享配置的文档](http://eslint.org/docs/developer-guide/shareable-configs)。
`recommended` 预设将包含管理 ES2015+ 环境的规则,并包含来自 [`@wordpress/eslint-plugin/recommended`](https://github.com/WordPress/gutenberg/tree/trunk/packages/eslint-plugin) 项目的规则。
如果要在代码编辑器中使用 prettier需要在项目根目录创建一个 `.prettierrc.js` 文件,内容如下:
```js
module.exports = require("@wordpress/prettier-config");
```
### 规则
| 规则 | 描述 | 推荐 |
| -------------------------------------------------------------------------- | ----------------------------------------- | ----------- |
| [dependency-group](/packages/js/eslint-plugin/docs/rules/dependency-group) | 强制依赖项文档块格式化 | ✓ |