Support float maximum_decrease and rename YAML key#577
Open
siklodi-mariusz wants to merge 1 commit into
Open
Conversation
threshold_score was coerced to an integer in argv.rb (Integer(...)) and configuration.rb (.to_i), so the smallest non-zero tolerance was a full point. Its sibling minimum_score — the same kind of 2-decimal score value — is already coerced as a float. Make threshold_score consistent by parsing it as a float (Float(...) / .to_f), so values like 0.5 work. Also rename the YAML config key from to to match the existing CLI flag. The legacy key still works but emits a deprecation warning; when both keys are present, takes precedence. The internal Config.threshold_score attribute is left as-is to limit churn.
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.
What & why
This PR makes two related, backward-compatible changes to the score-decrease threshold used in compare mode (
-b <branch>), which fails a build when a feature branch's score drops too far below the base branch.1. Accept float values for the threshold
threshold_scorewas coerced to an integer in two places, so the smallest non-zero tolerance was a full point — you couldn't express0.5or0.05:lib/rubycritic/cli/options/argv.rb:Integer(threshold_score)lib/rubycritic/configuration.rb:options[:threshold_score].to_iThis was arbitrary and inconsistent: the sibling
minimum_score— the same kind of value, a 2-decimal code-quality score — is already coerced as a float in the same files. The comparison incompare.rbalready doesFloat > Float, so nothing downstream required a whole number.This PR mirrors
minimum_score:argv.rb:Integer(...)→Float(...)configuration.rb:.to_i→.to_fSo
--maximum-decrease 0.5(ormaximum_decrease: 0.5in YAML) now works as expected.2. Rename the YAML key to match the CLI flag
The same setting had two different names on the two surfaces:
--maximum-decreasethreshold_scoreThe YAML key is renamed to
maximum_decreaseso it matches the flag. This is backward compatible:maximum_decrease:is the new canonical key.threshold_score:key still works but emits a deprecation warning (viaKernel#warn) telling users to switch.maximum_decreasekey wins.The internal
Config.threshold_scoreattribute is intentionally left named as-is to limit churn — only the user-facing YAML key changed.Docs
--maximum-decreasefootnote now notes FLOAT support, and the.rubycritic.ymlexample usesmaximum_decrease.