Skip to content

Commit

Permalink
Better error message for new capitalization warning.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151157351
  • Loading branch information
tbreisacher committed Mar 27, 2017
1 parent 87104b4 commit d414fc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/com/google/javascript/jscomp/ClosureCheckModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.google.javascript.jscomp;

import static com.google.common.base.Ascii.isUpperCase;
import static com.google.common.base.Ascii.toLowerCase;
import static com.google.common.base.Ascii.toUpperCase;

import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
Expand Down Expand Up @@ -98,7 +100,7 @@ public final class ClosureCheckModule extends AbstractModuleCallback
static final DiagnosticType INCORRECT_SHORTNAME_CAPITALIZATION =
DiagnosticType.disabled(
"JSC_INCORRECT_SHORTNAME_CAPITALIZATION",
"The capitalization of short name {0} is incorrect.");
"The capitalization of short name {0} is incorrect; it should be {1}.");

static final DiagnosticType EXPORT_NOT_A_MODULE_LEVEL_STATEMENT =
DiagnosticType.error(
Expand Down Expand Up @@ -412,7 +414,12 @@ private static void checkShortName(NodeTraversal t, Node shortNameNode, String n
}

if (isUpperCase(shortName.charAt(0)) != isUpperCase(lastSegment.charAt(0))) {
t.report(shortNameNode, INCORRECT_SHORTNAME_CAPITALIZATION, shortName);
char newStartChar =
isUpperCase(shortName.charAt(0))
? toLowerCase(shortName.charAt(0))
: toUpperCase(shortName.charAt(0));
String correctedName = newStartChar + shortName.substring(1);
t.report(shortNameNode, INCORRECT_SHORTNAME_CAPITALIZATION, shortName, correctedName);
}
}

Expand Down
6 changes: 4 additions & 2 deletions test/com/google/javascript/jscomp/ClosureCheckModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ public void testShorthandNameConvention() {
"goog.module('xyz');",
"",
"const GoogAsserts = goog.require('goog.asserts');"),
INCORRECT_SHORTNAME_CAPITALIZATION);
INCORRECT_SHORTNAME_CAPITALIZATION,
"The capitalization of short name GoogAsserts is incorrect; it should be googAsserts.");

testSame(
LINE_JOINER.join(
Expand All @@ -591,7 +592,8 @@ public void testShorthandNameConvention() {
"goog.module('xyz');",
"",
"const event = goog.require('goog.events.Event');"),
INCORRECT_SHORTNAME_CAPITALIZATION);
INCORRECT_SHORTNAME_CAPITALIZATION,
"The capitalization of short name event is incorrect; it should be Event.");
}

public void testIllegalExports() {
Expand Down

0 comments on commit d414fc4

Please sign in to comment.