From 93d9df1c4c3e3f6485130ec2976876ab332d0ef2 Mon Sep 17 00:00:00 2001 From: joeduffy Date: Sun, 12 Feb 2017 06:23:22 -0800 Subject: [PATCH] Issue a MuJS warning on unused dependencies --- tools/mujs/lib/compiler/transform.ts | 10 ++++++++++ tools/mujs/lib/diag/context.ts | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/tools/mujs/lib/compiler/transform.ts b/tools/mujs/lib/compiler/transform.ts index 627bdbb03..ebb44cee7 100644 --- a/tools/mujs/lib/compiler/transform.ts +++ b/tools/mujs/lib/compiler/transform.ts @@ -275,6 +275,16 @@ export class Transformer { } } + // Also warn about dependency packages that weren't actually used. + if (this.pkg.dependencies) { + for (let dep of Object.keys(this.pkg.dependencies)) { + if (!this.currentPackageDependencies.has(dep)) { + this.diagnostics.push(this.dctx.newUnusedDependencyWarning(dep)); + } + } + } + + // Now create a new package object. return { diagnostics: this.diagnostics, diff --git a/tools/mujs/lib/diag/context.ts b/tools/mujs/lib/diag/context.ts index 6e2e2e306..f5a33908a 100644 --- a/tools/mujs/lib/diag/context.ts +++ b/tools/mujs/lib/diag/context.ts @@ -221,6 +221,14 @@ export class Context { }; } + public newUnusedDependencyWarning(pkg: tokens.PackageToken): Diagnostic { + return { + category: DiagnosticCategory.Warning, + code: 4, + message: `Package '${pkg}' was declared as a dependency but not used`, + }; + } + public newAsyncNotSupportedError(node: ts.Node): Diagnostic { return { category: DiagnosticCategory.Error,