Skip to content

Commit 4fbde9d

Browse files
lauraharkercopybara-github
authored andcommitted
Put "too many type params" error in checkTypes diagnostic group & default it to warning
The "too many type params" error originally had its own group just for ease of rollout. It's been around for multiple years by now, though. This also cleans up some JSCompiler unit tests with existing violations. If your project enables checkTypes but not tooManyTypeParams, this means you will start seeing errors on extra template types. PiperOrigin-RevId: 766258413
1 parent bf39451 commit 4fbde9d

File tree

7 files changed

+19
-16
lines changed

7 files changed

+19
-16
lines changed

src/com/google/javascript/jscomp/RhinoErrorReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RhinoErrorReporter {
5858
DiagnosticType.disabled("JSC_JSDOC_IMPORT_TYPE_WARNING", "{0}");
5959

6060
static final DiagnosticType TOO_MANY_TEMPLATE_PARAMS =
61-
DiagnosticType.disabled("JSC_TOO_MANY_TEMPLATE_PARAMS", "{0}");
61+
DiagnosticType.warning("JSC_TOO_MANY_TEMPLATE_PARAMS", "{0}");
6262

6363
// Special-cased errors, so that they can be configured via the
6464
// warnings API.

src/com/google/javascript/jscomp/TypeCheck.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ public final class TypeCheck implements NodeTraversal.Callback, CompilerPass {
377377
POSSIBLE_INEXISTENT_PROPERTY,
378378
PROPERTY_ASSIGNMENT_TO_READONLY_VALUE,
379379
RhinoErrorReporter.CYCLIC_INHERITANCE_ERROR,
380+
RhinoErrorReporter.TOO_MANY_TEMPLATE_PARAMS,
380381
RhinoErrorReporter.TYPE_PARSE_ERROR,
381382
RhinoErrorReporter.UNRECOGNIZED_TYPE_ERROR,
382383
SAME_INTERFACE_MULTIPLE_IMPLEMENTS,

src/com/google/javascript/jscomp/testing/TestExternsBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static String getClosureExternsAsSource() {
107107
" */",
108108
"$jscomp.arrayFromIterable = function(iterable) {};",
109109
"/**",
110-
" * @param {string|!Iterable<T>|!Iterator<T>|!Arguments<T>} iterable",
110+
" * @param {string|!Iterable<T>|!Iterator<T>|!Arguments} iterable",
111111
" * @return {!Iterator<T>}",
112112
" * @template T",
113113
" */",

test/com/google/javascript/jscomp/CheckTemplateParamsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected CompilerPass getProcessor(Compiler compiler) {
4747
@Override
4848
protected CompilerOptions getOptions() {
4949
CompilerOptions options = super.getOptions();
50-
options.setWarningLevel(DiagnosticGroups.TOO_MANY_TYPE_PARAMS, CheckLevel.WARNING);
50+
options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.WARNING);
5151
return options;
5252
}
5353

test/com/google/javascript/jscomp/TypeCheckNoTranspileTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
@RunWith(JUnit4.class)
2727
public final class TypeCheckNoTranspileTest extends TypeCheckTestCase {
2828

29-
@Override
30-
protected CompilerOptions getDefaultOptions() {
31-
CompilerOptions options = super.getDefaultOptions();
32-
options.setWarningLevel(DiagnosticGroups.TOO_MANY_TYPE_PARAMS, CheckLevel.WARNING);
33-
return options;
34-
}
35-
3629
@Test
3730
public void testCorrectSubtyping_ofRecursiveTemplateType() {
3831
newTest()

test/com/google/javascript/jscomp/TypedScopeCreatorTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8149,10 +8149,14 @@ public void testReportBadTypeAnnotation_invalidEnumTemplateParametersAreParsed()
81498149

81508150
@Test
81518151
public void testReportBadTypeAnnotationInExtraTemplateParameter() {
8152-
testWarning(
8153-
"class C {} var /** !C<!MissingType> */ x;", RhinoErrorReporter.UNRECOGNIZED_TYPE_ERROR);
8154-
testWarning(
8155-
"var /** !Array<string, !MissingType> */ x;", RhinoErrorReporter.UNRECOGNIZED_TYPE_ERROR);
8152+
test(
8153+
srcs("class C {} var /** !C<!MissingType> */ x;"),
8154+
warning(RhinoErrorReporter.UNRECOGNIZED_TYPE_ERROR),
8155+
warning(RhinoErrorReporter.TOO_MANY_TEMPLATE_PARAMS));
8156+
test(
8157+
srcs("var /** !Array<string, !MissingType> */ x;"),
8158+
warning(RhinoErrorReporter.UNRECOGNIZED_TYPE_ERROR),
8159+
warning(RhinoErrorReporter.TOO_MANY_TEMPLATE_PARAMS));
81568160
}
81578161

81588162
@Test

test/com/google/javascript/jscomp/integration/ClosureIntegrationTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020
import static com.google.common.truth.Truth.assertWithMessage;
21-
import static com.google.javascript.jscomp.DiagnosticGroups.CHECK_TYPES;
2221
import static com.google.javascript.rhino.testing.NodeSubject.assertNode;
2322

2423
import com.google.common.collect.ImmutableList;
@@ -419,9 +418,15 @@ public void testTypecheckNativeModulesDoesntCrash_givenTemplatizedTypedefOfUnion
419418
const /** null */ n = /** @type {!a.TypeDef<?>} */ (0);
420419
"""
421420
},
421+
null,
422422
// Just making sure that typechecking ran and didn't crash. It would be reasonable
423423
// for there also to be other type errors in this code before the final null assignment.
424-
CHECK_TYPES);
424+
new DiagnosticGroup[] {
425+
DiagnosticGroups.CHECK_TYPES,
426+
DiagnosticGroups.CHECK_TYPES,
427+
DiagnosticGroups.CHECK_TYPES,
428+
DiagnosticGroups.CHECK_TYPES
429+
});
425430
}
426431

427432
@Test

0 commit comments

Comments
 (0)