分享一些有用的 ESlint 规则
小于 1 分钟
禁止全局变量
防止在你的项目由同名的类型和全局变量冲突,例如 Node
"no-restricted-globals": ["error", "Node"]
禁止导入
防止导入一些禁止使用的库
"@typescript-eslint/no-restricted-imports": ["error",
{
// 禁止使用 NodeJs 模块
"paths": ["assert","buffer","child_process","cluster","crypto","dgram","dns","domain","events","freelist","fs","http","https","module","net","os","path","punycode","querystring","readline","repl","smalloc","stream","string_decoder","sys","timers","tls","tracing","tty","url","util","vm","zlib"]
}
],
自动删除未使用的导入
依赖包
- eslint-plugin-unused-imports
配置
"plugins": ["unused-imports"],
"rules": {
"unused-imports/no-unused-imports": "error",
}