@@ -57,19 +57,15 @@ module.exports = class DisabledArea {
5757 * @param {Token } comment - The comment token to disable.
5858 * @param {object } location - The start location to disable.
5959 * @param {string[]|null } ruleIds - The ruleId names to disable.
60- * @param {string } kind - The kind of disable-comments to show in reports .
60+ * @param {string } kind - The kind of disable-comments.
6161 * @returns {void }
6262 * @private
6363 */
6464 _disable ( comment , location , ruleIds , kind ) {
6565 if ( ruleIds ) {
6666 for ( const ruleId of ruleIds ) {
6767 if ( this . _getArea ( ruleId , location ) != null ) {
68- this . duplicateDisableDirectives . push ( {
69- comment,
70- ruleId,
71- kind,
72- } )
68+ this . duplicateDisableDirectives . push ( { comment, ruleId } )
7369 }
7470
7571 this . areas . push ( {
@@ -84,11 +80,7 @@ module.exports = class DisabledArea {
8480 }
8581 else {
8682 if ( this . _getArea ( null , location ) != null ) {
87- this . duplicateDisableDirectives . push ( {
88- comment,
89- ruleId : null ,
90- kind,
91- } )
83+ this . duplicateDisableDirectives . push ( { comment, ruleId : null } )
9284 }
9385
9486 this . areas . push ( {
@@ -108,21 +100,21 @@ module.exports = class DisabledArea {
108100 * @param {Token } comment - The comment token to enable.
109101 * @param {object } location - The start location to enable.
110102 * @param {string[]|null } ruleIds - The ruleId names to enable.
103+ * @param {string } kind - The kind of disable-comments.
111104 * @returns {void }
112105 * @private
113106 */
114- _enable ( comment , location , ruleIds ) {
107+ _enable ( comment , location , ruleIds , kind ) {
115108 if ( ruleIds ) {
116109 for ( const ruleId of ruleIds ) {
117110 let used = false
118111
119112 for ( let i = this . areas . length - 1 ; i >= 0 ; -- i ) {
120113 const area = this . areas [ i ]
121114
122- if ( area . end === null && area . ruleId === ruleId ) {
115+ if ( area . end === null && area . kind === kind && area . ruleId === ruleId ) {
123116 area . end = location
124117 used = true
125- break
126118 }
127119 }
128120
@@ -132,21 +124,18 @@ module.exports = class DisabledArea {
132124 }
133125 }
134126 else {
135- let start = null
127+ let used = false
136128
137129 for ( let i = this . areas . length - 1 ; i >= 0 ; -- i ) {
138130 const area = this . areas [ i ]
139131
140- if ( start !== null && area . start !== start ) {
141- break
142- }
143- if ( area . end === null ) {
132+ if ( area . end === null && area . kind === kind ) {
144133 area . end = location
145- start = area . start
134+ used = true
146135 }
147136 }
148137
149- if ( start === null ) {
138+ if ( ! used ) {
150139 this . unusedEnableDirectives . push ( { comment, ruleId : null } )
151140 }
152141 }
@@ -192,32 +181,26 @@ module.exports = class DisabledArea {
192181 const ruleIds = m [ 2 ] ? m [ 2 ] . split ( DELIMITER ) : null
193182
194183 if ( comment . type === "Block" && kind === "eslint-disable" ) {
195- this . _disable ( comment , comment . loc . start , ruleIds , kind )
184+ this . _disable ( comment , comment . loc . start , ruleIds , "block" )
196185 }
197186 else if ( comment . type === "Block" && kind === "eslint-enable" ) {
198- this . _enable ( comment , comment . loc . start , ruleIds )
187+ this . _enable ( comment , comment . loc . start , ruleIds , "block" )
199188 }
200- else if (
201- comment . type === "Line" &&
202- kind === "eslint-disable-line"
203- ) {
189+ else if ( comment . type === "Line" && kind === "eslint-disable-line" ) {
204190 const line = comment . loc . start . line
205191 const start = { line, column : 0 }
206192 const end = { line : line + 1 , column : - 1 }
207193
208- this . _disable ( comment , start , ruleIds , kind )
209- this . _enable ( comment , end , ruleIds )
194+ this . _disable ( comment , start , ruleIds , "line" )
195+ this . _enable ( comment , end , ruleIds , "line" )
210196 }
211- else if (
212- comment . type === "Line" &&
213- kind === "eslint-disable-next-line"
214- ) {
197+ else if ( comment . type === "Line" && kind === "eslint-disable-next-line" ) {
215198 const line = comment . loc . start . line
216199 const start = { line : line + 1 , column : 0 }
217200 const end = { line : line + 2 , column : - 1 }
218201
219- this . _disable ( comment , start , ruleIds , kind )
220- this . _enable ( comment , end , ruleIds )
202+ this . _disable ( comment , start , ruleIds , "line" )
203+ this . _enable ( comment , end , ruleIds , "line" )
221204 }
222205 }
223206 }
0 commit comments