Skip to content

Commit

Permalink
Add linter warning and suggested fix for extra (i.e. unused) goog.req…
Browse files Browse the repository at this point in the history
…uireType statements.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=229796822
  • Loading branch information
tjgq authored and lauraharker committed Jan 18, 2019
1 parent f77d7c1 commit a28ed37
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 94 deletions.
17 changes: 11 additions & 6 deletions src/com/google/javascript/jscomp/CheckMissingAndExtraRequires.java
Expand Up @@ -154,19 +154,24 @@ private static ImmutableList<String> getClassNames(String qualifiedName) {
} }


// TODO(tbreisacher): Update CodingConvention.extractClassNameIf{Require,Provide} to match this. // TODO(tbreisacher): Update CodingConvention.extractClassNameIf{Require,Provide} to match this.
private String extractNamespace(Node call, String functionName) { private String extractNamespace(Node call, String... primitiveNames) {
Node callee = call.getFirstChild(); Node callee = call.getFirstChild();
if (callee.isGetProp() && callee.matchesQualifiedName(functionName)) { if (!callee.isGetProp()) {
Node target = callee.getNext(); return null;
if (target != null && target.isString()) { }
return target.getString(); for (String primitiveName : primitiveNames) {
if (callee.matchesQualifiedName(primitiveName)) {
Node target = callee.getNext();
if (target != null && target.isString()) {
return target.getString();
}
} }
} }
return null; return null;
} }


private String extractNamespaceIfRequire(Node call) { private String extractNamespaceIfRequire(Node call) {
return extractNamespace(call, "goog.require"); return extractNamespace(call, "goog.require", "goog.requireType");
} }


private String extractNamespaceIfForwardDeclare(Node call) { private String extractNamespaceIfForwardDeclare(Node call) {
Expand Down

0 comments on commit a28ed37

Please sign in to comment.