@1o1w1/eslint-config-react-app 中文文档教程
eslint-config-react-app
此软件包包含 Create React App 使用的可共享 ESLint 配置。
请参阅其文档:
- Getting Started – How to create a new app.
- User Guide – How to develop apps bootstrapped with Create React App.
Usage in Create React App Projects
使用此配置的最简单方法是使用 Create React App,默认包含它.
在Create React App项目中不需要单独安装。
Usage Outside of Create React App
如果你想在一个不是用Create React App构建的项目中使用这个ESLint配置,你可以通过以下步骤安装它。
首先,安装这个包、ESLint 和必要的插件。
npm install --save-dev eslint-config-react-app babel-eslint@9.x eslint@5.x eslint-plugin-flowtype@2.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@1.5.0
然后在项目的根文件夹中创建一个名为 .eslintrc.json
的文件,其中包含以下内容:
{
"extends": "react-app"
}
就是这样! 您可以通过编辑 .eslintrc.json
文件来覆盖 eslint-config-react-app
中的设置。 在 ESLint 网站上了解有关配置 ESLint 的更多信息。
Accessibility Checks
eslint-plugin-jsx-a11y 插件的以下规则被激活:
- accessible-emoji
- alt-text
- anchor-has-content
- aria-activedescendant-has-tabindex
- aria-props
- aria-proptypes
- aria-role
- aria-unsupported-elements
- heading-has-content
- href-no-hash
- iframe-has-title
- img-redundant-alt
- no-access-key
- no-distracting-elements
- no-redundant-roles
- role-has-required-aria-props
- role-supports-aria-props
- scope
如果你想启用甚至更多可访问性规则,您可以在项目的根目录中使用以下内容创建一个 .eslintrc.json
文件:
{
"extends": ["react-app", "plugin:jsx-a11y/recommended"],
"plugins": ["jsx-a11y"]
}
但是,如果您使用的是 Create React App 并没有弹出,任何额外的规则只会显示在 IDE 集成,但不在浏览器或终端中。
eslint-config-react-app
This package includes the shareable ESLint configuration used by Create React App.
Please refer to its documentation:
- Getting Started – How to create a new app.
- User Guide – How to develop apps bootstrapped with Create React App.
Usage in Create React App Projects
The easiest way to use this configuration is with Create React App, which includes it by default.
You don’t need to install it separately in Create React App projects.
Usage Outside of Create React App
If you want to use this ESLint configuration in a project not built with Create React App, you can install it with the following steps.
First, install this package, ESLint and the necessary plugins.
npm install --save-dev eslint-config-react-app babel-eslint@9.x eslint@5.x eslint-plugin-flowtype@2.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@1.5.0
Then create a file named .eslintrc.json
with following contents in the root folder of your project:
{
"extends": "react-app"
}
That's it! You can override the settings from eslint-config-react-app
by editing the .eslintrc.json
file. Learn more about configuring ESLint on the ESLint website.
Accessibility Checks
The following rules from the eslint-plugin-jsx-a11y plugin are activated:
- accessible-emoji
- alt-text
- anchor-has-content
- aria-activedescendant-has-tabindex
- aria-props
- aria-proptypes
- aria-role
- aria-unsupported-elements
- heading-has-content
- href-no-hash
- iframe-has-title
- img-redundant-alt
- no-access-key
- no-distracting-elements
- no-redundant-roles
- role-has-required-aria-props
- role-supports-aria-props
- scope
If you want to enable even more accessibility rules, you can create an .eslintrc.json
file in the root of your project with this content:
{
"extends": ["react-app", "plugin:jsx-a11y/recommended"],
"plugins": ["jsx-a11y"]
}
However, if you are using Create React App and have not ejected, any additional rules will only be displayed in the IDE integrations, but not in the browser or the terminal.