Skip to content

feat(bazel): validate that checked-in bundles are ignored in prettierignore#3707

Open
josephperrott wants to merge 1 commit into
angular:mainfrom
josephperrott:validate-prettierignore-check
Open

feat(bazel): validate that checked-in bundles are ignored in prettierignore#3707
josephperrott wants to merge 1 commit into
angular:mainfrom
josephperrott:validate-prettierignore-check

Conversation

@josephperrott
Copy link
Copy Markdown
Member

Adds a Bazel js_test validation check to the esbuild_checked_in macro that asserts that the checked-in bundle is ignored in .prettierignore, preventing format check-in mismatches.

@josephperrott josephperrott added the action: merge The PR is ready for merge by the caretaker label May 27, 2026
@josephperrott josephperrott requested a review from alan-agius4 May 27, 2026 15:55
@angular-robot angular-robot Bot added the detected: feature PR contains a feature commit label May 27, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a validation mechanism to ensure that checked-in bundles generated by the esbuild_checked_in macro are correctly ignored in .prettierignore. It adds a new Bazel validation rule validate_prettierignore and a supporting Node.js script verify-prettierignore.mjs. The review feedback identifies several critical improvements: handling Windows path separators (\\) in the verification script to prevent regex failures, normalizing .prettierignore patterns by stripping leading ./ or / to avoid false negatives, and forwarding common test attributes (such as tags and testonly) from the macros to the underlying js_test to ensure correct test execution behavior.

// We need to clean it up to match the relative workspace path.
// Aspect JS rules prefix the path with the workspace name segment (e.g. "_main" or "devinfra").
// Removing the first segment gets the workspace-relative path.
const relativePath = bundlePath.replace(/^[^/]+\//, '');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

On Windows, bundlePath may contain backslashes (\\) instead of forward slashes (/). This will cause the regex replacement to fail to strip the workspace prefix, and the resulting path will not match the forward-slash format used in .prettierignore.

To ensure Windows compatibility (as required by the general rules), we should normalize the path separators to forward slashes before processing.

Suggested change
const relativePath = bundlePath.replace(/^[^/]+\//, '');
const normalizedBundlePath = bundlePath.replace(/\\/g, '/');
const relativePath = normalizedBundlePath.replace(/^[^/]+\//, '');

Comment on lines +19 to +24
const ignoredFiles = new Set(
prettierIgnoreContent
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => line && !line.startsWith('#')),
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

.prettierignore entries often start with / or ./ to specify paths relative to the workspace root (e.g., /foo/bar.js or ./foo/bar.js). Since relativePath does not have a leading slash, a direct Set.has check will fail to match these entries.

We can normalize the ignore patterns by stripping leading / and ./ prefixes to prevent false negatives.

Suggested change
const ignoredFiles = new Set(
prettierIgnoreContent
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => line && !line.startsWith('#')),
);
const ignoredFiles = new Set(
prettierIgnoreContent
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => line && !line.startsWith('#'))
.map((line) => line.replace(/^\.?\//, '')),
);

Comment thread bazel/validation/defs.bzl
Comment on lines +17 to +29
def validate_prettierignore(name, prettierignore, bundle):
js_test(
name = name,
data = [
prettierignore,
bundle,
],
entry_point = "@devinfra//bazel/validation:verify-prettierignore",
fixed_args = [
"$(rlocationpath %s)" % prettierignore,
"$(rlocationpath %s)" % bundle,
],
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The validate_prettierignore macro does not accept or forward common test attributes (such as tags, testonly, timeout, etc.) to the underlying js_test.

If esbuild_checked_in is called with specific tags (e.g., tags = ["manual"]) or other attributes, they won't be applied to the validation test, which can lead to unexpected test execution behavior.

We should accept **kwargs in validate_prettierignore and forward them to js_test.

Suggested change
def validate_prettierignore(name, prettierignore, bundle):
js_test(
name = name,
data = [
prettierignore,
bundle,
],
entry_point = "@devinfra//bazel/validation:verify-prettierignore",
fixed_args = [
"$(rlocationpath %s)" % prettierignore,
"$(rlocationpath %s)" % bundle,
],
)
def validate_prettierignore(name, prettierignore, bundle, **kwargs):
js_test(
name = name,
data = [
prettierignore,
bundle,
],
entry_point = "@devinfra//bazel/validation:verify-prettierignore",
fixed_args = [
"$(rlocationpath %s)" % prettierignore,
"$(rlocationpath %s)" % bundle,
],
**kwargs
)

Comment thread tools/defaults.bzl
Comment on lines +173 to +177
validate_prettierignore(
name = "%s_prettierignore_test" % name,
prettierignore = "//:prettierignore",
bundle = "%s.js" % name,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure that the validation test inherits the correct tags and testonly attributes from the parent esbuild_checked_in macro, we should retrieve and pass them to validate_prettierignore.

Suggested change
validate_prettierignore(
name = "%s_prettierignore_test" % name,
prettierignore = "//:prettierignore",
bundle = "%s.js" % name,
)
validate_prettierignore(
name = "%s_prettierignore_test" % name,
prettierignore = "//:prettierignore",
bundle = "%s.js" % name,
tags = kwargs.get("tags", []),
testonly = kwargs.get("testonly", False),
)

@josephperrott josephperrott force-pushed the validate-prettierignore-check branch from 48a6e62 to b496c1b Compare May 27, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants