Skip to content

Commit

Permalink
Fixing #34 - don't report false positives for yarn managed modules
Browse files Browse the repository at this point in the history
  • Loading branch information
egamma committed Apr 10, 2017
1 parent d83908f commit 3424c55
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ function loadConfiguration(context: ExtensionContext): void {
}
}

function validateDocument(document: TextDocument) {
async function validateDocument(document: TextDocument) {
//console.log('validateDocument ', document.fileName);
if (!validationEnabled) {

// do not validate yarn managed node_modules
if (!validationEnabled || await isYarnManaged()) {
diagnosticCollection.clear();
return;
}
if (!isPackageJson(document)) {
Expand All @@ -249,6 +252,18 @@ function isPackageJson(document: TextDocument) {
return document && path.basename(document.fileName) === 'package.json';
}

async function isYarnManaged(): Promise<boolean> {
return new Promise<boolean>((resolve, _reject) => {
const cwd = workspace.rootPath;
if (!cwd) {
return resolve(false);
}
fs.stat(path.join(cwd, 'yarn.lock'), (err, _stat) => {
return resolve(err === null);
});
});
}

function validateAllDocuments() {
// TODO: why doesn't this not work?
//workspace.textDocuments.forEach(each => validateDocument(each));
Expand Down

0 comments on commit 3424c55

Please sign in to comment.