@@ -29,34 +29,15 @@ const needles = [
29
29
30
30
iterateESLintModules ( patch )
31
31
32
- function getLinterFromModule ( moduleExports ) {
33
- return moduleExports . Linter
34
- ? moduleExports . Linter // ESLint 6+
35
- : moduleExports // ESLint 5-
36
- }
37
-
38
- function getModuleFromCache ( key ) {
39
- if ( ! needles . some ( ( needle ) => key . endsWith ( needle ) ) ) return
40
-
41
- const module = require . cache [ key ]
42
- if ( ! module || ! module . exports ) return
43
-
44
- const Linter = getLinterFromModule ( module . exports )
45
- if (
46
- typeof Linter === "function" &&
47
- typeof Linter . prototype . verify === "function"
48
- ) {
49
- return Linter
50
- }
51
- }
52
-
53
32
function iterateESLintModules ( fn ) {
54
33
let found = false
55
34
56
35
for ( const key in require . cache ) {
57
- const Linter = getModuleFromCache ( key )
58
- if ( Linter ) {
59
- fn ( Linter )
36
+ if ( ! needles . some ( ( needle ) => key . endsWith ( needle ) ) ) continue
37
+
38
+ const module = require . cache [ key ]
39
+ if ( module && module . exports ) {
40
+ fn ( module )
60
41
found = true
61
42
}
62
43
}
@@ -68,7 +49,8 @@ function iterateESLintModules(fn) {
68
49
}
69
50
}
70
51
71
- function patch ( Linter ) {
52
+ function patch ( module ) {
53
+ const Linter = getLinterFromModule ( module )
72
54
// ignore if verify function is already been patched sometime before
73
55
if ( Linter [ LINTER_ISPATCHED_PROPERTY_NAME ] === true ) {
74
56
return
@@ -84,5 +66,17 @@ function patch(Linter) {
84
66
const verifyWithFlatConfig =
85
67
Linter . prototype . _verifyWithFlatConfigArrayAndWithoutProcessors
86
68
Linter . prototype . _verifyWithFlatConfigArrayAndWithoutProcessors =
87
- createVerifyWithFlatConfigPatch ( verifyWithFlatConfig )
69
+ createVerifyWithFlatConfigPatch ( module , verifyWithFlatConfig )
70
+ }
71
+
72
+ function getLinterFromModule ( module ) {
73
+ const Linter = module . exports . Linter
74
+ ? module . exports . Linter // ESLint 6+
75
+ : module . exports // ESLint 5-
76
+ if (
77
+ typeof Linter === "function" &&
78
+ typeof Linter . prototype . verify === "function"
79
+ ) {
80
+ return Linter
81
+ }
88
82
}
0 commit comments