feat(lint): add --fix option to auto-remove unused locals#58
Merged
julienduchesne merged 1 commit intomasterfrom Feb 27, 2026
Merged
feat(lint): add --fix option to auto-remove unused locals#58julienduchesne merged 1 commit intomasterfrom
julienduchesne merged 1 commit intomasterfrom
Conversation
Add a --fix flag to both `rtk lint` and the standalone `jrsonnet-lint` binary. For the unused_locals check, the fix removes the entire local statement (for single-bind statements) or the object local member, including surrounding whitespace and trailing commas. Multi-bind statements (local x = 1, y = 2;) are not auto-fixed since partial removal would require more complex AST surgery. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Benchmark Results
Full results available in workflow artifacts. Benchmark run on commit |
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.
Summary
--fixflag tortk lintand the standalonejrsonnet-lintbinaryunused_localscheck, the fix automatically removes the offending local statement from the source fileDiagnosticvia a newFixstructapply_fixespublic function injrsonnet-lintapplies all fixes to a source string (in reverse offset order to preserve positions)How it works
localstatements (local x = 1;): the entire statement is removed, including surrounding whitespace and trailing newlinelocal x = 1,inside{}): the member is removed, including surrounding whitespace and the trailing commalocal x = 1, y = 2;): no auto-fix (would require partial AST surgery); these are still reported as diagnostics--fixis used, any diagnostics without a fix are still reported and cause a non-zero exitTest plan
cargo test -p jrsonnet-lint— 30 tests pass (4 new tests forapply_fixes)make test— full suite passesrtk lint --fix <dir>rewrites files in placejrsonnet-lint --fix <file>rewrites file in placejrsonnet-lint --fix -(stdin) warns and reports diagnostics normally🤖 Generated with Claude Code