|
Lines 79-84
define([
Link Here
|
| 79 |
this.fileClient = null; |
79 |
this.fileClient = null; |
| 80 |
this.handlers = [eslintHandler]; |
80 |
this.handlers = [eslintHandler]; |
| 81 |
this.projectFiles = [this.PACKAGE_JSON, this.TERN_PROJECT, this.ESLINTRC, this.ESLINTRC_JS, this.ESLINTRC_JSON, this.ESLINTRC_YAML, this.ESLINTRC_YML]; |
81 |
this.projectFiles = [this.PACKAGE_JSON, this.TERN_PROJECT, this.ESLINTRC, this.ESLINTRC_JS, this.ESLINTRC_JSON, this.ESLINTRC_YAML, this.ESLINTRC_YML]; |
|
|
82 |
this.lintFiles = [this.ESLINTRC_JS, this.ESLINTRC_JSON, this.ESLINTRC, this.ESLINTRC_YAML, this.ESLINTRC_YML, this.PACKAGE_JSON]; |
| 82 |
} |
83 |
} |
| 83 |
/** |
84 |
/** |
| 84 |
* The .tern-project file name |
85 |
* The .tern-project file name |
|
Lines 307-356
define([
Link Here
|
| 307 |
* @see http://eslint.org/docs/user-guide/configuring |
308 |
* @see http://eslint.org/docs/user-guide/configuring |
| 308 |
*/ |
309 |
*/ |
| 309 |
JavaScriptProject.prototype.getESlintOptions = function getESlintOptions() { |
310 |
JavaScriptProject.prototype.getESlintOptions = function getESlintOptions() { |
|
|
311 |
var deferred = new Deferred(); |
| 310 |
if(this.map.eslint) { |
312 |
if(this.map.eslint) { |
| 311 |
return new Deferred().resolve(this.map.eslint); |
313 |
return deferred.resolve(this.map.eslint); |
| 312 |
} |
314 |
} |
| 313 |
var vals; |
315 |
this.projectPromise.then(function() { |
| 314 |
return this.getFile(this.ESLINTRC_JS).then(function(file) { |
316 |
var p = []; |
| 315 |
vals = readAndMap(this.map, file, "eslint"); |
317 |
this.lintFiles.forEach(function(_name) { |
| 316 |
if(vals) { |
318 |
p.push(this.getFile(_name)); |
| 317 |
return vals; |
319 |
}.bind(this)) |
| 318 |
} |
320 |
p.reduce(function(prev, current, index, array) { |
| 319 |
return this.getFile(this.ESLINTRC_JSON).then(function(file) { |
321 |
return prev.then(function(_file) { |
| 320 |
vals = readAndMap(this.map, file, "eslint"); |
322 |
var vals = readAndMap(this.map, _file, "eslint"); |
| 321 |
if(vals) { |
323 |
if(vals) { |
| 322 |
return vals; |
324 |
deferred.resolve(vals); |
| 323 |
} |
325 |
return current.reject("done"); |
| 324 |
return this.getFile(this.ESLINTRC).then(function(file) { |
326 |
} else { |
| 325 |
vals = readAndMap(this.map, file, "eslint"); |
327 |
if(index === array.length-1) { |
| 326 |
if(vals) { |
328 |
deferred.resolve(null); |
| 327 |
return vals; |
329 |
} |
| 328 |
} |
330 |
return current; |
| 329 |
return this.getFile(this.ESLINTRC_YAML).then(function(file) { |
331 |
} |
| 330 |
vals = readAndMap(this.map, file, "eslint"); |
332 |
}.bind(this)); |
| 331 |
if (vals) { |
333 |
}.bind(this), new Deferred().resolve()); |
| 332 |
return vals; |
334 |
}.bind(this)); |
| 333 |
} |
335 |
return deferred; |
| 334 |
return this.getFile(this.ESLINTRC_YML).then(function(file) { |
|
|
| 335 |
vals = readAndMap(this.map, file, "eslint"); |
| 336 |
if (vals) { |
| 337 |
return vals; |
| 338 |
} |
| 339 |
return this.getFile(this.PACKAGE_JSON).then(function(file) { |
| 340 |
if(file && file.contents) { |
| 341 |
vals = JSON.parse(file.contents); |
| 342 |
if(vals.eslintConfig !== null && typeof vals.eslintConfig === 'object' && Object.keys(vals.eslintConfig).length > 0) { |
| 343 |
this.map.eslint = vals.eslintConfig; |
| 344 |
return this.map.eslint; |
| 345 |
} |
| 346 |
} |
| 347 |
return null; |
| 348 |
}.bind(this)); |
| 349 |
}.bind(this)); |
| 350 |
}.bind(this)); |
| 351 |
}.bind(this)); |
| 352 |
}.bind(this)); |
| 353 |
}.bind(this)); |
| 354 |
}; |
336 |
}; |
| 355 |
|
337 |
|
| 356 |
/** |
338 |
/** |
|
Lines 388-393
define([
Link Here
|
| 388 |
// ignore |
370 |
// ignore |
| 389 |
} |
371 |
} |
| 390 |
} |
372 |
} |
|
|
373 |
if(vals.eslintConfig && typeof vals.eslintConfig === "object") { |
| 374 |
vals = vals.eslintConfig; |
| 375 |
} |
| 391 |
} |
376 |
} |
| 392 |
if (vals && Object.keys(vals).length > 0) { |
377 |
if (vals && Object.keys(vals).length > 0) { |
| 393 |
map[key] = vals; |
378 |
map[key] = vals; |
|
Lines 416-421
define([
Link Here
|
| 416 |
initialized = true; |
401 |
initialized = true; |
| 417 |
var file = evnt.file; |
402 |
var file = evnt.file; |
| 418 |
resolveProject.call(this, file).then(function(project) { |
403 |
resolveProject.call(this, file).then(function(project) { |
|
|
404 |
this.projectPromise.resolve(project); |
| 419 |
if (project) { |
405 |
if (project) { |
| 420 |
if(!this.projectMeta || project.Location !== this.projectMeta.Location) { |
406 |
if(!this.projectMeta || project.Location !== this.projectMeta.Location) { |
| 421 |
this.projectMeta = project; |
407 |
this.projectMeta = project; |
|
Lines 449-458
define([
Link Here
|
| 449 |
*/ |
435 |
*/ |
| 450 |
function resolveProject(file) { |
436 |
function resolveProject(file) { |
| 451 |
var deferred = new Deferred(); |
437 |
var deferred = new Deferred(); |
|
|
438 |
this.projectPromise = new Deferred(); |
| 452 |
if(file) { |
439 |
if(file) { |
| 453 |
if(this.projectMeta && file.Location && file.Location.startsWith(this.projectMeta.Location)) { |
440 |
var floc = file.Location ? file.Location : file.location; |
|
|
441 |
if(this.projectMeta && floc && floc.startsWith(this.projectMeta.Location)) { |
| 454 |
deferred.resolve(this.projectMeta); |
442 |
deferred.resolve(this.projectMeta); |
| 455 |
return; |
443 |
return deferred; |
| 456 |
} |
444 |
} |
| 457 |
var parents = file.parents ? file.parents : file.Parents; |
445 |
var parents = file.parents ? file.parents : file.Parents; |
| 458 |
if(!Array.isArray(parents) || parents.length < 1) { |
446 |
if(!Array.isArray(parents) || parents.length < 1) { |
|
Lines 466-481
define([
Link Here
|
| 466 |
promises.push(this.getFile(_f, prnt.Location)); |
454 |
promises.push(this.getFile(_f, prnt.Location)); |
| 467 |
promises.push(this.getFile(_f, "/file/")); |
455 |
promises.push(this.getFile(_f, "/file/")); |
| 468 |
}.bind(this)); |
456 |
}.bind(this)); |
| 469 |
promises.reduce(/* @callback */ function(prev, item) { |
457 |
promises.reduce(function(prev, item, index, array) { |
| 470 |
return prev.then(/* @callback */ function(value) { |
458 |
return prev.then(function(_file) { |
| 471 |
return item.then(function(_file) { |
459 |
if(_file && _file.contents) { |
| 472 |
if(_file) { |
460 |
deferred.resolve({Location: _file.project}); |
| 473 |
deferred.resolve({Location: _file.project}); |
461 |
return item.reject("done"); |
| 474 |
throw new Error("stop"); |
462 |
} |
| 475 |
} |
463 |
if(index === array.length-1) { |
| 476 |
}); |
464 |
//nothing was found, assume /file/ |
| 477 |
}); |
465 |
deferred.resolve({Location: "/file/"}); |
| 478 |
}, new Deferred().resolve()); |
466 |
} |
|
|
467 |
return item; |
| 468 |
}.bind(this)); |
| 469 |
}.bind(this), new Deferred().resolve()); |
| 479 |
} else { |
470 |
} else { |
| 480 |
deferred.resolve(parents[parents.length-1]); |
471 |
deferred.resolve(parents[parents.length-1]); |
| 481 |
} |
472 |
} |