Skip to content

Commit

Permalink
Don't apply BanUnknownThis conformance rule to TS-originated files
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 601702161
  • Loading branch information
Closure Team authored and copybara-github committed Jan 26, 2024
1 parent 02a37d2 commit 62745bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/com/google/javascript/jscomp/ConformanceRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,12 @@ public BanUnknownThis(AbstractCompiler compiler, Requirement requirement)
super(compiler, requirement);
}

@Override
protected boolean tsIsAllowlisted() {
// We expect TypeScript to already check it.
return true;
}

@Override
protected ConformanceResult checkConformance(NodeTraversal t, Node n) {
if (n.isThis()) {
Expand Down
12 changes: 12 additions & 0 deletions test/com/google/javascript/jscomp/CheckConformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,18 @@ public void testCustomBanUnknownThis_allowsGoogAssert() {
testNoWarning("function f() {goog.asserts.assertInstanceof(this, Error);}");
}

@Test
public void testCustomBanUnknownThis_allowsTs() {
configuration =
"requirement: {\n"
+ " type: CUSTOM\n"
+ " java_class: 'com.google.javascript.jscomp.ConformanceRules$BanUnknownThis'\n"
+ " error_message: 'BanUnknownThis Message'\n"
+ "}";

testNoWarning(srcs(SourceFile.fromCode("file.closure.js", "function f() {alert(this);}")));
}

private static String config(String rule, String message, String... fields) {
String result = "requirement: {\n" + " type: CUSTOM\n" + " java_class: '" + rule + "'\n";
for (String field : fields) {
Expand Down

0 comments on commit 62745bb

Please sign in to comment.