UNPKG

@truenine/eslint9-config

Version:

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

51 lines (49 loc) 1.74 kB
//#region src/rules/code-style/no-separator-comment.ts const rule = { meta: { type: "layout", docs: { description: "Remove comments containing repeated characters (===, ---, +++, ###, etc.) used as separators", recommended: false }, fixable: "code", messages: { noSeparatorComment: "Separator comments with repeated characters are not allowed and will be removed." }, schema: [] }, create(context) { const { sourceCode } = context; const separatorPattern = /(.)\1{2,}/; return { Program() { const comments = sourceCode.getAllComments(); for (const comment of comments) if (separatorPattern.test(comment.value)) context.report({ loc: comment.loc, messageId: "noSeparatorComment", fix(fixer) { if (!comment.range || !comment.loc) return null; 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 }); const contentBefore = sourceCode.text.slice(lineStart, comment.range[0]); const contentAfter = sourceCode.text.slice(comment.range[1], lineEnd); if (contentBefore.trim() !== "" && contentAfter.trim() === "") return fixer.remove(comment); 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-separator-comment.cjs.map