Skip to content

Commit 1a031d3

Browse files
Closure Teamcopybara-github
Closure Team
authored andcommitted
Change JsCompiler and JsSafeCodingPolicy to strip the genfiles prefix
PiperOrigin-RevId: 732250224
1 parent f9f05d4 commit 1a031d3

File tree

4 files changed

+36
-23
lines changed

4 files changed

+36
-23
lines changed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -1183,18 +1183,14 @@ public boolean getAssumeStaticInheritanceIsNotUsed() {
11831183
private ImmutableList<ConformanceConfig> conformanceConfigs = ImmutableList.of();
11841184

11851185
/**
1186-
* Remove the first match of this regex from any paths when checking conformance whitelists.
1186+
* Remove the first match of this regex from any paths when checking conformance allowlists.
11871187
*
11881188
* <p>You can use this to make absolute paths relative to the root of your source tree. This is
11891189
* useful to work around CI and build systems that use absolute paths.
11901190
*/
11911191
private Optional<Pattern> conformanceRemoveRegexFromPath =
11921192
Optional.of(
1193-
// The regex uses lookahead because we want to be able to identify generated files. For a
1194-
// path like "blaze-out/directory/bin/some/file.js" we strip out the entire prefix,
1195-
// resulting in a reported path of "some/file.js". For generated files, we only strip the
1196-
// first two segments, leaving "genfiles/some/file.js".
1197-
Pattern.compile("^((.*/)?google3/)?(/?(blaze|bazel)-out/[^/]+/(bin/|(?=genfiles/)))?"));
1193+
Pattern.compile("^((.*/)?google3/)?(/?(blaze|bazel)-out/[^/]+/(bin|genfiles)/)?"));
11981194

11991195
public void setConformanceRemoveRegexFromPath(Optional<Pattern> pattern) {
12001196
conformanceRemoveRegexFromPath = pattern;

src/com/google/javascript/jscomp/conformance/conformance.proto

+18-10
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,26 @@ message Requirement {
3131
// and contacts.
3232
optional string error_message = 1;
3333

34-
// Optional: A list of source path prefixes that are exempt from the
35-
// requirement.
34+
// Optional: A list of google3-relative path prefixes that are exempt from the
35+
// requirement. Do not include the `blaze-out/cfg/(bin|genfiles)` prefix for
36+
// generated files.
3637
// DEPRECATED: Use allowlist instead.
3738
repeated string whitelist = 2 [deprecated = true];
3839

39-
// Optional: A list of source paths regexs that are exempt from the
40-
// requirement.
40+
// Optional: A list of google3-relative path regexps that are exempt from the
41+
// requirement. Do not include the `blaze-out/cfg/(bin|genfiles)` prefix for
42+
// generated files.
4143
// DEPRECATED: Use allowlist_regexp instead.
4244
repeated string whitelist_regexp = 3;
4345

44-
// Optional: A list of source path prefixes that are exempt from the
45-
// requirement.
46+
// Optional: A list of google3-relative path prefixes that are exempt from the
47+
// requirement. Do not include the `blaze-out/cfg/(bin|genfiles)` prefix for
48+
// generated files.
4649
repeated string allowlist = 17;
4750

48-
// Optional: A list of source path prefixes that are exempt from the
49-
// requirement.
51+
// Optional: A list of google3-relative path regexps that are exempt from the
52+
// requirement. Do not include the `blaze-out/cfg/(bin|genfiles)` prefix for
53+
// generated files.
5054
repeated string allowlist_regexp = 18;
5155

5256
message WhitelistEntry {
@@ -59,10 +63,14 @@ message Requirement {
5963

6064
optional Reason reason = 1;
6165

62-
// A list of source path prefixes.
66+
// A list of google3-relative path prefixes to be allowlisted.
67+
// Do not include the `blaze-out/cfg/(bin|genfiles)` prefix for generated
68+
// files.
6369
repeated string prefix = 2;
6470

65-
// A list of regexes matching sources to be ignored
71+
// A list of google3-relative path regexps to be allowlisted.
72+
// Do not include the `blaze-out/cfg/(bin|genfiles)` prefix for generated
73+
// files.
6674
repeated string regexp = 3;
6775

6876
// Short explanation.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public void testViolationWhitelistedIgnoresRegex_genfiles() {
495495
+ " type: BANNED_NAME\n"
496496
+ " value: 'eval'\n"
497497
+ " error_message: 'eval is not allowed'\n"
498-
+ " whitelist: 'genfiles/file.js'\n "
498+
+ " whitelist: 'file.js'\n "
499499
+ "}";
500500

501501
testNoWarning(srcs(SourceFile.fromCode("blaze-out/k8-opt/genfiles/file.js", "eval()")));
@@ -508,7 +508,7 @@ public void testViolationAllowlistedIgnoresRegex_genfiles() {
508508
+ " type: BANNED_NAME\n"
509509
+ " value: 'eval'\n"
510510
+ " error_message: 'eval is not allowed'\n"
511-
+ " allowlist: 'genfiles/file.js'\n "
511+
+ " allowlist: 'file.js'\n "
512512
+ "}";
513513

514514
testNoWarning(srcs(SourceFile.fromCode("blaze-out/k8-opt/genfiles/file.js", "eval()")));
@@ -521,8 +521,8 @@ public void testViolationWhitelistedAndAllowlistedIgnoresRegex_genfiles() {
521521
+ " type: BANNED_NAME\n"
522522
+ " value: 'eval'\n"
523523
+ " error_message: 'eval is not allowed'\n"
524-
+ " whitelist: 'genfiles/file1.js'\n "
525-
+ " allowlist: 'genfiles/file2.js'\n "
524+
+ " whitelist: 'file1.js'\n "
525+
+ " allowlist: 'file2.js'\n "
526526
+ "}";
527527

528528
testNoWarning(srcs(SourceFile.fromCode("blaze-out/k8-opt/genfiles/file1.js", "eval()")));

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,25 @@ public void testRemoveRegexFromPath() {
162162
.isEqualTo("some/path");
163163
assertThat(pattern.matcher("blaze-out/k8-fastbin/bin/some/path").replaceAll(""))
164164
.isEqualTo("some/path");
165-
assertThat(pattern.matcher("google3/bazel-out/k8-fastbin/bin/some/path").replaceAll(""))
165+
assertThat(pattern.matcher("google3/blaze-out/k8-fastbin/bin/some/path").replaceAll(""))
166166
.isEqualTo("some/path");
167167
assertThat(pattern.matcher("google3/blaze-out/k8-fastbin/genfiles/some/path").replaceAll(""))
168-
.isEqualTo("genfiles/some/path");
169-
assertThat(pattern.matcher("somethin/google3/blaze-out/k8-fastbin/some/path").replaceAll(""))
168+
.isEqualTo("some/path");
169+
assertThat(pattern.matcher("something/google3/blaze-out/k8-fastbin/some/path").replaceAll(""))
170170
.isEqualTo("blaze-out/k8-fastbin/some/path");
171+
assertThat(
172+
pattern.matcher("/something/google3/blaze-out/k8-fastbin/bin/some/path").replaceAll(""))
173+
.isEqualTo("some/path");
174+
assertThat(pattern.matcher("google3/some/path").replaceAll("")).isEqualTo("some/path");
171175

172176
assertThat(pattern.matcher("google3/foo/blaze-out/some/path").replaceAll(""))
173177
.isEqualTo("foo/blaze-out/some/path");
174178
assertThat(pattern.matcher("google3/blaze-out/foo/blaze-out/some/path").replaceAll(""))
175179
.isEqualTo("blaze-out/foo/blaze-out/some/path");
180+
181+
assertThat(pattern.matcher("bazel-out/k8-fastbin/bin/some/path").replaceAll(""))
182+
.isEqualTo("some/path");
183+
assertThat(pattern.matcher("bazel-out/k8-fastbin/genfiles/some/path").replaceAll(""))
184+
.isEqualTo("some/path");
176185
}
177186
}

0 commit comments

Comments
 (0)