如何编写一个自定义的 eslint 规则?
准备
正文
开始编写 eslint 插件
编写规则
module.exports = {
create: function(context) {
// declare the state of the rule
return {
ReturnStatement: function(node) {
// at a ReturnStatement node while going down
},
// at a function expression node while going up:
"FunctionExpression:exit": checkLASTSegment,
"ArrowFunctionExpression:exit": checkLASTSegment,
onCodePathStart: function (codePath, node) {
// at the start of analyzing a code path
},
onCodePathEnd: function(codePath, node) {
// at the end of analyzing a code path
}
};
}
};使用规则
参考内容
Last updated