Skip to content

Updating positional-args check to be more comprehensive#1393

Merged
oreflow merged 1 commit intomainfrom
positional-args
Sep 26, 2025
Merged

Updating positional-args check to be more comprehensive#1393
oreflow merged 1 commit intomainfrom
positional-args

Conversation

@oreflow
Copy link
Collaborator

@oreflow oreflow commented Sep 12, 2025

  • Previous implementation just assumed that macros were called at the root of a BUILD file, and that all calls were to macros/rules except for explicit allowlist. Updating the check to more precisely validate whether something is a rule/macro, and checking all call expressions (including ones nested in dicts/attrs).
  • Also updating IsMacro implementation to correctly support symblic macro definitions (my_macro = macro(...))

@oreflow oreflow requested a review from vladmos as a code owner September 12, 2025 12:31
@oreflow oreflow enabled auto-merge (squash) September 12, 2025 12:32
@oreflow oreflow disabled auto-merge September 12, 2025 12:43
@oreflow oreflow marked this pull request as draft September 12, 2025 12:55
@oreflow oreflow force-pushed the positional-args branch 2 times, most recently from f23947f to 0a68444 Compare September 17, 2025 11:32
@oreflow oreflow marked this pull request as ready for review September 17, 2025 11:35
@AnnaSvalova AnnaSvalova self-requested a review September 17, 2025 16:16
// Check whether fn.name is a rule
if fileData.rules[fn.name] {
// Check whether fn.name is a rule or macro
if fileData.rulesOrMacros[fn.name] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's weird that we collect rules and macros in this list, but set report.isMacro to true. The description of this function says "whether the given function is a macro". You need to update the description, the field name and the function name, or split the rulesOrMacros list into 2, probably.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+1, in essence this comes from the history of this only being called externally on def statements, in which it was being used to determine whether the function implemented was a macro or not, but then recursively it was used on all calls, as a macro is defined as a function which calls a macro or a rule.

Updated all the isMacro references to be isRuleOrMacro

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Realized this comment was more related to this being a rule or not, and the update was related to handling calls to create symbolic macros... in hindsight this should probably go as a separate PR

"native-sh-binary": NativeShellRulesWarning("sh_binary"),
"native-sh-library": NativeShellRulesWarning("sh_library"),
"native-sh-test": NativeShellRulesWarning("sh_test"),
"positional-args": positionalArgumentsWarning,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity: why is this change needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The function definition of the previous is designed to run for a single Expr, this one is for the entire file

  • Previous one does not receive the full file as input
  • Previous one can only return a single finding.

- Previous implementation just assumed that macros were called at the root of a BUILD file, and that all calls were to macros/rules except for explicit allowlist. Updating the check to more precisely validate whether something is a rule/macro, and checking all call expressions (including ones nested in dicts/attrs).
- Also updating IsMacro implementation to correctly support symblic macro definitions (`my_macro = macro(...)`)
@oreflow oreflow merged commit 6c4b75d into main Sep 26, 2025
5 checks passed
@oreflow oreflow deleted the positional-args branch September 26, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants