@aval-adr / eslint-config
ESLint平面配置用于筛选器匹配的确定代码规则(ADR-0044)
完全正确。版本控制 adr-lint 板条箱。
import { adrLint, adrLintTyped } from "@aval-adr/eslint-config";
export default [
...adrLint({
restrictedImports: [
{ files: ["src/domain/**"], paths: ["fs"], patterns: [{ group: ["@mui/*"] }] },
],
}),
];
adrLint({ restrictedImports = [] })返回配置数组。每个条目是{ files?, paths?, patterns? };相同的条目files(缺席=全部 文件)被连接到一个@typescript-eslint/no-restricted-imports选项,因为平面配置只保留规则的最后一个选项。没有条目, 没有这样的东西。adrLintTyped(options)是adrLint(options)加上类型化规则switch-exhaustiveness-check和parserOptions.projectService: true;它 需要一个tsconfig.json.adrLint单独不设置类型化规则和parserOptions。
规则和各自执行的决定规则
| 规则 | 决定规则 |
|---|---|
linterOptions.reportUnusedDisableDirectives: "error" | general.no-disabled-safety |
@typescript-eslint/ban-ts-comment (ts-expect-error: allow-with-description, ts-ignore, ts-nocheck 禁止) | general.no-disabled-safety |
@eslint-community/eslint-comments/no-unlimited-disable, require-description, disable-enable-pair | general.no-disabled-safety |
adr-lint/no-swallowed-catch | errors.never-swallowed |
@typescript-eslint/no-restricted-imports (从 restrictedImports) | architecture.dependency-rule, domain.independent-of-infrastructure |
@typescript-eslint/switch-exhaustiveness-check (输入) | types.exhaustive-matching |
缩小了,为什么?
- errors.never-swallowed: ESLint的
no-empty标记每个空块,和 也catch {} // why,这是规则主体允许的。adr-lint/no-swallowed-catch只报告一个catch在子句中没有任何语句和注释 (catch (e) /* why */ {}包括)或在其右大括号行上。 - general.no-disabled-safety:
require-description只问一个理由 压制指令;eslint-enable,global(s),exported和eslint-env什么都不压抑,什么都不需要。
switch-exhaustiveness-check 保留其股票期权,这是规则主体:
一宗失踪案件即使在沉默的背后也有人报案 default,和一个完整的开关
谁的 default 分配给 never 传球。
递延
- components.acyclic-dependencies:
import/no-cycle是延迟的。它需要eslint-plugin-import-x每个消费者都有一个TS解析器,以及它的lint 时间是无法衡量的。
依赖关系
@eslint-community/eslint-plugin-eslint-comments的家 disable-directive规则;拥有它们意味着解析指令注释 我们自己。它没有构建脚本,也没有运行时依赖项escape-string-regexp和ignore;如果被抛弃,三条规则就会进入adr-lint/在这里。eslint和typescript-eslint是消费者已经拥有的对等依赖项。