Skip to content

Commit

Permalink
Add a new DiagnosticGroup: unnecessaryEscape
Browse files Browse the repository at this point in the history
This gives feedback when JS strings contain backslash escapes that aren't
meaningful and are silently ignored. This can catch real issues, and
is quite useful.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160464984
  • Loading branch information
blickly authored and Yannic committed Jul 6, 2017
1 parent 12836b7 commit 1f6810d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/com/google/javascript/jscomp/DiagnosticGroups.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ public DiagnosticGroup forName(String name) {
DiagnosticGroups.registerGroup("jsdocMissingType",
RhinoErrorReporter.JSDOC_MISSING_TYPE_WARNING);

public static final DiagnosticGroup UNNECESSARY_ESCAPE =
DiagnosticGroups.registerGroup("unnecessaryEscape", RhinoErrorReporter.UNNECESSARY_ESCAPE);

// Warnings reported by the linter. If you enable these as errors in your build targets,
// the JS Compiler team will break your build and not rollback.
public static final DiagnosticGroup LINT_CHECKS =
Expand Down Expand Up @@ -633,7 +636,6 @@ public DiagnosticGroup forName(String name) {
ClosureCheckModule.REFERENCE_TO_FULLY_QUALIFIED_IMPORT_NAME,
ClosureCheckModule.REFERENCE_TO_SHORT_IMPORT_BY_LONG_NAME_INCLUDING_SHORT_NAME,
ClosureRewriteModule.USELESS_USE_STRICT_DIRECTIVE,
RhinoErrorReporter.UNNECESSARY_ESCAPE,
RhinoErrorReporter.JSDOC_MISSING_BRACES_WARNING));

static final DiagnosticGroup STRICT_MODULE_CHECKS =
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 @@ -87,6 +87,7 @@ static void lint(Path path, Compiler compiler) throws IOException {
options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING);

options.setWarningLevel(DiagnosticGroups.JSDOC_MISSING_TYPE, CheckLevel.ERROR);
options.setWarningLevel(DiagnosticGroups.UNNECESSARY_ESCAPE, 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);
Expand Down
2 changes: 1 addition & 1 deletion test/com/google/javascript/jscomp/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4280,7 +4280,7 @@ public void testUnnecessaryBackslashInStringLiteral() {

public void testWarnUnnecessaryBackslashInStringLiteral() {
CompilerOptions options = createCompilerOptions();
options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.UNNECESSARY_ESCAPE, CheckLevel.WARNING);
test(options,
"var str = '\\q';",
"var str = 'q';",
Expand Down

0 comments on commit 1f6810d

Please sign in to comment.