@@ -38,16 +38,16 @@ function compareLocations(itemA, itemB) {
3838 * @param {Iterable<Directive> } directives Unused directives to be removed.
3939 * @returns {Directive[][] } Directives grouped by their parent comment.
4040 */
41- function groupByParentComment ( directives ) {
41+ function groupByParentDirective ( directives ) {
4242 const groups = new Map ( ) ;
4343
4444 for ( const directive of directives ) {
45- const { unprocessedDirective : { parentComment } } = directive ;
45+ const { unprocessedDirective : { parentDirective } } = directive ;
4646
47- if ( groups . has ( parentComment ) ) {
48- groups . get ( parentComment ) . push ( directive ) ;
47+ if ( groups . has ( parentDirective ) ) {
48+ groups . get ( parentDirective ) . push ( directive ) ;
4949 } else {
50- groups . set ( parentComment , [ directive ] ) ;
50+ groups . set ( parentDirective , [ directive ] ) ;
5151 }
5252 }
5353
@@ -57,19 +57,19 @@ function groupByParentComment(directives) {
5757/**
5858 * Creates removal details for a set of directives within the same comment.
5959 * @param {Directive[] } directives Unused directives to be removed.
60- * @param {Token } commentToken The backing Comment token.
60+ * @param {Token } node The backing Comment token.
6161 * @returns {{ description, fix, unprocessedDirective }[] } Details for later creation of output Problems.
6262 */
63- function createIndividualDirectivesRemoval ( directives , commentToken ) {
63+ function createIndividualDirectivesRemoval ( directives , node ) {
6464
6565 /*
66- * `commentToken .value` starts right after `//` or `/*`.
66+ * `node .value` starts right after `//` or `/*`.
6767 * All calculated offsets will be relative to this index.
6868 */
69- const commentValueStart = commentToken . range [ 0 ] + "//" . length ;
69+ const commentValueStart = node . range [ 0 ] + "//" . length ;
7070
7171 // Find where the list of rules starts. `\S+` matches with the directive name (e.g. `eslint-disable-line`)
72- const listStartOffset = / ^ \s * \S + \s + / u. exec ( commentToken . value ) [ 0 ] . length ;
72+ const listStartOffset = / ^ \s * \S + \s + / u. exec ( node . value ) [ 0 ] . length ;
7373
7474 /*
7575 * Get the list text without any surrounding whitespace. In order to preserve the original
@@ -78,7 +78,7 @@ function createIndividualDirectivesRemoval(directives, commentToken) {
7878 * // eslint-disable-line rule-one , rule-two , rule-three -- comment
7979 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8080 */
81- const listText = commentToken . value
81+ const listText = node . value
8282 . slice ( listStartOffset ) // remove directive name and all whitespace before the list
8383 . split ( / \s - { 2 , } \s / u) [ 0 ] // remove `-- comment`, if it exists
8484 . trimEnd ( ) ; // remove all whitespace after the list
@@ -159,13 +159,13 @@ function createIndividualDirectivesRemoval(directives, commentToken) {
159159}
160160
161161/**
162- * Creates a description of deleting an entire unused disable comment .
162+ * Creates a description of deleting an entire unused disable directive .
163163 * @param {Directive[] } directives Unused directives to be removed.
164- * @param {Token } commentToken The backing Comment token.
165- * @returns {{ description, fix, unprocessedDirective } } Details for later creation of an output Problem .
164+ * @param {Token } node The backing Comment token.
165+ * @returns {{ description, fix, unprocessedDirective } } Details for later creation of an output problem .
166166 */
167- function createCommentRemoval ( directives , commentToken ) {
168- const { range } = commentToken ;
167+ function createDirectiveRemoval ( directives , node ) {
168+ const { range } = node ;
169169 const ruleIds = directives . filter ( directive => directive . ruleId ) . map ( directive => `'${ directive . ruleId } '` ) ;
170170
171171 return {
@@ -186,20 +186,20 @@ function createCommentRemoval(directives, commentToken) {
186186 * @returns {{ description, fix, unprocessedDirective }[] } Details for later creation of output Problems.
187187 */
188188function processUnusedDirectives ( allDirectives ) {
189- const directiveGroups = groupByParentComment ( allDirectives ) ;
189+ const directiveGroups = groupByParentDirective ( allDirectives ) ;
190190
191191 return directiveGroups . flatMap (
192192 directives => {
193- const { parentComment } = directives [ 0 ] . unprocessedDirective ;
194- const remainingRuleIds = new Set ( parentComment . ruleIds ) ;
193+ const { parentDirective } = directives [ 0 ] . unprocessedDirective ;
194+ const remainingRuleIds = new Set ( parentDirective . ruleIds ) ;
195195
196196 for ( const directive of directives ) {
197197 remainingRuleIds . delete ( directive . ruleId ) ;
198198 }
199199
200200 return remainingRuleIds . size
201- ? createIndividualDirectivesRemoval ( directives , parentComment . commentToken )
202- : [ createCommentRemoval ( directives , parentComment . commentToken ) ] ;
201+ ? createIndividualDirectivesRemoval ( directives , parentDirective . node )
202+ : [ createDirectiveRemoval ( directives , parentDirective . node ) ] ;
203203 }
204204 ) ;
205205}
@@ -372,7 +372,7 @@ function applyDirectives(options) {
372372
373373 const unusedDirectives = processed
374374 . map ( ( { description, fix, unprocessedDirective } ) => {
375- const { parentComment , type, line, column } = unprocessedDirective ;
375+ const { parentDirective , type, line, column } = unprocessedDirective ;
376376
377377 let message ;
378378
@@ -388,8 +388,8 @@ function applyDirectives(options) {
388388 return {
389389 ruleId : null ,
390390 message,
391- line : type === "disable-next-line" ? parentComment . commentToken . loc . start . line : line ,
392- column : type === "disable-next-line" ? parentComment . commentToken . loc . start . column + 1 : column ,
391+ line : type === "disable-next-line" ? parentDirective . node . loc . start . line : line ,
392+ column : type === "disable-next-line" ? parentDirective . node . loc . start . column + 1 : column ,
393393 severity : options . reportUnusedDisableDirectives === "warn" ? 1 : 2 ,
394394 nodeType : null ,
395395 ...options . disableFixes ? { } : { fix }
0 commit comments