ESLint 配置
这些是ESLint的设置
它会做什么
基于当前推荐的最佳做法,此设置会提示您的 JavaScript 和 TypeScript 代码 .
兼容性
- 节点 22
- 节点 24
安装
国家预防机制
npm i -D @cruk/eslint-config
Monorepo 安装
如果您正在使用像 NX 这样的单曲工具 nx run many -t=eslint 然后您需要在根部安装 eslint 的依赖性 .
如果您正在使用像 npm 工作空间这样的单重工具 npm run eslint --ws --if-present 您需要在每个软件包中安装 eslint 依赖性
配置
创建( 或更新) a eslint.config.mjs 文件在您的 repo 根中,或者如果您在每个软件包的根中有单个 repo 。 如果您拥有一个大型的多包单体,则特别推荐,因为同时在所有包上运行的eslint可能会超过JS堆积大小限制.
示例
Kitchen switch expaple 中也包含使用一些相容性工具的更古老的配置:
import { FlatCompat } from "@eslint/eslintrc";
import tsParser from "@typescript-eslint/parser";
import path from "path";
import { fileURLToPath } from "url";
import { fixupConfigRules } from "@eslint/compat";
import { config as crukConfig } from "@cruk/eslint-config";
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
const compat = new FlatCompat({
// import.meta.dirname is available after Node.js v20.11.0
baseDirectory: import.meta.dirname,
});
const config = [
...crukConfig,
...compat.config({
extends: ["next"],
settings: {
next: {
rootDir: ".",
},
},
}),
{
languageOptions: {
parser: tsParser,
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
},
},
rules: {
"@next/next/no-img-element": "off",
},
files: ["src/**/*.ts", "src/**/*.tsx", "playwright/**/*.ts"],
ignores: [".next", ".swc", "test-results", "node_modules"],
},
];
export default fixupConfigRules(config);
你可以运行测试你的设置是否正确
npx eslint --fix-dry-run .
释放
释放前
- 请更新软件包中的版本编号. json并遵循版本编号的 semver 标准.
- 运行
nvm use确保您在正确的节点版本. - 运行
npm i以确保锁文件中的正确版本. - 更新 ChangeGELOG.md 应列出发布时的更改, 指令位于文件底部 .
- 这些更改需要合并为主.
释放
- 确定您有正确的权限 。 @ cruk org 在国家预防机制.
- 运行发行脚本
npm run release
这个应该用 release-it 允许您选择与套件 JSON 中描述的相同的版本编号,它应该照顾其余的:
- 它运行 npm ci
- 它的建设
- 它制造和推出标签
- 释放了国家防范机制
- 它请求您在 github 上记录释放,并自动生成释放笔记.
- 同意所有这些步骤 释放它走过, 当Github打开 释放点击
Publish按钮。 如果有什么不对的释放 - 它应该退后. - 当它打开 github 创建放出/tag时,使用自动生成来创建放出注释.