Skip to content

Commit

Permalink
Split the unused local variable check out from lintChecks so that it …
Browse files Browse the repository at this point in the history
…can be enabled without accidentally enabling other lint checks.

Also make sure the "unused local variable" check is enabled as part of the linter.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=142040994
  • Loading branch information
tbreisacher authored and blickly committed Dec 15, 2016
1 parent c157a1f commit c584457
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/com/google/javascript/jscomp/DiagnosticGroups.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ public DiagnosticGroup forName(String name) {
ClosureRewriteModule.USELESS_USE_STRICT_DIRECTIVE,
RhinoErrorReporter.JSDOC_MISSING_BRACES_WARNING,
RhinoErrorReporter.JSDOC_MISSING_TYPE_WARNING,
RhinoErrorReporter.TOO_MANY_TEMPLATE_PARAMS,
VariableReferenceCheck.UNUSED_LOCAL_ASSIGNMENT));
RhinoErrorReporter.TOO_MANY_TEMPLATE_PARAMS));

static final DiagnosticGroup STRICT_MODULE_CHECKS =
DiagnosticGroups.registerGroup(
Expand Down
9 changes: 9 additions & 0 deletions src/com/google/javascript/jscomp/LintPassConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LintPassConfig extends PassConfig.PassConfigDelegate {
@Override protected List<PassFactory> getChecks() {
return ImmutableList.of(
earlyLintChecks,
variableReferenceCheck,
closureRewriteClass,
lateLintChecks);
}
Expand Down Expand Up @@ -78,6 +79,14 @@ protected CompilerPass create(AbstractCompiler compiler) {
}
};

private final PassFactory variableReferenceCheck =
new PassFactory("variableReferenceCheck", true) {
@Override
protected CompilerPass create(AbstractCompiler compiler) {
return new VariableReferenceCheck(compiler);
}
};

private final PassFactory closureRewriteClass =
new PassFactory("closureRewriteClass", true) {
@Override
Expand Down
1 change: 1 addition & 0 deletions src/com/google/javascript/jscomp/Linter.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private static void lint(Path path, boolean fix) throws IOException {
options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING);

options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.UNUSED_LOCAL_VARIABLE, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.STRICT_MISSING_REQUIRE, CheckLevel.ERROR);
options.setWarningLevel(DiagnosticGroups.EXTRA_REQUIRE, CheckLevel.ERROR);
options.setWarningLevel(DiagnosticGroups.USE_OF_GOOG_BASE, CheckLevel.WARNING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public final class VariableReferenceCheckTest extends Es6CompilerTestCase {
private static final String VARIABLE_RUN =
"var a = 1; var b = 2; var c = a + b, d = c;";

private boolean enableUnusedLocalAssignmentCheck = false;
private boolean enableUnusedLocalAssignmentCheck;

@Override
public CompilerOptions getOptions() {
CompilerOptions options = super.getOptions();
if (enableUnusedLocalAssignmentCheck) {
options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.UNUSED_LOCAL_VARIABLE, CheckLevel.WARNING);
}
return options;
}
Expand All @@ -46,6 +46,7 @@ public CompilerPass getProcessor(Compiler compiler) {
@Override
public void setUp() throws Exception {
super.setUp();
enableUnusedLocalAssignmentCheck = false;
}

public void testCorrectCode() {
Expand Down

0 comments on commit c584457

Please sign in to comment.