"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const shared_1 = require("../shared"); const utils_1 = require("../utils"); const compat_1 = require("../utils/compat"); // ----------------------------------------------------------------------------- // Helpers // ----------------------------------------------------------------------------- const COMMENT_DIRECTIVE_B = /^\s*(eslint-(?:en|dis)able)(?:\s+|$)/; const COMMENT_DIRECTIVE_L = /^\s*(eslint-disable(?:-next)?-line)(?:\s+|$)/; // eslint-disable-next-line func-style -- ignore const ALL_RULES = () => true; /** * Remove the ignored part from a given directive comment and trim it. * @param {string} value The comment text to strip. * @returns {string} The stripped text. */ function stripDirectiveComment(value) { return value.split(/\s-{2,}\s/u)[0]; } exports.default = (0, utils_1.createRule)('comment-directive', { meta: { docs: { description: 'support comment-directives in HTML template', category: 'System', recommended: 'base' }, schema: [ { type: 'object', properties: { reportUnusedDisableDirectives: { type: 'boolean' } }, additionalProperties: false } ], messages: { unused: 'Unused {{kind}} directive (no problems were reported).', unusedRule: "Unused {{kind}} directive (no problems were reported from '{{rule}}').", unusedEnable: 'Unused {{kind}} directive (reporting is not suppressed).', unusedEnableRule: "Unused {{kind}} directive (reporting from '{{rule}}' is not suppressed)." }, type: 'problem' }, create(context) { const shared = (0, shared_1.getShared)((0, compat_1.getFilename)(context)); if (!shared) return {}; const options = context.options[0] || {}; const reportUnusedDisableDirectives = Boolean(options.reportUnusedDisableDirectives); const directives = shared.newCommentDirectives({ ruleId: 'svelte/comment-directive', reportUnusedDisableDirectives }); const sourceCode = (0, compat_1.getSourceCode)(context); /** * Parse a given comment. */ function parse(pattern, comment) { const text = stripDirectiveComment(comment.value); const match = pattern.exec(text); if (match == null) { return null; } const type = match[1]; const rules = []; const rulesRe = /([^\s,]+)[\s,]*/g; let startIndex = match[0].length; rulesRe.lastIndex = startIndex; let res; while ((res = rulesRe.exec(text))) { const ruleId = res[1].trim(); const commentStart = comment.range[0] + 4; /*