@abstracter/eslint-config 中文文档教程
eslint-config
通用环境/堆栈的通用 eslint 配置
Install
npm install --save-dev eslint @abstracter/eslint-config eslint-plugin-import eslint-plugin-node eslint-plugin-promise
Usage
Javascript
javascript 的通用配置(没有针对特定环境或stack)
eslint 配置示例:
{
"extends": "@abstracter/eslint-config/javascript"
}
此配置依赖于:
TypeScript
用 TypeScript 编写的代码的配置。
eslint 配置示例:
{
"extends": "@abstracter/eslint-config/typescript"
}
此配置需要:
确保安装:
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
Browser
预期在浏览器环境中运行的代码的配置。
eslint 配置示例:
{
"extends": ["@abstracter/eslint-config/browser"]
}
Node.js
预期在节点环境中运行的代码的配置。
eslint配置示例:
{
"extends": ["@abstracter/eslint-config/node"]
}
此配置使用eslint-plugin-node推荐配置。
JSX
用 JSX 编写的代码的配置。
eslint 配置示例:
{
"extends": ["@abstracter/eslint-config/jsx"]
}
React
使用 React 编写的代码的配置。
eslint 配置示例:
{
"extends": ["@abstracter/eslint-config/react"]
}
配置使用 eslint-plugin-react-hooks推荐配置。
确保安装:
npm install --save-dev eslint-plugin-react-hooks
Jest
使用 Jest 的代码配置。
eslint 配置示例:
{
"extends": ["@abstracter/eslint-config/jest"]
}
此配置使用 eslint-plugin-jest 推荐的配置。
TypeScript Node.js
使用 TypeScript & 的代码配置 Node.js
此配置在使用 typescript 时关闭冗余的 eslint-plugin-node 规则。
eslint 配置示例:
{
"extends": ["@abstracter/eslint-config/typescript-node"]
}
此配置需要与 TypeScript 和 Node.js 相同的依赖项。
确保安装:
npm install --save-dev eslint-plugin-jest
Mix & Match configs
使用多个配置来实现多用途配置。
使用 TypeScript、React 和 Jest:
{
"extends": [
"@abstracter/eslint-config/typescript",
"@abstracter/eslint-config/react",
"@abstracter/eslint-config/jest"
]
}
eslint-config
Common eslint configuration for common env/stacks
Install
npm install --save-dev eslint @abstracter/eslint-config eslint-plugin-import eslint-plugin-node eslint-plugin-promise
Usage
Javascript
A general config for javascript (no rules for a specific environment or stack)
eslint config example:
{
"extends": "@abstracter/eslint-config/javascript"
}
This config depends on:
TypeScript
A config for code written in TypeScript.
eslint config example:
{
"extends": "@abstracter/eslint-config/typescript"
}
This config requires:
Make sure to install:
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
Browser
A config for code expected to run in a browser environment.
eslint config example:
{
"extends": ["@abstracter/eslint-config/browser"]
}
Node.js
A config for code expected to run in a node environment.
eslint config example:
{
"extends": ["@abstracter/eslint-config/node"]
}
This config uses eslint-plugin-node recommend config.
JSX
A config for code written in JSX.
eslint config example:
{
"extends": ["@abstracter/eslint-config/jsx"]
}
React
A config for code written using React.
eslint config example:
{
"extends": ["@abstracter/eslint-config/react"]
}
The config uses eslint-plugin-react-hooks recommend config.
Make sure to install:
npm install --save-dev eslint-plugin-react-hooks
Jest
A config for code which uses Jest.
eslint config example:
{
"extends": ["@abstracter/eslint-config/jest"]
}
This config uses eslint-plugin-jest recommended config.
TypeScript Node.js
A config for code which uses TypeScript & Node.js
This config turns off redundant eslint-plugin-node rules when using typescript.
eslint config example:
{
"extends": ["@abstracter/eslint-config/typescript-node"]
}
This config requires the same dependencies as TypeScript and Node.js.
Make sure to install:
npm install --save-dev eslint-plugin-jest
Mix & Match configs
Use more than a single config to achieve a multipurpose config.
Using TypeScript, React and Jest:
{
"extends": [
"@abstracter/eslint-config/typescript",
"@abstracter/eslint-config/react",
"@abstracter/eslint-config/jest"
]
}