Repository navigation
[beman-tidy] Implement cmake.no_single_use_vars - #359
Draft
neatudarius wants to merge 6 commits into
Draft
neatudarius wants to merge 6 commits into
neatudarius wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
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 ascmake.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.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The CMake check miscounts literal arguments as variable reads and misidentifies ordinary assignment values as modifiers, allowing single-use variables to pass undetected.
2 open issues
5 resolved since last review
PR metadata/Issue #177 calls out implementing both check() and fix() for cmake.no_single_use_vars,…set()supports case-insensitive keywords, but this check only skips variables when the arguments… For consistency with the other (skipped) fix_inplace tests above, add a brief docstring explaining… Other tests in this file include a short docstring describing the check under test; this new test… Other tests in this file include a short docstring describing the check under test; this new test…
Review effort: Balanced
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Implements #177