import { isERBNode } from "@herb-tools/core";
import { BaseRuleVisitor } from "./rule-utils.js";
class RequireWhitespaceInsideTags extends BaseRuleVisitor {
    visitChildNodes(node) {
        this.checkWhitespace(node);
        super.visitChildNodes(node);
    }
    checkWhitespace(node) {
        if (!isERBNode(node)) {
            return;
        }
        const openTag = node.tag_opening;
        const closeTag = node.tag_closing;
        const content = node.content;
        if (!openTag || !closeTag || !content) {
            return;
        }
        const value = content.value;
        this.checkOpenTagWhitespace(openTag, value);
        this.checkCloseTagWhitespace(closeTag, value);
    }
    checkOpenTagWhitespace(openTag, content) {
        if (content.startsWith(" ") || content.startsWith("\n")) {
            return;
        }
        this.addOffense(`Add whitespace after \`${openTag.value}\`.`, openTag.location, "error");
    }
    checkCloseTagWhitespace(closeTag, content) {
        if (content.endsWith(" ") || content.endsWith("\n")) {
            return;
        }
        this.addOffense(`Add whitespace before \`${closeTag.value}\`.`, closeTag.location, "error");
    }
}
export class ERBRequireWhitespaceRule {
    name = "erb-require-whitespace-inside-tags";
    check(node) {
        const visitor = new RequireWhitespaceInsideTags(this.name);
        visitor.visit(node);
        return visitor.offenses;
    }
}
//# sourceMappingURL=erb-require-whitespace-inside-tags.js.map