MCPcopy
hub / github.com/htmlhint/HTMLHint / parseDisableComments

Method parseDisableComments

src/core/core.ts:82–188  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

80 }
81
82 private parseDisableComments(html: string): DisabledRulesMap {
83 const disabledRulesMap: DisabledRulesMap = {}
84 const lines = html.split(/\r?\n/)
85 const regComment =
86 /<!--\s*htmlhint-(disable|enable)(?:-next-line)?(?:\s+([^\r\n]+?))?\s*-->/gi
87
88 // Find all disable/enable comments and their positions
89 const comments: Array<{
90 line: number
91 command: string
92 isNextLine: boolean
93 rulesStr?: string
94 }> = []
95
96 let match: RegExpExecArray | null
97 while ((match = regComment.exec(html)) !== null) {
98 // Calculate line number from match position
99 const beforeMatch = html.substring(0, match.index)
100 const lineNumber = beforeMatch.split(/\r?\n/).length
101 const command = match[1].toLowerCase()
102 const isNextLine = match[0].includes('-next-line')
103 const rulesStr = match[2]?.trim()
104
105 comments.push({
106 line: lineNumber,
107 command,
108 isNextLine,
109 rulesStr,
110 })
111 }
112
113 // Process comments in order
114 let currentDisabledRules: Set<string> | null = null
115 let isAllDisabled = false
116
117 for (let i = 0; i < lines.length; i++) {
118 const line = i + 1
119
120 // Check if there's a comment on this line
121 const commentOnLine = comments.find((c) => c.line === line)
122 if (commentOnLine) {
123 if (commentOnLine.command === 'disable') {
124 if (commentOnLine.isNextLine) {
125 // htmlhint-disable-next-line
126 const nextLine = line + 1
127 if (commentOnLine.rulesStr) {
128 // Specific rules disabled
129 const rules = commentOnLine.rulesStr
130 .split(/\s+/)
131 .filter((r) => r.length > 0)
132 if (!disabledRulesMap[nextLine]) {
133 disabledRulesMap[nextLine] = {}
134 }
135 if (!disabledRulesMap[nextLine].rules) {
136 disabledRulesMap[nextLine].rules = new Set()
137 }
138 rules.forEach((r) => disabledRulesMap[nextLine].rules!.add(r))
139 } else {

Callers 1

verifyMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected