跳到主要内容
版本:3.0.0-rc.1

📦 eslint-plugin

ESLint is a tool that statically analyzes your code and reports problems or suggests best practices through editor hints and command line. Docusaurus 提供了一个 ESLint 插件来推广 Docusaurus 相关的最佳做法。

安装流程

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

用法

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

.eslintrc
{
"extends": ["plugin:@docusaurus/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

  • Recommended: 推荐大多数 Docusaurus 站点使用的规则,建议继承。
  • All: all rules enabled. 这个配置的内容会在次要版本之间发生变化,所以如果你想避免不必要的破坏性变更,就不应使用这个配置。

Supported rules

参数描述
@docusaurus/no-untranslated-text确保 JSX 中的所有文本标签都被翻译 API 包裹。
@docusaurus/string-literal-i18n-messages确保翻译 API 只用于纯文本标签。
@docusaurus/no-html-linksEnsures @docusaurus/Link is used instead of <a> tags
@docusaurus/prefer-docusaurus-headingEnsures @theme/Heading is used instead of <hn> tags for headings

✅ = recommended

示例配置

这是一个示例配置:

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