@endo/eslint-plugin (英语)
ESLint 规则和可共享配置 硬化 Java 脚本 财务报告和审定财务报表 远藤 软件包.
安装
npm install --save-dev eslint @endo/eslint-plugin
使用量
ESLint 9+ (Flat Config) (中文(简体) )
在你身边 eslint.config.js (或 .mjs编号 :.cjs:
import endoPlugin from '@endo/eslint-plugin';
export default [
// Apply the recommended rules for Hardened JS code.
...endoPlugin.configs['flat/recommended'],
];
ESLint 8( 列克西配置)
在你身边 .eslintrc.json (或 .eslintrc.js等 :
{
"extends": ["plugin:@endo/recommended"]
}
可分享配置
recommended 编号 : flat/recommended
用于在 Hardened JavaScript (后-) 下运行的代码的核心规则lockdown()) (中文(简体) ).
// flat config
...endoPlugin.configs['flat/recommended']
// legacy
{ "extends": ["plugin:@endo/recommended"] }
中断更改( v3 ) : 这个配置不再捆绑
@jessie.js/eslint-plugin想要杰西的消费者safe-await-separator规则和规则use-jessie处理器必须安装@jessie.js/eslint-plugin并直接配置:import jessie from '@jessie.js/eslint-plugin'; import endo from '@endo/eslint-plugin'; export default [ ...endo.configs['flat/recommended'], ...jessie.configs['flat/recommended'], { processor: jessie.processors['use-jessie'] }, ];
recommended-requiring-type-checking 编号 : flat/recommended-requiring-type-checking
扩展 recommended 添加 restrict-comparison-operands 规则,它需要 TypeScript 类型信息.
// flat config
...endoPlugin.configs['flat/recommended-requiring-type-checking']
// legacy
{ "extends": ["plugin:@endo/recommended-requiring-type-checking"] }
style 编号 : flat/style
认为JS编码式的规则: @stylistic/slint-plugin (英语), (中文(简体) ), 日记,以及 更美丽。 。 。 .
...endoPlugin.configs['flat/style']
imports 编号 : flat/imports
关于软件包应如何使用导入的规则:要求文件扩展名,不允许的外相依赖性,更喜欢命名的导出.
...endoPlugin.configs['flat/imports']
strict 编号 : flat/strict
style + 键 imports + 键 recommended 在一个配置.
...endoPlugin.configs['flat/strict']
internal 编号 : flat/internal
所有软件包使用的有意见基线 在远东独行道内部扩展 strict 并添加 TypeScript-ESLint 。 无意外用.
...endoPlugin.configs['flat/internal']
ses 编号 : flat/ses
扩展 internal 严格全球可变限制以前运行的 SES 靴套代码 lockdown()。 。 。 .
...endoPlugin.configs['flat/ses']
daemon 编号 : flat/daemon (折旧)
别名 internal编号 :flat/internal。 。 。 .
规则
| 规则 | 说明 | 可修复 |
|---|---|---|
| @ endo/ sassert- fail- as- throw (英语) | 制作 assert.fail() 计为 ESLint 控制流分析中的一掷 | —— 说 |
| @ endo/ harden- 导出 | 确保每个命名的导出立即被后面 harden() | 🔧 |
| @endo/ no-assign-to-exported-let-var-or-函数 | 取消对导出方的重新安排 let编号 :var编号 :function 约束 | —— 说 |
| @ endo/ no-harden- pattern- makes (没有硬度) | 当硬化图案生成器返回值时警告( 它们已经被硬化) | —— 说 |
| @endo/no-多名-本地出口 | 拒绝以多个名称导出相同的本地绑定 | —— 说 |
| @ endo/ no- polymorphic- call( 无效) | 拒绝方法调用非本地接收对象 | —— 说 |
| @endo/retracted-comparidson-operands (英语) | 限制 <编号 :>编号 :<=编号 :>= 改为相容类型的操作 | —— 说 |
配置个别规则
// flat config
export default [
{
plugins: { '@endo': endoPlugin },
rules: {
'@endo/harden-exports': 'error',
'@endo/no-polymorphic-call': 'warn',
},
},
];
// legacy (.eslintrc.json)
{
"plugins": ["@endo"],
"rules": {
"@endo/harden-exports": "error",
"@endo/no-polymorphic-call": "warn"
}
}
兼容性
| ESLint 版本( E) | 如何使用 |
|---|---|
| 9.x (中文(简体) ) | eslint.config.js 平面配置, 使用 flat/* 配置 |
| 8.x 电话 | .eslintrc.* 常规配置, 使用空配置名称 |
插件同时传送遗产( E)recommended, (中文(简体) ), internal,)并平 (flat/recommended, (中文(简体) ), flat/internal,...)配置,这样您就可以使用您项目所需的任意ESLint版本.