Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Importantly, this API should _only_ be used when the offense is caused by the configuration handled by `EnforcedStyle`. Prior to this commit, this cop was inconsistent about when it called `correct_style_detected` on success and `opposite_style_detected` on failure. This means it would always output `EnforcedStyle: <some value>` during `--auto-gen-config` runs. 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 makes sure we always call `opposite_style_detected` when we call `add_offense`, and always call `correct_style_detected` when we don't detect an offense. Note, because this cop has separate style choices for braces with contents, `EnforcedStyle`, and empty braces without contents, `EnforcedStyleForEmptyBraces`, we also have to make sure to only call the `xxx_style_detected` methods when the offenses / passes are detected for the former as the API provided by `ConfigurableEnforcedStyle` only applies to `EnforcedStyle` config.
- Loading branch information