no-dom-import
Ast Rule: import
no-dom-import
function cleanName(name) {
return name.substr(1).slice(0, -1);
}
function visit(node, filename, code) {
// only run inside spec files
if (!filename.includes(".spec.") && !filename.includes(".test.")) return;
if (
node.pkg &&
(
cleanName(node.pkg.value) === "dom-testing-library" ||
cleanName(node.pkg.value) === "@testing-library/dom"
)
) {
const error = buildError(
node.start.line,
node.start.col,
node.end.line,
node.end.col,
"import from DOM Testing Library is restricted, import from corresponding Testing Library framework instead.",
"INFORMATIONAL",
"BEST_PRACTICE"
);
addError(error);
}
}
test.spec.js
Expected test result: has error
Examples of incorrect code for this rule
test.spec.js
Expected test result: no error
Examples of correct code for this rule