Const DISALLOWEDMETHODS = ["Log", "info", "Warn", "Error", "dir"];module.exports={meta: {docs: {description:"Disallow Use of console", Category:"Best Practices", recommended:true}}, create (context) {return{Identifier (node) {Const Isconsolecall=lookslike (node, {name:"Console", Parent: {type:"Memberexpression", property: {name:val=Disallowedmethods.includes (val)}} }); //find the identifier with Name ' console ' if(!Isconsolecall) { return; } Context.report ({node, message: "Using {{identifier}} is not allowed", data: {identifier:node.name // con Sole } }); } }; }};functionLookslike (A, b) {return(A&&b&&Object.keys (b). Every (Bkey={Const BVal=B[bkey]; Const Aval=A[bkey]; if(typeofBVal = = = "function") { returnBVal (Aval); } returnIsprimitive (bVal)? BVal = = =aval:lookslike (Aval, BVal); }) );}functionIsprimitive (val) {returnval = =NULL|| /^[sbn]/.test (typeofval);}
We can use the placeholder for more detail information:
"Using {{identifier}} is not allowed"
The placeholder can found in data prop:
data: { // console }
[Javascript AST] 4. Continue:report ESLint Error