Skip to content

Commit 62745bb

Browse files
Closure Teamcopybara-github
Closure Team
authored andcommitted
Don't apply BanUnknownThis conformance rule to TS-originated files
PiperOrigin-RevId: 601702161
1 parent 02a37d2 commit 62745bb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,12 @@ public BanUnknownThis(AbstractCompiler compiler, Requirement requirement)
16311631
super(compiler, requirement);
16321632
}
16331633

1634+
@Override
1635+
protected boolean tsIsAllowlisted() {
1636+
// We expect TypeScript to already check it.
1637+
return true;
1638+
}
1639+
16341640
@Override
16351641
protected ConformanceResult checkConformance(NodeTraversal t, Node n) {
16361642
if (n.isThis()) {

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

+12
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,18 @@ public void testCustomBanUnknownThis_allowsGoogAssert() {
23842384
testNoWarning("function f() {goog.asserts.assertInstanceof(this, Error);}");
23852385
}
23862386

2387+
@Test
2388+
public void testCustomBanUnknownThis_allowsTs() {
2389+
configuration =
2390+
"requirement: {\n"
2391+
+ " type: CUSTOM\n"
2392+
+ " java_class: 'com.google.javascript.jscomp.ConformanceRules$BanUnknownThis'\n"
2393+
+ " error_message: 'BanUnknownThis Message'\n"
2394+
+ "}";
2395+
2396+
testNoWarning(srcs(SourceFile.fromCode("file.closure.js", "function f() {alert(this);}")));
2397+
}
2398+
23872399
private static String config(String rule, String message, String... fields) {
23882400
String result = "requirement: {\n" + " type: CUSTOM\n" + " java_class: '" + rule + "'\n";
23892401
for (String field : fields) {

0 commit comments

Comments
 (0)