Skip to content

Commit 04691da

Browse files
committed
fix: eslit race conditions causing intermitant github actions test fails
1 parent 0a6a251 commit 04691da

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/extensions/default/JSLint/ESLint.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,15 @@ define(function (require, exports, module) {
183183
* @returns {Promise} a promise to return configuration object.
184184
*/
185185
function _isESLintProject() {
186-
return new Promise((resolve)=>{
186+
return new Promise((resolve, reject)=>{
187187
const configFilePath = path.join(ProjectManager.getProjectRoot().fullPath, PACKAGE_JSON);
188188
DocumentManager.getDocumentForPath(configFilePath).done(function (configDoc) {
189+
if (!ProjectManager.isWithinProject(configFilePath)) {
190+
// this is a rare race condition where the user switches project between the get document call.
191+
// Eg. in integ tests.
192+
reject(`ESLint Project changed while scanning ${configFilePath}`);
193+
return;
194+
}
189195
const content = configDoc.getText();
190196
try {
191197
const config = JSON.parse(content);
@@ -208,10 +214,19 @@ define(function (require, exports, module) {
208214

209215
function _reloadOptions() {
210216
esLintServiceFailed = false;
217+
const scanningProjectPath = ProjectManager.getProjectRoot().fullPath;
211218
_isESLintProject().then((shouldESLintEnable)=>{
219+
if(scanningProjectPath !== ProjectManager.getProjectRoot().fullPath){
220+
// this is a rare race condition where the user switches project between the get document call.
221+
// Eg. in integ tests. do nothing as another scan for the new project will be in progress.
222+
return;
223+
}
212224
useESLintFromProject = shouldESLintEnable;
213225
CodeInspection.requestRun(Strings.ESLINT_NAME);
214226
}).catch(()=>{
227+
if(scanningProjectPath !== ProjectManager.getProjectRoot().fullPath){
228+
return;
229+
}
215230
useESLintFromProject = false;
216231
CodeInspection.requestRun(Strings.ESLINT_NAME);
217232
});

0 commit comments

Comments
 (0)