UNPKG

@truenine/eslint9-config

Version:

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

1 lines 3.69 kB
{"version":3,"file":"no-document-requirements.cjs","names":[],"sources":["../../../src/rules/code-style/no-document-requirements.ts"],"sourcesContent":["import type {Rule} from 'eslint' /* eslint-disable ts/no-unsafe-argument */\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'layout',\n docs: {\n description: 'Remove redundant \"Requirements\" lines from document comments',\n recommended: false\n },\n fixable: 'code',\n messages: {\n noDocumentRequirements: 'Redundant \"Requirements\" lines in document comments are not allowed and will be removed.'\n },\n schema: []\n },\n create(context) {\n const {sourceCode} = context\n const requirementsPattern = /^\\s*\\* Requirements/m\n\n return {\n Program() {\n const comments = sourceCode.getAllComments()\n\n for (const comment of comments) {\n const content = comment.value\n if (comment.type === 'Block' && requirementsPattern.test(content)) {\n context.report({\n loc: comment.loc!,\n messageId: 'noDocumentRequirements',\n fix(fixer) {\n if (!comment.range) return null\n\n const commentText = sourceCode.getText(comment as any)\n const lines = commentText.split('\\n')\n const filteredLines = lines.filter(line => !/^\\s*\\* Requirements/.test(line))\n\n const hasContent = filteredLines.some(line => { // Check if the comment still has meaningful content\n const l = line.trim()\n return l !== '' && l !== '/*' && l !== '/**' && l !== '*/' && l !== '*'\n })\n\n if (hasContent) return fixer.replaceText(comment as any, filteredLines.join('\\n'))\n\n const startLine = comment.loc!.start.line // If no content remains, remove the entire comment block\n const endLine = comment.loc!.end.line\n const lineStart = sourceCode.getIndexFromLoc({line: startLine, column: 0})\n const lineEnd = sourceCode.lines[endLine - 1].length + sourceCode.getIndexFromLoc({line: endLine, column: 0})\n\n const isLastLine = endLine === sourceCode.lines.length\n if (isLastLine) return fixer.removeRange([lineStart, lineEnd])\n\n const nextLineStart = sourceCode.getIndexFromLoc({line: endLine + 1, column: 0})\n return fixer.removeRange([lineStart, nextLineStart])\n }\n })\n }\n }\n }\n }\n }\n}\n\nexport default rule\n"],"mappings":";;AAEA,MAA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