为lodash和lodash/fp自定义eslint no-restricted-imports &



我正在尝试定义一个应该从fp导入的某些lodash方法列表。此外,我试图禁止从lodash的顶层导入。应该禁止从lodash.

目标如下:

import _ from 'lodash'; // should show message "Import [module] from lodash/[module] instead"
import { isEqual } from 'lodash'; // should show message "Import [module] from lodash/[module] instead"
import isEmpty from 'lodash/isEqual'; // should pass
import set from 'lodash/set'; // should show message "Import [module] from lodash/fp/[module] instead"

eslintrc.json

"no-restricted-imports": [
"error",
{
"patterns": [
{
"group": ["lodash/set"],
"message": "Import [module] from lodash/fp/[module] instead"
},
{
"group": ["lodash", "!lodash/*"],
"message": "Import [module] from lodash/[module] instead"
}
]
}
],

这些是我一直在使用的标志/模式。我试过打开和关闭负匹配器,并切换组数组字符串和组本身的顺序。无法获得所需的eslint错误。

这个怎么样?

"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "lodash",
"message": "Import [module] from lodash/[module] instead"
}
],
"patterns": [
{
"group": ["lodash/set"],
"message": "Import [module] from lodash/fp/[module] instead"
}
]
}
],

相关内容

  • 没有找到相关文章