Exclude sbt-git's own keys from sbt's lintUnused check - #406
Closed
jakubjanecek wants to merge 1 commit into
Closed
Conversation
The plugin sets a number of keys eagerly in buildSettings/projectSettings
that a build only consumes when git versioning is enabled, or that are read
by commands rather than by other settings. sbt's `lintUnused` check has no
way to see that, so it reports them as unused and points at GitPlugin.scala:
[warn] * ThisBuild / gitUncommittedChanges
[warn] * ThisBuild / scmInfo
[warn] * root / gitDescribedVersion
Add `globalSettings` that append the keys this plugin owns to
`Global / excludeLintKeys`, so builds are warning free out of the box. The
exclusion matches on key label, which keeps it independent of the scope a
key ends up in and of the source positions baked into the published plugin.
`excludeLintKeys` is preferred over `withRank(KeyRanks.Invisible)` because
the latter would also hide these user-facing keys from `settings`/`inspect`.
Add a scripted test that sets git keys nothing consumes and asserts that
`lintUnused` reports none of the plugin's keys.
Fixes sbt#379
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Author
|
Closing because it was found out the issue cannot be reproduced in the latest snapshot. |
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.
Fixes #379.
Problem
GitPluginsets a number of keys eagerly inbuildSettings/projectSettingsthat a build only consumes when git versioning is enabled, or that are read by commands rather than by other settings. sbt'slintUnusedcheck cannot see that, so it reports them as unused and points atGitPlugin.scala:Worth noting why this only shows up for some builds:
LintUnusedonly reports a candidate whose recorded position passesisLocallyDefined, i.e. some position'spathcontains a/. The releasedsbt-git 2.1.0sbt-2 artifact recorded positions whose "path" is the setting's source text (ThisBuild / gitUncommittedChanges := …), which contains a/and therefore passes; a rebuild of the same source with sbt 2.0.0 today recordsLinePosition(GitPlugin.scala, 135)and the keys silently pass instead. So the warnings can appear and disappear across releases, and the fix should not depend on that.Fix
Add
globalSettingsthat appends the keys this plugin owns toGlobal / excludeLintKeys. The exclusion matches on key label, so it is independent of the scope a key ends up in and of the positions baked into the published plugin.excludeLintKeysis preferred overwithRank(KeyRanks.Invisible), which would also hide these user-facing keys fromsettings/inspect.The list also covers
gitRemoteRepoandgitBranch, which nothing in the plugin ever reads, so users who set them were being warned at too.scmInfois included because the plugin is what sets it inbuildSettings— that is the second warning in the issue.Test
New scripted test
src/sbt-test/lint/exclude-lint-keyssets git keys that nothing in the build consumes and assertsLintUnused.lintUnusedreports none of the plugin's keys. Without the plugin change it fails withlintUnused reported sbt-git keys: gitRemoteRepo.Verification
ThisBuild / gitUncommittedChangesandroot / gitDescribedVersion; adding those labels toexcludeLintKeysturns the run into[success] ok.[baseVersion, useGitDescribe, gitRemoteRepo], fixed reports[]— on sbt 2.0.0 and on sbt 1.x, confirming pluginglobalSettingsare applied after sbt's ownexcludeLintKeys := …in both.+compile,++3.x test,scalafmtCheckAll/scalafmtSbtCheck, and++3.x scripted lint/exclude-lint-keyspass locally. The sbt 1.x scripted suite could not be run locally (sbt 1.5.8 ships Scala 2.12.14, which fails withbad constant pool indexon JDK 21/26 — pre-existing, existing tests fail identically), so CI covers that side.🤖 Generated with Claude Code