Skip to main content
Version: 3.6.1

📦 eslint-plugin

ESLint 是一种静态分析代码并报告问题或通过编辑器提示和命令行建议最佳实践的工具。Docusaurus 提供了 ESLint 插件来实现最佳 Docusaurus 实践。

¥ESLint is a tool that statically analyzes your code and reports problems or suggests best practices through editor hints and command line. Docusaurus provides an ESLint plugin to enforce best Docusaurus practices.

安装

¥Installation

npm install --save-dev @docusaurus/eslint-plugin

用法

¥Usage

¥Recommended config

plugin:@docusaurus/recommended 添加到 .eslintrc 配置文件的 extends 部分:

¥Add plugin:@docusaurus/recommended to the extends section of your .eslintrc configuration file:

.eslintrc
{
"extends": ["plugin:@docusaurus/recommended"]
}

这将启用 @docusaurus eslint 插件并使用 recommended 配置。请参阅下面的 支持的规则,了解这将启用的规则列表。

¥This will enable the @docusaurus eslint plugin and use the recommended config. See Supported rules below for a list of rules that this will enable.

手动配置

¥Manual config

为了更细粒度的控制,你还可以手动启用插件并直接配置你要使用的规则:

¥For more fine-grained control, you can also enable the plugin manually and configure the rules you want to use directly:

.eslintrc
{
"plugins": ["@docusaurus"],
"rules": {
"@docusaurus/string-literal-i18n-messages": "error",
"@docusaurus/no-untranslated-text": "warn"
}
}

支持的配置

¥Supported configs

  • 受到推崇的:大多数 Docusaurus 站点的推荐规则集应从中扩展。

    ¥Recommended: recommended rule set for most Docusaurus sites that should be extended from.

  • 全部:启用所有规则。这将在次要版本之间发生变化,因此如果你想避免意外的重大更改,则不应使用它。

    ¥All: all rules enabled. This will change between minor versions, so you should not use this if you want to avoid unexpected breaking changes.

支持的规则

¥Supported rules

名称描述
@docusaurus/no-untranslated-text强制 JSX 中的文本标签通过翻译调用进行换行
@docusaurus/string-literal-i18n-messages强制在纯文本标签上调用翻译 API
@docusaurus/no-html-links确保使用 @docusaurus/Link 而不是 <a> 标签
@docusaurus/prefer-docusaurus-heading确保使用 @theme/Heading 而不是标题的 <hn> 标签

✅ = 推荐

¥✅ = recommended

配置示例

¥Example configuration

这是一个配置示例:

¥Here's an example configuration:

.eslintrc.js
module.exports = {
extends: ['plugin:@docusaurus/recommended'],
rules: {
'@docusaurus/no-untranslated-text': [
'warn',
{ignoredStrings: ['·', '—', '×']},
],
},
};