Skip to content

Exclude sbt-git's own keys from sbt's lintUnused check - #406

Closed
jakubjanecek wants to merge 1 commit into
sbt:mainfrom
jakubjanecek:wip/exclude-lint-keys
Closed

Exclude sbt-git's own keys from sbt's lintUnused check#406
jakubjanecek wants to merge 1 commit into
sbt:mainfrom
jakubjanecek:wip/exclude-lint-keys

Conversation

@jakubjanecek

Copy link
Copy Markdown

Fixes #379.

Problem

GitPlugin 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 cannot see that, so it reports them as unused and points at GitPlugin.scala:

[warn] * ThisBuild / gitUncommittedChanges
[warn] * ThisBuild / scmInfo
[warn] * root / gitDescribedVersion

Worth noting why this only shows up for some builds: LintUnused only reports a candidate whose recorded position passes isLocallyDefined, i.e. some position's path contains a /. The released sbt-git 2.1.0 sbt-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 records LinePosition(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 globalSettings that appends the keys this plugin owns to Global / 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.

excludeLintKeys is preferred over withRank(KeyRanks.Invisible), which would also hide these user-facing keys from settings/inspect.

The list also covers gitRemoteRepo and gitBranch, which nothing in the plugin ever reads, so users who set them were being warned at too. scmInfo is included because the plugin is what sets it in buildSettings — that is the second warning in the issue.

Test

New scripted test src/sbt-test/lint/exclude-lint-keys sets git keys that nothing in the build consumes and asserts LintUnused.lintUnused reports none of the plugin's keys. Without the plugin change it fails with lintUnused reported sbt-git keys: gitRemoteRepo.

Verification

  • Reproduced the issue on sbt 2.0.0 with sbt-ci-release 1.12.1 and released sbt-git 2.1.0: the exact warnings for ThisBuild / gitUncommittedChanges and root / gitDescribedVersion; adding those labels to excludeLintKeys turns the run into [success] ok.
  • Locally published before/after builds in a scratch project: unfixed reports [baseVersion, useGitDescribe, gitRemoteRepo], fixed reports [] — on sbt 2.0.0 and on sbt 1.x, confirming plugin globalSettings are applied after sbt's own excludeLintKeys := … in both.
  • +compile, ++3.x test, scalafmtCheckAll / scalafmtSbtCheck, and ++3.x scripted lint/exclude-lint-keys pass locally. The sbt 1.x scripted suite could not be run locally (sbt 1.5.8 ships Scala 2.12.14, which fails with bad constant pool index on JDK 21/26 — pre-existing, existing tests fail identically), so CI covers that side.

🤖 Generated with Claude Code

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>
@jakubjanecek

Copy link
Copy Markdown
Author

Closing because it was found out the issue cannot be reproduced in the latest snapshot.

@jakubjanecek
jakubjanecek deleted the wip/exclude-lint-keys branch September 8, 2026 13:49
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.

sbt 2.x lintUnused warnings for plugin-defined keys

1 participant