Skip to content

Commit 72614c1

Browse files
Soy Authorscopybara-github
authored andcommitted
correct Tricorder merger bounds and DuplicateNamespacesFixer ranges
PiperOrigin-RevId: 907805892
1 parent 81a8c8b commit 72614c1

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

java/src/com/google/template/soy/passes/BanDuplicateNamespacesPass.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@
4646
final class BanDuplicateNamespacesPass implements CompilerFileSetPass {
4747
private static final SoyErrorKind DUPLICATE_NAMESPACE =
4848
SoyErrorKind.of(
49-
"Found another file ''{0}'' with the same namespace. All files must have unique"
50-
+ " namespaces.",
49+
"Namespace collision with: {0}. All files must have unique namespaces.",
5150
Impression.ERROR_BAN_DUPLICATE_NAMESPACES_PASS_DUPLICATE_NAMESPACE);
5251
private static final SoyErrorKind DUPLICATE_NAMESPACE_WARNING =
5352
SoyErrorKind.of(
54-
"Found another file ''{0}'' with the same namespace. All files should have unique"
55-
+ " namespaces. This will soon become an error.",
53+
"Namespace collision with: {0}. All files should have unique namespaces. This will soon"
54+
+ " become an error.",
5655
Impression.WARNING_BAN_DUPLICATE_NAMESPACES_PASS_DUPLICATE_NAMESPACE_WARNING);
5756
private static final SoyErrorKind NAMESPACE_COLLISION =
5857
SoyErrorKind.of(
@@ -79,7 +78,10 @@ public Result run(ImmutableList<SoyFileNode> sourceFiles, IdGenerator nodeIdGen)
7978
if (filePaths.size() > 1) {
8079
String filePath = sourceFile.getFilePath().path();
8180
String otherFiles =
82-
filePaths.stream().filter(path -> !path.equals(filePath)).collect(joining(", "));
81+
filePaths.stream()
82+
.filter(path -> !path.equals(filePath))
83+
.map(path -> "'" + path + "'")
84+
.collect(joining(", "));
8385
if (NamespaceExemptions.isKnownDuplicateNamespace(sourceFile.getNamespace())) {
8486
errorReporter.warn(
8587
sourceFile.getNamespaceDeclaration().getSourceLocation(),

java/tests/com/google/template/soy/passes/BanDuplicateNamespacesPassTest.java

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

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import com.google.common.base.Joiner;
2221
import com.google.template.soy.SoyFileSetParser.ParseResult;
2322
import com.google.template.soy.base.SourceFilePath;
2423
import com.google.template.soy.base.internal.SoyFileSupplier;
@@ -37,32 +36,28 @@ public void externOnlyDuplicateNamespace_reportsError() {
3736
ParseResult unused =
3837
SoyFileSetParserBuilder.forSuppliers(
3938
SoyFileSupplier.Factory.create(
40-
Joiner.on("\n")
41-
.join(
42-
"{namespace my.duplicate.namespace.testing}",
43-
"{template t}",
44-
"{/template}"),
39+
"""
40+
{namespace my.duplicate.namespace.testing}
41+
{template t}
42+
{/template}\
43+
""",
4544
SourceFilePath.forTest("file1.soy")),
4645
SoyFileSupplier.Factory.create(
47-
Joiner.on("\n")
48-
.join(
49-
"{namespace my.duplicate.namespace.testing}",
50-
"{extern myExtern: (s: string) => string}",
51-
" {jsimpl namespace=\"goog.string\" function=\"capitalize\" /}",
52-
"{/extern}"),
46+
"""
47+
{namespace my.duplicate.namespace.testing}
48+
{extern myExtern: (s: string) => string}
49+
{jsimpl namespace="goog.string" function="capitalize" /}
50+
{/extern}\
51+
""",
5352
SourceFilePath.forTest("file2.soy")))
5453
.errorReporter(errorReporter)
5554
.build()
5655
.parse();
5756

5857
assertThat(errorReporter.getErrors()).hasSize(2);
5958
assertThat(errorReporter.getErrors().get(0).message())
60-
.isEqualTo(
61-
"Found another file 'file2.soy' with the same namespace. All files must have unique"
62-
+ " namespaces.");
59+
.isEqualTo("Namespace collision with: 'file2.soy'. All files must have unique namespaces.");
6360
assertThat(errorReporter.getErrors().get(1).message())
64-
.isEqualTo(
65-
"Found another file 'file1.soy' with the same namespace. All files must have unique"
66-
+ " namespaces.");
61+
.isEqualTo("Namespace collision with: 'file1.soy'. All files must have unique namespaces.");
6762
}
6863
}

0 commit comments

Comments
 (0)