Red*_*dro 5 node.js eslint gulp
我有一个node.js项目,根据.eslintrc使用gulp和中指定的规则检查自己的代码一致性gulp-eslint.
现在,我想让它在遇到某个时候抛出自定义弃用警告require:
const someModule = require('myDeprecatedModule');
// Warning: myDeprecatedModule is deprecated. Use myNewModule in stead.
Run Code Online (Sandbox Code Playgroud)
这有可能以一种简单的方式被IDE取出吗?
.eslintnpmnode_modules该规则no-restricted-modules正是这样做的:它不允许需要某些模块。
已弃用模块的名称必须在配置中进行编码。因此,为了禁止已弃用的内容,myDeprecatedModule您可以将此设置添加到该"rules"部分下的 .eslintrc 文件中。
"no-restricted-modules": ["error", "myDeprecatedModule"]
Run Code Online (Sandbox Code Playgroud)
但我认为无法自定义错误消息。这可以通过自定义插件实现。