12
12
const DisabledArea = require ( "../disabled-area" )
13
13
const utils = require ( "../utils" )
14
14
15
- //------------------------------------------------------------------------------
16
- // Helpers
17
- //------------------------------------------------------------------------------
18
-
19
- /**
20
- * Checks whether `disabledArea` covers `node`.
21
- *
22
- * @param {DisabledArea } disabledArea - Disabled area in question.
23
- * @param {Node } node - The node that might be covered.
24
- * @returns {boolean } `true` if `disabledArea` covers `node`.
25
- * @private
26
- */
27
- function disabledAreaCoversNode ( disabledArea , node ) {
28
- return utils . lte ( disabledArea . start , node . loc . start ) &&
29
- ( ! disabledArea . end || utils . lte ( node . loc . end , disabledArea . end ) )
30
- }
31
-
32
- /**
33
- * Checks whether `disabledArea` covers `node`'s body.
34
- *
35
- * @param {DisabledArea } disabledArea - Disabled area in question.
36
- * @param {Node } node - The node whose body may or may not be covered.
37
- * Must have a `body` property (a Program or BlockStatement will do).
38
- * @returns {boolean } `true` if `disabledArea` covers `node`'s body.
39
- * @private
40
- */
41
- function disabledAreaCoversNodeBody ( disabledArea , node ) {
42
- const body = node . body
43
- const first = body [ 0 ]
44
- const last = body [ body . length - 1 ]
45
- return ! first ||
46
- ( disabledAreaCoversNode ( disabledArea , first ) &&
47
- disabledAreaCoversNode ( disabledArea , last ) )
48
- }
49
-
50
15
//------------------------------------------------------------------------------
51
16
// Rule Definition
52
17
//------------------------------------------------------------------------------
@@ -72,23 +37,20 @@ module.exports = {
72
37
73
38
create ( context ) {
74
39
const allowWholeFile = context . options [ 0 ] && context . options [ 0 ] . allowWholeFile
75
-
76
40
const sourceCode = context . getSourceCode ( )
77
41
const disabledArea = DisabledArea . get ( sourceCode )
78
42
79
- const firstDisabledArea = disabledArea . areas [ 0 ]
80
-
81
43
return {
82
44
Program ( node ) {
45
+ if ( allowWholeFile && node . body . length === 0 ) {
46
+ return
47
+ }
48
+
83
49
for ( const area of disabledArea . areas ) {
84
50
if ( area . end != null ) {
85
51
continue
86
52
}
87
-
88
- if ( allowWholeFile &&
89
- area === firstDisabledArea &&
90
- disabledAreaCoversNodeBody ( area , node )
91
- ) {
53
+ if ( allowWholeFile && utils . lte ( area . start , node . loc . start ) ) {
92
54
continue
93
55
}
94
56
0 commit comments