我可以为同一es lint规则强制执行多个级别。例如:不同路径的错误和警告

时间:2019-05-30 21:24:17

标签: javascript eslint eslintrc eslint-plugin-compat

我希望针对特定的导入在我的代码库中强制执行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规则,一次是为了错误,一次是为了警告,但是由于它是一个对象,因此它被覆盖。

2 个答案:

答案 0 :(得分:0)

这在eslint中是不可能的。规则必须始终为warn或始终为error

答案 1 :(得分:0)

eslint-plugin-local和直接从eslint包中引用no-restricted-imports规则的小型存根规则的组合可能会为您带来帮助。

一点也不优雅,但似乎至少应该是可能

相关问题