Skip to content

[beman-tidy] Implement cmake.no_single_use_vars - #359

Draft
neatudarius wants to merge 6 commits into
bemanproject:mainfrom
neatudarius:issue-177
Draft

neatudarius wants to merge 6 commits into
bemanproject:mainfrom
neatudarius:issue-177

Conversation

@neatudarius

@neatudarius neatudarius commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Implements #177

Copilot AI 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.

Pull request overview

Adds a new Beman Standard CMake check (cmake.no_single_use_vars) to flag set() variables that are referenced only once, along with pytest coverage and invalid CMake fixture inputs.

Changes:

  • Implement CMakeNoSingleUseVarsCheck.check() and register it as cmake.no_single_use_vars.
  • Add new tests covering valid/invalid cases for the new check.
  • Add invalid CMake fixture files demonstrating single-use set() variables.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
beman_tidy/lib/checks/beman_standard/cmake.py Adds the new cmake.no_single_use_vars check (and a currently-nonfunctional fix()).
tests/lib/checks/beman_standard/cmake/test_cmake.py Adds test coverage wiring for the new check (valid/invalid) and a skipped fix-inplace test.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-no_single_use_vars-v1.txt New invalid fixture demonstrating a single-use SOURCES variable.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-no_single_use_vars-v2.txt New invalid fixture demonstrating a single-use EXAMPLE_DIR variable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

# Conflicts:
#	beman_tidy/lib/checks/beman_standard/cmake.py
#	tests/lib/checks/beman_standard/cmake/test_cmake.py
Count bare-name uses such as if(VAR), skip CMake built-in variables and
variables set more than once, match SET() in any case, ignore comments.

Copilot AI 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.

Comment on lines +499 to +500
if arg.value == var_name and not (defines and index == 0):
references += 1
Comment on lines +512 to +514
upper_args = {arg.value.upper() for arg in command.args}
if "CACHE" in upper_args or "PARENT_SCOPE" in upper_args:
continue
CMake keywords are case-sensitive, so set(X cache) is a plain variable.
Also skip ENV{...} variables and cover list(APPEND)/foreach uses in tests.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants