HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode.com/node_modules/eslint-plugin-svelte/lib/rules/no-useless-mustaches.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
function stripQuotes(text) {
    if ((text.startsWith('"') || text.startsWith("'") || text.startsWith("`")) &&
        text.endsWith(text[0])) {
        return text.slice(1, -1);
    }
    return null;
}
exports.default = (0, utils_1.createRule)("no-useless-mustaches", {
    meta: {
        docs: {
            description: "disallow unnecessary mustache interpolations",
            category: "Best Practices",
            recommended: false,
        },
        fixable: "code",
        schema: [
            {
                type: "object",
                properties: {
                    ignoreIncludesComment: {
                        type: "boolean",
                    },
                    ignoreStringEscape: {
                        type: "boolean",
                    },
                },
                additionalProperties: false,
            },
        ],
        messages: {
            unexpected: "Unexpected mustache interpolation with a string literal value.",
        },
        type: "suggestion",
    },
    create(context) {
        const opts = context.options[0] || {};
        const ignoreIncludesComment = Boolean(opts.ignoreIncludesComment);
        const ignoreStringEscape = Boolean(opts.ignoreStringEscape);
        const sourceCode = context.getSourceCode();
        function verify(node) {
            if (node.kind === "raw") {
                return;
            }
            const { expression } = node;
            let strValue, rawValue;
            if (expression.type === "Literal") {
                if (typeof expression.value !== "string") {
                    return;
                }
                strValue = expression.value;
                rawValue = sourceCode.getText(expression).slice(1, -1);
            }
            else if (expression.type === "TemplateLiteral") {
                if (expression.expressions.length > 0) {
                    return;
                }
                strValue = expression.quasis[0].value.cooked;
                rawValue = expression.quasis[0].value.raw;
            }
            else {
                return;
            }
            const hasComment = sourceCode
                .getTokens(node, { includeComments: true })
                .some((t) => t.type === "Block" || t.type === "Line");
            if (ignoreIncludesComment && hasComment) {
                return;
            }
            let hasEscape = false;
            if (rawValue !== strValue) {
                const chars = [...rawValue];
                let c = chars.shift();
                while (c) {
                    if (c === "\\") {
                        c = chars.shift();
                        if (c == null ||
                            "nrvtbfux".includes(c)) {
                            hasEscape = true;
                            break;
                        }
                    }
                    c = chars.shift();
                }
            }
            if (ignoreStringEscape && hasEscape) {
                return;
            }
            context.report({
                node,
                messageId: "unexpected",
                fix(fixer) {
                    if (hasComment || hasEscape) {
                        return null;
                    }
                    const text = stripQuotes(sourceCode.getText(expression));
                    if (text == null) {
                        return null;
                    }
                    if (text.includes("\n") || /^\s|\s$/u.test(text)) {
                        return null;
                    }
                    const unescaped = text.replace(/\\([\s\S])/g, "$1");
                    if (node.parent.type === "SvelteAttribute" ||
                        node.parent.type === "SvelteStyleDirective") {
                        const div = sourceCode.text.slice(node.parent.key.range[1], node.parent.value[0].range[0]);
                        if (!div.endsWith('"') && !div.endsWith("'")) {
                            return [
                                fixer.insertTextBefore(node.parent.value[0], '"'),
                                fixer.replaceText(node, unescaped.replace(/"/gu, """)),
                                fixer.insertTextAfter(node.parent.value[node.parent.value.length - 1], '"'),
                            ];
                        }
                        return fixer.replaceText(node, unescaped);
                    }
                    return fixer.replaceText(node, unescaped.replace(/</gu, "&lt;").replace(/>/gu, "&gt;"));
                },
            });
        }
        return {
            SvelteMustacheTag: verify,
        };
    },
});