@techteam/slint (英语)
我们使用的埃斯林特配置 爱奇
++ 版本 1. 0.0+ 需要 ESLint 9 - 看到没 移徙指南 用于升级.
安装
npm i -D eslint@^9.0.0 prettier @etchteam/eslint-config eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-storybook
使用量
创建一个 eslint.config.js 在工程根中的文件 :
import etchConfig from '@etchteam/eslint-config';
export default etchConfig;
环境特定配置
对于不需要完全配置的项目,使用特定环境的进口以减少依赖性:
下一个.js
npm i -D eslint prettier @etchteam/eslint-config eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-storybook @next/eslint-plugin-next eslint-plugin-react-hooks
import nextjs from '@etchteam/eslint-config/nextjs';
export default nextjs;
节点.js / Express
npm i -D eslint prettier @etchteam/eslint-config
import nodejs from '@etchteam/eslint-config/nodejs';
export default nodejs;
角质
npm i -D eslint prettier @etchteam/eslint-config eslint-plugin-storybook angular-eslint
import angular from '@etchteam/eslint-config/angular';
export default angular;
预录
npm i -D eslint prettier @etchteam/eslint-config eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-storybook
import preact from '@etchteam/eslint-config/preact';
export default preact;
Web 组件( 鼠标)
npm i -D eslint prettier @etchteam/eslint-config eslint-plugin-storybook eslint-plugin-lit
import webComponents from '@etchteam/eslint-config/web-components';
export default webComponents;
网点JS
npm i -D eslint prettier @etchteam/eslint-config @darraghor/eslint-plugin-nestjs-typed
import nestjs from '@etchteam/eslint-config/nestjs';
export default nestjs;
可编译配置
通过组合单个模块构建自定义配置 :
import { base, json, yaml, react } from '@etchteam/eslint-config';
export default [
...base,
...json,
...yaml,
...react,
{
// Your custom overrides
rules: {
'react/prefer-read-only-props': 'warn',
},
},
];
可用模块
| 模块 | 说明 |
|---|---|
base | 核心规则:JS、TypeScript、安全、进口、更美 |
json | JSON 文件林入 |
yaml | YAML 文件林入 |
storybook | 故事书最佳做法 |
react | React + JSX 可访问性 |
环境配置(自定义)
| 配置 | 包括 |
|---|---|
nextjs | 基础 + json + yaml + 故事本 + 反应 + Next.js 规则 |
nodejs | 基数 + json + yaml + 节点.js 全球 |
angular | 基础 + json + yaml + 故事本 + 角规则 |
preact | 基础 + json + yaml + 故事本 + 反应(预设) |
web-components | 基础 + json + yaml + 故事本 + 立特规则 |
nestjs | 基础 + json + yaml + NestJS 规则 + 顶级全球赛 |
所需同伴依赖
这个 基础, (中文(简体) ), 乔森,以及 雅姆尔 模块包含其所有插件作为软件包依赖性——不需要额外安装.
其他配置需要作为对等依赖安装额外的插件 :
| 配置 | 要安装的额外插件 |
|---|---|
默认( E)@etchteam/eslint-config(中文(简体) ) | eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-storybook |
react | eslint-plugin-react eslint-plugin-jsx-a11y |
storybook | eslint-plugin-storybook |
nextjs | eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-storybook @next/eslint-plugin-next eslint-plugin-react-hooks |
nodejs | 无 |
preact | eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-storybook |
angular | eslint-plugin-storybook angular-eslint |
web-components | eslint-plugin-storybook eslint-plugin-lit |
nestjs | @darraghor/eslint-plugin-nestjs-typed |
有了舞台
新项目
运行如下 :
npm i -D husky lint-staged
echo "module.exports = { '*.{ts,tsx,js,jsx,yml,yaml,json}': 'eslint --fix' };" > lint-staged.config.cjs
npx husky init
echo "npx --no-install -- lint-staged" > .husky/pre-commit
实施Husky和lint项目
在您的相位配置中添加以下内容:
'*.{ts,tsx,js,jsx,yml,yaml,json}': 'eslint --fix'
使用 VSCode
没有 VSCode 配置的新工程
运行如下 :
mkdir .vscode
echo "{ \"editor.formatOnSave\": false, \"editor.codeActionsOnSave\": { \"source.fixAll.eslint\": \"explicit\" } }" > .vscode/settings.json
# The VSCode prettier extension doesn't read the eslint config, so specific
# prettier overrides need to go in a prettier config for format on save
echo "export default { singleQuote: true };" > prettier.config.js
使用 VSCode 配置的探索项目
添加以下内容到 .vscode/settings.json数字 :
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
运行如下 :
# The VSCode prettier extension doesn't read the eslint config, so specific
# prettier overrides need to go in a prettier config for format on save
echo "export default { singleQuote: true };" > prettier.config.js
从ESLint 8 移动
如果你正在升级 从ESLint 8,遵循这些步骤:
1. 更新的附属关系
npm install eslint@^9.0.0 @etchteam/eslint-config@^1.0.0
2. 替换配置
移除旧的 .eslintrc.* 文件并创建新文件 eslint.config.js数字 :
import etchConfig from '@etchteam/eslint-config';
export default etchConfig;
3. 更新脚本(如有需要)
ESLint 9默认使用平面配置,因此您现有的npm脚本应该不作修改地工作.
变了什么
- 平面配置格式 - 更明确、更能发挥作用
- ESLint 9 兼容性 - 最新特点和修正
- 更新的插件 - 更新到最新版本的所有插件
- 模块配置 - 仅导入您需要的环境