1
1
/**
2
- * @author Toru Nagashima
3
- * @copyright 2016 Toru Nagashima. All rights reserved.
2
+ * @author Toru Nagashima <https://github.com/mysticatea>
4
3
* See LICENSE file in root directory for full license.
5
4
*/
6
5
"use strict"
7
6
8
- //------------------------------------------------------------------------------
9
- // Requirements
10
- //------------------------------------------------------------------------------
11
-
12
7
const utils = require ( "./utils" )
13
-
14
- //------------------------------------------------------------------------------
15
- // Helpers
16
- //------------------------------------------------------------------------------
17
-
18
8
const COMMENT_DIRECTIVE = / ^ \s * ( e s l i n t - (?: e n | d i s ) a b l e (?: (?: - n e x t ) ? - l i n e ) ? ) \s * (?: ( \S | \S [ \s \S ] * \S ) \s * ) ? $ /
19
9
const DELIMITER = / [ \s , ] + / g
20
10
const pool = new WeakMap ( )
21
11
22
- //------------------------------------------------------------------------------
23
- // Exports
24
- //------------------------------------------------------------------------------
25
-
26
12
module . exports = class DisabledArea {
27
13
/**
28
14
* Get singleton instance for the given source code.
@@ -78,8 +64,7 @@ module.exports = class DisabledArea {
78
64
reported : false ,
79
65
} )
80
66
}
81
- }
82
- else {
67
+ } else {
83
68
if ( this . _getArea ( null , location ) != null ) {
84
69
this . duplicateDisableDirectives . push ( { comment, ruleId : null } )
85
70
}
@@ -115,7 +100,11 @@ module.exports = class DisabledArea {
115
100
for ( let i = this . areas . length - 1 ; i >= 0 ; -- i ) {
116
101
const area = this . areas [ i ]
117
102
118
- if ( area . end === null && area . kind === kind && area . ruleId === ruleId ) {
103
+ if (
104
+ area . end === null &&
105
+ area . kind === kind &&
106
+ area . ruleId === ruleId
107
+ ) {
119
108
relatedDisableDirectives . add ( area . comment )
120
109
area . end = location
121
110
used = true
@@ -126,8 +115,7 @@ module.exports = class DisabledArea {
126
115
this . unusedEnableDirectives . push ( { comment, ruleId } )
127
116
}
128
117
}
129
- }
130
- else {
118
+ } else {
131
119
let used = false
132
120
133
121
for ( let i = this . areas . length - 1 ; i >= 0 ; -- i ) {
@@ -145,7 +133,10 @@ module.exports = class DisabledArea {
145
133
}
146
134
}
147
135
148
- this . numberOfRelatedDisableDirectives . set ( comment , relatedDisableDirectives . size )
136
+ this . numberOfRelatedDisableDirectives . set (
137
+ comment ,
138
+ relatedDisableDirectives . size
139
+ )
149
140
}
150
141
151
142
/**
@@ -160,7 +151,8 @@ module.exports = class DisabledArea {
160
151
for ( let i = this . areas . length - 1 ; i >= 0 ; -- i ) {
161
152
const area = this . areas [ i ]
162
153
163
- if ( ( area . ruleId === null || area . ruleId === ruleId ) &&
154
+ if (
155
+ ( area . ruleId === null || area . ruleId === ruleId ) &&
164
156
utils . lte ( area . start , location ) &&
165
157
( area . end === null || utils . lte ( location , area . end ) )
166
158
) {
@@ -189,19 +181,22 @@ module.exports = class DisabledArea {
189
181
190
182
if ( comment . type === "Block" && kind === "eslint-disable" ) {
191
183
this . _disable ( comment , comment . loc . start , ruleIds , "block" )
192
- }
193
- else if ( comment . type === "Block" && kind === "eslint-enable" ) {
184
+ } else if ( comment . type === "Block" && kind === "eslint-enable" ) {
194
185
this . _enable ( comment , comment . loc . start , ruleIds , "block" )
195
- }
196
- else if ( comment . type === "Line" && kind === "eslint-disable-line" ) {
186
+ } else if (
187
+ comment . type === "Line" &&
188
+ kind === "eslint-disable-line"
189
+ ) {
197
190
const line = comment . loc . start . line
198
191
const start = { line, column : 0 }
199
192
const end = { line : line + 1 , column : - 1 }
200
193
201
194
this . _disable ( comment , start , ruleIds , "line" )
202
195
this . _enable ( comment , end , ruleIds , "line" )
203
- }
204
- else if ( comment . type === "Line" && kind === "eslint-disable-next-line" ) {
196
+ } else if (
197
+ comment . type === "Line" &&
198
+ kind === "eslint-disable-next-line"
199
+ ) {
205
200
const line = comment . loc . start . line
206
201
const start = { line : line + 1 , column : 0 }
207
202
const end = { line : line + 2 , column : - 1 }
0 commit comments