pattern-rule
Pattern Rule: console.log(${BAR})
pattern-rule
function visit(pattern, filename, code) {
const variable = pattern.variables.get("BAR");
// If the name of the variable passed is foo, raise an error
if (variable.value === "foo") {
// build the error being reported
const error = buildError(pattern.start.line, pattern.start.col, pattern.end.line, pattern.end.col, "Do not use foo as a variable", "INFO", "BEST_PRACTICES");
// Make an edit to replace where the variable is by "bar"
const edit = buildEdit(variable.start.line, variable.start.col, variable.end.line, variable.end.col, "update", "bar");
// Make a fix with the edit we previously built
const fix = buildFix("use bar instead", [edit]);
// add the error to the list of reported errors
addError(error.addFix(fix));
}
}
program.js
Expected test result: no error
Detect when we pass foo to console.log