Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…Braces` The expected use of the API provided by `ConfigurableEnforcedStyle` is for the cop to call `correct_style_detected` if the cop detects no offense or to call one of the other `xxx_style_detected` api methods if it does detect an offense, and it should also call `add_offense` to register the offense. Doing this updates `config_to_allow_offenses` which is used during `--auto-gen-config` to decide how to configure the cop for the current code under review so that regardless of the styles used the code passes review. Prior to this commit, this cop called `correct_style_detected` correctly on success, but made several mistakes with calling `ambiguous_style_detected` or `unexpected_style_detected` on error. It treated these methods as predicates and wouldn't call `add_offense` if they returned `true` so the detected offenses would not be registered. It also passed the wrong `style` parameter to these methods - it passed the configured style from `EnforcedStyle` rather than the one detected by the offense. This means: 1. During a normal run the cop would not report all offenses detected in the whole code base under review. 2. During a `--auto-gen-config` run the cop would only ever output `EnforcedStyle: <some value>`. If the code under review actually has a mix of styles rather than a single consistent style then the generated config for this cop in `.rubocop_todo.yml` will not produce a passing review as instead of an exclusion list, or turning the cop off, it will only have the `EnforcedStyle: <some value>` config. This commit corrects both the errors: it passes the detected incorrect style when calling `ambiguous_style_detected` or `unexpected_style_detected` and always calls `add_offense` instead of treating the return value of `ambiguous_style_detected` or `unexpected_style_detected` as a predicate to decide if it should or not.
- Loading branch information