Skip to content

Support float maximum_decrease and rename YAML key#577

Open
siklodi-mariusz wants to merge 1 commit into
whitesmith:mainfrom
siklodi-mariusz:float-maximum-decrease
Open

Support float maximum_decrease and rename YAML key#577
siklodi-mariusz wants to merge 1 commit into
whitesmith:mainfrom
siklodi-mariusz:float-maximum-decrease

Conversation

@siklodi-mariusz

Copy link
Copy Markdown

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_score was coerced to an integer in two places, so the smallest non-zero tolerance was a full point — you couldn't express 0.5 or 0.05:

  • lib/rubycritic/cli/options/argv.rb: Integer(threshold_score)
  • lib/rubycritic/configuration.rb: options[:threshold_score].to_i

This 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 in compare.rb already does Float > Float, so nothing downstream required a whole number.

This PR mirrors minimum_score:

  • argv.rb: Integer(...)Float(...)
  • configuration.rb: .to_i.to_f

So --maximum-decrease 0.5 (or maximum_decrease: 0.5 in 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:

  • CLI flag: --maximum-decrease
  • YAML key: threshold_score

The YAML key is renamed to maximum_decrease so it matches the flag. This is backward compatible:

  • maximum_decrease: is the new canonical key.
  • The legacy threshold_score: key still works but emits a deprecation warning (via Kernel#warn) telling users to switch.
  • When both keys are present, the new maximum_decrease key wins.

The internal Config.threshold_score attribute is intentionally left named as-is to limit churn — only the user-facing YAML key changed.

Docs

  • README: the --maximum-decrease footnote now notes FLOAT support, and the .rubycritic.yml example uses maximum_decrease.
  • CHANGELOG entries for both changes.

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.
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.

1 participant