import { arrayJoin, stringSplit } from "ts-extras";
import { ruleCreator } from "../_internal/rule-creator.js";
const splitLines = (sourceText) => stringSplit(sourceText.replaceAll(/\r\n?/gu, "\n"), "\n");
const hasBlankLine = (text) => splitLines(text).some((line) => line.trim().length === 0);
const normalizeExpressionSource = (sourceText) => {
    const lines = splitLines(sourceText).map((line) => line.trimEnd());
    return arrayJoin(lines.filter((line) => line.trim().length > 0), "\n");
};
const createFix = (sourceCode, node) => (fixer) => {
    const sourceText = sourceCode.getText(node.expression);
    const replacement = `${normalizeExpressionSource(sourceText)};`;
    return fixer.replaceText(node, replacement);
};
/**
 * Disallow blank lines inside expression statements.
 */
const rule = ruleCreator({
    create: (context) => ({
        ExpressionStatement: (node) => {
            const sourceText = context.sourceCode.getText(node.expression);
            if (!hasBlankLine(sourceText)) {
                return;
            }
            context.report({
                fix: createFix(context.sourceCode, node),
                messageId: "forbidden",
                node,
            });
        },
    }),
    defaultOptions: [],
    meta: {
        deprecated: false,
        docs: {
            deprecated: false,
            description: "disallow blank lines inside expression statements.",
            frozen: false,
            recommended: false,
            url: "https://nick2bad4u.github.io/eslint-plugin-etc-misc/docs/rules/no-expression-empty-lines",
        },
        fixable: "code",
        hasSuggestions: false,
        messages: {
            forbidden: "Expression statement contains unnecessary blank lines.",
        },
        schema: [],
        type: "suggestion",
    },
    name: "no-expression-empty-lines",
});
export default rule;
//# sourceMappingURL=no-expression-empty-lines.js.map