UNPKG

@truenine/eslint9-config

Version:

ESLint 9 configuration package for Compose Client projects with TypeScript, Vue, and modern JavaScript support

56 lines (54 loc) 1.92 kB
//#region src/rules/code-style/no-document-requirements.ts const rule = { meta: { type: "layout", docs: { description: "Remove redundant \"Requirements\" lines from document comments", recommended: false }, fixable: "code", messages: { noDocumentRequirements: "Redundant \"Requirements\" lines in document comments are not allowed and will be removed." }, schema: [] }, create(context) { const { sourceCode } = context; const requirementsPattern = /^\s*\* Requirements/m; return { Program() { const comments = sourceCode.getAllComments(); for (const comment of comments) { const content = comment.value; if (comment.type === "Block" && requirementsPattern.test(content)) context.report({ loc: comment.loc, messageId: "noDocumentRequirements", fix(fixer) { if (!comment.range) return null; const filteredLines = sourceCode.getText(comment).split("\n").filter((line) => !/^\s*\* Requirements/.test(line)); if (filteredLines.some((line) => { const l = line.trim(); return l !== "" && l !== "/*" && l !== "/**" && l !== "*/" && l !== "*"; })) return fixer.replaceText(comment, filteredLines.join("\n")); const startLine = comment.loc.start.line; const endLine = comment.loc.end.line; const lineStart = sourceCode.getIndexFromLoc({ line: startLine, column: 0 }); const lineEnd = sourceCode.lines[endLine - 1].length + sourceCode.getIndexFromLoc({ line: endLine, column: 0 }); if (endLine === sourceCode.lines.length) return fixer.removeRange([lineStart, lineEnd]); const nextLineStart = sourceCode.getIndexFromLoc({ line: endLine + 1, column: 0 }); return fixer.removeRange([lineStart, nextLineStart]); } }); } } }; } }; //#endregion module.exports = rule; //# sourceMappingURL=no-document-requirements.cjs.map