我希望在我的代码库中针对特定导入执行 no-restricted-imports
规则。
但是,我需要为某些路径抛出错误并为其他路径抛出警告。看起来我不能只做:
'no-restricted-imports': [
'warn',
{
paths: [
{
name: 'd3',
message: 'd3 would be deprecated soon, please consider moving away from it'
}
]
},
'error',
{
paths: [
{
name: 'moment',
message: 'Use of moment is not allowed',
},
]
]
实现此行为的最佳方式是什么?
我已经尝试定义 no-restricted-imports
规则两次,一次用于错误,一次用于警告,但由于它是一个对象,它被覆盖了。
最佳答案
这在 ESLint 中是不可能的。规则必须总是 warn
或总是 error
。
关于javascript - 我可以为同一个 es lint 规则执行多个级别吗?例如 : error and warning for different paths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56385819/