import { isDefined } from "ts-extras";
import { ruleCreator } from "../_internal/rule-creator.js";
const selector = ":matches(PropertyDefinition, TSPropertySignature)[readonly!=true]";
/**
 * Require readonly modifiers on class and interface properties.
 */
const rule = ruleCreator({
    create: (context) => ({
        [selector]: (node) => {
            if (node.type !== "PropertyDefinition" &&
                node.type !== "TSPropertySignature") {
                return;
            }
            const keyNode = node.key;
            const fix = keyNode.type === "Identifier" ||
                keyNode.type === "PrivateIdentifier" ||
                keyNode.type === "Literal"
                ? (fixer) => fixer.insertTextBefore(keyNode, "readonly ")
                : undefined;
            context.report({
                messageId: "forbidden",
                node,
                ...(isDefined(fix)
                    ? {
                        fix,
                        suggest: [
                            {
                                fix,
                                messageId: "suggestAddReadonly",
                            },
                        ],
                    }
                    : {}),
            });
        },
    }),
    defaultOptions: [],
    meta: {
        deprecated: false,
        docs: {
            deprecated: false,
            description: "require readonly for class and interface properties.",
            frozen: false,
            recommended: false,
            url: "https://nick2bad4u.github.io/eslint-plugin-etc-misc/docs/rules/typescript-prefer-readonly-property",
        },
        fixable: "code",
        hasSuggestions: true,
        messages: {
            forbidden: "Prefer readonly property declarations.",
            suggestAddReadonly: "Insert readonly modifier for this property declaration.",
        },
        schema: [],
        type: "suggestion",
    },
    name: "typescript/prefer-readonly-property",
});
export default rule;
//# sourceMappingURL=typescript-prefer-readonly-property.js.map