@@ -34,6 +34,16 @@ function eventInvolvesFile (event, fileName) {
34
34
return event . path . endsWith ( fileName ) || ( event . oldPath && event . oldPath . endsWith ( fileName ) ) ;
35
35
}
36
36
37
+ // Catch file-change events that involve any of `.eslintrc`, `.eslintrc.js`, or
38
+ // `.eslintrc.yml`.
39
+ function eventInvolvesEslintrc ( event ) {
40
+ return [ event . path , event . oldPath ] . some ( ( p ) => {
41
+ return p && (
42
+ p . includes ( `${ Path . sep } .eslintrc` ) || p . startsWith ( `.eslintrc` )
43
+ ) ;
44
+ } ) ;
45
+ }
46
+
37
47
export default {
38
48
39
49
shouldAutoFix ( textEditor ) {
@@ -48,7 +58,7 @@ export default {
48
58
} ,
49
59
50
60
async activate ( ) {
51
- Config . initialize ( ) ;
61
+ Config . initialize ( atom . project . getPaths ( ) [ 0 ] ) ;
52
62
this . workerPath = Path . join ( __dirname , 'worker.js' ) ;
53
63
this . jobManager = new JobManager ( ) ;
54
64
@@ -78,18 +88,15 @@ export default {
78
88
} ) ;
79
89
}
80
90
) ,
91
+
81
92
// Scan for new .linter-eslint config files when project paths change.
82
- atom . project . onDidChangePaths (
83
- projectPaths => {
84
- this . projectPaths = projectPaths ;
85
- Config . rescan ( ) ;
86
- }
87
- ) ,
93
+ atom . project . onDidChangePaths ( ( ) => Config . rescan ( ) ) ,
94
+
88
95
// React to changes that happen either in a .linter-eslint file or the
89
96
// base package settings.
90
97
Config . onConfigDidChange (
91
98
( config , prevConfig ) => {
92
- console . debug ( 'Config.onConfigDidChange ' , config , prevConfig ) ;
99
+ console . debug ( 'Config changed: ' , config , prevConfig ) ;
93
100
if ( helpers . configShouldInvalidateWorkerCache ( config , prevConfig ) ) {
94
101
this . clearESLintCache ( ) ;
95
102
}
@@ -101,11 +108,10 @@ export default {
101
108
102
109
if ( config . nodeBin !== prevConfig . nodeBin ) {
103
110
this . notified . invalidNodeBin = false ;
104
- console . log ( 'Testing bin:' , config . nodeBin , this . notified . invalid ) ;
105
111
NodePathTester
106
- . schedule ( config . nodeBin )
112
+ . test ( config . nodeBin )
107
113
. then ( ( version ) => {
108
- console . log ( `Switched Node to version` , version ) ;
114
+ console . log ( `Switched Node to version: ` , version ) ;
109
115
this . jobManager . createWorker ( ) ;
110
116
} )
111
117
. catch ( ( ) => {
@@ -114,6 +120,7 @@ export default {
114
120
}
115
121
}
116
122
) ,
123
+
117
124
atom . commands . add ( 'atom-text-editor' , {
118
125
'linter-eslint-node:fix-file' : async ( ) => {
119
126
await this . fixJob ( ) ;
@@ -123,11 +130,13 @@ export default {
123
130
}
124
131
} ) ,
125
132
126
- // Keep track of `.eslintignore` updates.
127
- // TODO: If the changed file's relative project path includes
128
- // `node_modules`, ignore it.
133
+ // Keep track of `.eslintignore` and `.eslintrc` updates.
129
134
atom . project . onDidChangeFiles ( events => {
130
135
for ( const event of events ) {
136
+ // Without this, `npm install` inside an already-open project
137
+ // triggers a _bunch_ of cache clearances.
138
+ if ( event . path . includes ( 'node_modules' ) ) { return false ; }
139
+
131
140
if ( eventInvolvesFile ( event , '.linter-eslint' ) ) {
132
141
Config . rescan ( ) ;
133
142
}
@@ -140,6 +149,10 @@ export default {
140
149
if ( eventInvolvesFile ( event , '.eslintignore' ) ) {
141
150
this . clearESLintCache ( ) ;
142
151
}
152
+
153
+ if ( eventInvolvesEslintrc ( event ) ) {
154
+ this . clearESLintCache ( ) ;
155
+ }
143
156
}
144
157
} ) ,
145
158
@@ -372,7 +385,6 @@ export default {
372
385
} ,
373
386
374
387
handleError ( err , type , editor = null ) {
375
- console . debug ( 'handleError:' , err ) ;
376
388
if ( err . name && err . name === 'InvalidWorkerError' ) {
377
389
// The worker script never got created. Aside from notifying the user
378
390
// (which will be skipped if they've already gotten such a message in
@@ -555,7 +567,7 @@ export default {
555
567
filteredResults . push ( result ) ;
556
568
}
557
569
558
- console . log ( 'RETURNED RESULTS :', filteredResults ) ;
570
+ console . debug ( 'Linting results :', filteredResults ) ;
559
571
return filteredResults ;
560
572
} catch ( err ) {
561
573
return this . handleError ( err , 'lint' , textEditor ) ;
0 commit comments