|
5 | 5 | "use strict"
|
6 | 6 |
|
7 | 7 | const utils = require("./utils")
|
8 |
| -const COMMENT_DIRECTIVE = /^\s*(eslint-(?:en|dis)able(?:(?:-next)?-line)?)\s*(?:(\S|\S[\s\S]*\S)\s*)?$/u |
9 | 8 | const DELIMITER = /[\s,]+/gu
|
10 | 9 | const pool = new WeakMap()
|
11 | 10 |
|
@@ -162,39 +161,44 @@ module.exports = class DisabledArea {
|
162 | 161 | }
|
163 | 162 |
|
164 | 163 | /**
|
165 |
| - * Scan the souce code and setup disabled area list. |
| 164 | + * Scan the source code and setup disabled area list. |
166 | 165 | *
|
167 | 166 | * @param {eslint.SourceCode} sourceCode - The source code to scan.
|
168 | 167 | * @returns {void}
|
169 | 168 | * @private
|
170 | 169 | */
|
171 | 170 | _scan(sourceCode) {
|
172 | 171 | for (const comment of sourceCode.getAllComments()) {
|
173 |
| - const m = COMMENT_DIRECTIVE.exec(comment.value) |
174 |
| - if (m == null) { |
| 172 | + const directiveComment = utils.parseDirectiveComment(comment) |
| 173 | + if (directiveComment == null) { |
175 | 174 | continue
|
176 | 175 | }
|
177 |
| - const kind = m[1] |
178 |
| - const ruleIds = m[2] ? m[2].split(DELIMITER) : null |
179 | 176 |
|
180 |
| - if (comment.type === "Block" && kind === "eslint-disable") { |
| 177 | + const kind = directiveComment.kind |
| 178 | + if ( |
| 179 | + kind !== "eslint-disable" && |
| 180 | + kind !== "eslint-enable" && |
| 181 | + kind !== "eslint-disable-line" && |
| 182 | + kind !== "eslint-disable-next-line" |
| 183 | + ) { |
| 184 | + continue |
| 185 | + } |
| 186 | + const ruleIds = directiveComment.value |
| 187 | + ? directiveComment.value.split(DELIMITER) |
| 188 | + : null |
| 189 | + |
| 190 | + if (kind === "eslint-disable") { |
181 | 191 | this._disable(comment, comment.loc.start, ruleIds, "block")
|
182 |
| - } else if (comment.type === "Block" && kind === "eslint-enable") { |
| 192 | + } else if (kind === "eslint-enable") { |
183 | 193 | this._enable(comment, comment.loc.start, ruleIds, "block")
|
184 |
| - } else if ( |
185 |
| - comment.type === "Line" && |
186 |
| - kind === "eslint-disable-line" |
187 |
| - ) { |
| 194 | + } else if (kind === "eslint-disable-line") { |
188 | 195 | const line = comment.loc.start.line
|
189 | 196 | const start = { line, column: 0 }
|
190 | 197 | const end = { line: line + 1, column: -1 }
|
191 | 198 |
|
192 | 199 | this._disable(comment, start, ruleIds, "line")
|
193 | 200 | this._enable(comment, end, ruleIds, "line")
|
194 |
| - } else if ( |
195 |
| - comment.type === "Line" && |
196 |
| - kind === "eslint-disable-next-line" |
197 |
| - ) { |
| 201 | + } else if (kind === "eslint-disable-next-line") { |
198 | 202 | const line = comment.loc.start.line
|
199 | 203 | const start = { line: line + 1, column: 0 }
|
200 | 204 | const end = { line: line + 2, column: -1 }
|
|
0 commit comments