@@ -57,19 +57,15 @@ module.exports = class DisabledArea {
57
57
* @param {Token } comment - The comment token to disable.
58
58
* @param {object } location - The start location to disable.
59
59
* @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.
61
61
* @returns {void }
62
62
* @private
63
63
*/
64
64
_disable ( comment , location , ruleIds , kind ) {
65
65
if ( ruleIds ) {
66
66
for ( const ruleId of ruleIds ) {
67
67
if ( this . _getArea ( ruleId , location ) != null ) {
68
- this . duplicateDisableDirectives . push ( {
69
- comment,
70
- ruleId,
71
- kind,
72
- } )
68
+ this . duplicateDisableDirectives . push ( { comment, ruleId } )
73
69
}
74
70
75
71
this . areas . push ( {
@@ -84,11 +80,7 @@ module.exports = class DisabledArea {
84
80
}
85
81
else {
86
82
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 } )
92
84
}
93
85
94
86
this . areas . push ( {
@@ -108,21 +100,21 @@ module.exports = class DisabledArea {
108
100
* @param {Token } comment - The comment token to enable.
109
101
* @param {object } location - The start location to enable.
110
102
* @param {string[]|null } ruleIds - The ruleId names to enable.
103
+ * @param {string } kind - The kind of disable-comments.
111
104
* @returns {void }
112
105
* @private
113
106
*/
114
- _enable ( comment , location , ruleIds ) {
107
+ _enable ( comment , location , ruleIds , kind ) {
115
108
if ( ruleIds ) {
116
109
for ( const ruleId of ruleIds ) {
117
110
let used = false
118
111
119
112
for ( let i = this . areas . length - 1 ; i >= 0 ; -- i ) {
120
113
const area = this . areas [ i ]
121
114
122
- if ( area . end === null && area . ruleId === ruleId ) {
115
+ if ( area . end === null && area . kind === kind && area . ruleId === ruleId ) {
123
116
area . end = location
124
117
used = true
125
- break
126
118
}
127
119
}
128
120
@@ -132,21 +124,18 @@ module.exports = class DisabledArea {
132
124
}
133
125
}
134
126
else {
135
- let start = null
127
+ let used = false
136
128
137
129
for ( let i = this . areas . length - 1 ; i >= 0 ; -- i ) {
138
130
const area = this . areas [ i ]
139
131
140
- if ( start !== null && area . start !== start ) {
141
- break
142
- }
143
- if ( area . end === null ) {
132
+ if ( area . end === null && area . kind === kind ) {
144
133
area . end = location
145
- start = area . start
134
+ used = true
146
135
}
147
136
}
148
137
149
- if ( start === null ) {
138
+ if ( ! used ) {
150
139
this . unusedEnableDirectives . push ( { comment, ruleId : null } )
151
140
}
152
141
}
@@ -192,32 +181,26 @@ module.exports = class DisabledArea {
192
181
const ruleIds = m [ 2 ] ? m [ 2 ] . split ( DELIMITER ) : null
193
182
194
183
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" )
196
185
}
197
186
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" )
199
188
}
200
- else if (
201
- comment . type === "Line" &&
202
- kind === "eslint-disable-line"
203
- ) {
189
+ else if ( comment . type === "Line" && kind === "eslint-disable-line" ) {
204
190
const line = comment . loc . start . line
205
191
const start = { line, column : 0 }
206
192
const end = { line : line + 1 , column : - 1 }
207
193
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" )
210
196
}
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" ) {
215
198
const line = comment . loc . start . line
216
199
const start = { line : line + 1 , column : 0 }
217
200
const end = { line : line + 2 , column : - 1 }
218
201
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" )
221
204
}
222
205
}
223
206
}
0 commit comments