Skip to content

Do not report misplaced-load lint in WORKSPACE files#186

Open
abhinavgautam01 wants to merge 3 commits into
facebook:mainfrom
abhinavgautam01:fix/workspace-load-lint
Open

Do not report misplaced-load lint in WORKSPACE files#186
abhinavgautam01 wants to merge 3 commits into
facebook:mainfrom
abhinavgautam01:fix/workspace-load-lint

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Fixes #145.

Summary

This PR fixes a false-positive lint warning in Bazel workspace files.

misplaced-load currently warns when a load(...) is not at the top of a file.
That behavior is useful for normal Starlark files, but it is noisy for WORKSPACE / WORKSPACE.bazel, where repository setup calls may legitimately appear before
load(...).

Changes

  • Skip FlowIssue::MisplacedLoad for files named:
  • WORKSPACE
  • WORKSPACE.bazel
  • Keep existing misplaced-load behavior unchanged for all other files.
  • Add focused tests in starlark/src/analysis/flow.rs:
  • test_lint_misplaced_load_workspace
  • test_lint_misplaced_load_workspace_bazel

Validation

  • cargo test -p starlark test_lint_misplaced_load --lib
  • cargo clippy
  • cargo build
  • cargo test
  • cargo bench

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 2, 2026
@meta-codesync

meta-codesync Bot commented May 2, 2026

Copy link
Copy Markdown

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D103520777. (Because this pull request was imported automatically, there will not be any future comments.)

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

ping @ndmitchell

@JakobDegen

Copy link
Copy Markdown
Contributor

Baking this into the dialect-agnostic starlark doesn't really feel right.

First of all, what does the spec have to say about the placement of load statements, I thought they had to be at the top?

In any case, the appropriate way to do this would be to plumb it through properly and have the dialect report it among other interpreter-configuration settings in the evaluator (or somewhere similar)

@JakobDegen JakobDegen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

Comment thread starlark_syntax/src/dialect.rs
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Baking this into the dialect-agnostic starlark doesn't really feel right.

First of all, what does the spec have to say about the placement of load statements, I thought they had to be at the top?

In any case, the appropriate way to do this would be to plumb it through properly and have the dialect report it among other interpreter-configuration settings in the evaluator (or somewhere similar)

thanks, agreed. i moved this out of the dialect-agnostic flow lint path...

the misplaced-load lint now stays enabled by default via a new dialect setting, enable_load_after_statement: false, so standard Starlark behavior is unchanged. Bazel mode now opts into that setting only when parsing WORKSPACE or WORKSPACE.bazel, which keeps the WORKSPACE-specific exception in the Bazel dialect/configuration path rather than baking filename logic into the generic analyzer...

i also added tests for both sides:

  • generic flow lint respects the dialect flag
  • Bazel mode enables the flag for WORKSPACE/WORKSPACE.bazel and not BUILD.bazel

@JakobDegen JakobDegen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP: load statement not at the top of WORKSPACE file

2 participants