diff --git a/changelog/change_disable_style_yoda_expression_by_default.md b/changelog/change_disable_style_yoda_expression_by_default.md new file mode 100644 index 000000000000..cb5a302ec6cd --- /dev/null +++ b/changelog/change_disable_style_yoda_expression_by_default.md @@ -0,0 +1 @@ +* [#11380](https://github.com/rubocop/rubocop/pull/11380): Disable `Style/YodaExpression` by default. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 8f9c00a3a7a5..2a807d37056e 100644 --- a/config/default.yml +++ b/config/default.yml @@ -5440,9 +5440,10 @@ Style/YodaCondition: Style/YodaExpression: Description: 'Forbid the use of yoda expressions.' - Enabled: pending + Enabled: false Safe: false VersionAdded: '1.42' + VersionChanged: '<>' SupportedOperators: - '*' - '+' diff --git a/lib/rubocop/cop/style/yoda_expression.rb b/lib/rubocop/cop/style/yoda_expression.rb index 84a9de55c399..9c60672df06c 100644 --- a/lib/rubocop/cop/style/yoda_expression.rb +++ b/lib/rubocop/cop/style/yoda_expression.rb @@ -7,6 +7,13 @@ module Style # and `^` operators) where the order of expression is reversed, eg. `1 + x`. # This cop complements `Style/YodaCondition` cop, which has a similar purpose. # + # This cop is disabled by default to respect user intentions such as: + # + # [source,ruby] + # ---- + # config.server_port = 9000 + ENV["TEST_ENV_NUMBER"].to_i + # ---- + # # @safety # This cop is unsafe because binary operators can be defined # differently on different classes, and are not guaranteed to