import { arrayJoin } from "ts-extras";
import { ruleCreator } from "../_internal/rule-creator.js";
const selector = arrayJoin([
    ":not(TSTypeOperator[operator='readonly']) > :matches(TSArrayType, TSTupleType)",
    "TSTypeReference > Identifier[name='Array']",
], ", ");
/**
 * Require readonly array and tuple type annotations.
 */
const rule = ruleCreator({
    create: (context) => {
        const sourceCode = context.sourceCode;
        return {
            [selector]: (node) => {
                if (node.type !== "Identifier" &&
                    node.type !== "TSArrayType" &&
                    node.type !== "TSTupleType") {
                    return;
                }
                const fix = node.type === "Identifier"
                    ? (fixer) => fixer.replaceText(node, "ReadonlyArray")
                    : (fixer) => fixer.replaceText(node, `readonly ${sourceCode.getText(node)}`);
                context.report({
                    fix,
                    messageId: "forbidden",
                    node,
                });
            },
        };
    },
    defaultOptions: [],
    meta: {
        deprecated: false,
        docs: {
            deprecated: false,
            description: "require readonly array and tuple type annotations.",
            frozen: false,
            recommended: false,
            url: "https://nick2bad4u.github.io/eslint-plugin-etc-misc/docs/rules/typescript-prefer-readonly-array",
        },
        fixable: "code",
        hasSuggestions: false,
        messages: {
            forbidden: "Prefer readonly array or tuple types.",
        },
        schema: [],
        type: "suggestion",
    },
    name: "typescript/prefer-readonly-array",
});
export default rule;
//# sourceMappingURL=typescript-prefer-readonly-array.js.map