import { ruleCreator } from "../_internal/rule-creator.js";
const disallowedSelector = "VariableDeclarator > TSAsExpression[expression.properties.length=0] > TSTypeReference > Identifier[name='const'], VariableDeclarator[id.typeAnnotation] > TSAsExpression > TSTypeReference > Identifier[name='const']";
const getAsConstExpression = (node) => {
    if (node.type !== "Identifier" ||
        node.parent?.type !== "TSTypeReference" ||
        node.parent.parent?.type !== "TSAsExpression") {
        return undefined;
    }
    return node.parent.parent;
};
/**
 * Disallow unnecessary `as const` assertions.
 */
const rule = ruleCreator({
    create: (context) => {
        const sourceCode = context.sourceCode;
        return {
            [disallowedSelector]: (node) => {
                const asConstExpression = getAsConstExpression(node);
                if (asConstExpression === undefined) {
                    return;
                }
                const replacementText = sourceCode.getText(asConstExpression.expression);
                context.report({
                    fix: (fixer) => fixer.replaceText(asConstExpression, replacementText),
                    messageId: "forbidden",
                    node,
                });
            },
        };
    },
    defaultOptions: [],
    meta: {
        deprecated: false,
        docs: {
            deprecated: false,
            description: "disallow unnecessary as const assertions.",
            frozen: false,
            recommended: false,
            url: "https://nick2bad4u.github.io/eslint-plugin-etc-misc/docs/rules/no-unnecessary-as-const",
        },
        fixable: "code",
        hasSuggestions: false,
        messages: {
            forbidden: "Unnecessary as const assertion.",
        },
        schema: [],
        type: "suggestion",
    },
    name: "no-unnecessary-as-const",
});
export default rule;
//# sourceMappingURL=no-unnecessary-as-const.js.map