Skip to content

Commit aee64e2

Browse files
pawelmabbatsov
authored andcommitted
Rename new SupportedShorthandSyntax from consistent_either to either_consistent
This will indicate that it works like `either` option which contains a consistency within a single hash definition. Suggested in #12904 (comment) PR comment
1 parent 86b0c39 commit aee64e2

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* [#12904](https://github.com/rubocop/rubocop/pull/12904): Add new `consistent_either` `SupportedShorthandSyntax` to `Style/HashSyntax`. ([@pawelma][])
1+
* [#12904](https://github.com/rubocop/rubocop/pull/12904): Add new `either_consistent` `SupportedShorthandSyntax` to `Style/HashSyntax`. ([@pawelma][])

config/default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4070,7 +4070,7 @@ Style/HashSyntax:
40704070
# forces use of the 3.1 syntax only if all values can be omitted in the hash.
40714071
- consistent
40724072
# allow either (implicit or explicit) syntax but enforce consistency within a single hash
4073-
- consistent_either
4073+
- either_consistent
40744074
# Force hashes that have a symbol value to use hash rockets
40754075
UseHashRocketsWithSymbolValues: false
40764076
# Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style

lib/rubocop/cop/mixin/hash_shorthand_syntax.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ def register_offense(node, message, replacement) # rubocop:disable Metrics/AbcSi
6868

6969
def ignore_mixed_hash_shorthand_syntax?(hash_node)
7070
target_ruby_version <= 3.0 ||
71-
!%w[consistent consistent_either].include?(enforced_shorthand_syntax) ||
71+
!%w[consistent either_consistent].include?(enforced_shorthand_syntax) ||
7272
!hash_node.hash_type?
7373
end
7474

7575
def ignore_hash_shorthand_syntax?(pair_node)
7676
target_ruby_version <= 3.0 || enforced_shorthand_syntax == 'either' ||
77-
%w[consistent consistent_either].include?(enforced_shorthand_syntax) ||
77+
%w[consistent either_consistent].include?(enforced_shorthand_syntax) ||
7878
!pair_node.parent.hash_type?
7979
end
8080

@@ -175,7 +175,7 @@ def hash_with_values_that_cant_be_omitted?(hash_value_type_breakdown)
175175

176176
def ignore_explicit_omissible_hash_shorthand_syntax?(hash_value_type_breakdown)
177177
hash_value_type_breakdown.keys == [:value_omittable] &&
178-
enforced_shorthand_syntax == 'consistent_either'
178+
enforced_shorthand_syntax == 'either_consistent'
179179
end
180180

181181
def each_omitted_value_pair(hash_value_type_breakdown, &block)

lib/rubocop/cop/style/hash_syntax.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module Style
2929
# * never - forces use of explicit hash literal value
3030
# * either - accepts both shorthand and explicit use of hash literal value
3131
# * consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash
32-
# * consistent_either - accepts both shorthand and explicit use of hash literal value,
32+
# * either_consistent - accepts both shorthand and explicit use of hash literal value,
3333
# but they must be consistent
3434
#
3535
# @example EnforcedStyle: ruby19 (default)
@@ -112,7 +112,7 @@ module Style
112112
# # good - can't omit `baz`
113113
# {foo: foo, bar: baz}
114114
#
115-
# @example EnforcedShorthandSyntax: consistent_either
115+
# @example EnforcedShorthandSyntax: either_consistent
116116
#
117117
# # good - `foo` and `bar` values can be omitted, but they are consistent, so it's accepted
118118
# {foo: foo, bar: bar}

spec/rubocop/cli/auto_gen_config_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
15001500
.to eq(<<~YAML)
15011501
# Configuration parameters: EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
15021502
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
1503-
# SupportedShorthandSyntax: always, never, either, consistent, consistent_either
1503+
# SupportedShorthandSyntax: always, never, either, consistent, either_consistent
15041504
Style/HashSyntax:
15051505
EnforcedStyle: hash_rockets
15061506
YAML
@@ -1514,7 +1514,7 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
15141514
.to eq(<<~YAML)
15151515
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
15161516
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
1517-
# SupportedShorthandSyntax: always, never, either, consistent, consistent_either
1517+
# SupportedShorthandSyntax: always, never, either, consistent, either_consistent
15181518
Style/HashSyntax:
15191519
Exclude:
15201520
- 'example1.rb'
@@ -1531,7 +1531,7 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
15311531
.to eq(<<~YAML)
15321532
# Configuration parameters: EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
15331533
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
1534-
# SupportedShorthandSyntax: always, never, either, consistent, consistent_either
1534+
# SupportedShorthandSyntax: always, never, either, consistent, either_consistent
15351535
Style/HashSyntax:
15361536
Exclude:
15371537
- 'example1.rb'
@@ -1546,7 +1546,7 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
15461546
.to eq(<<~YAML)
15471547
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
15481548
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
1549-
# SupportedShorthandSyntax: always, never, either, consistent, consistent_either
1549+
# SupportedShorthandSyntax: always, never, either, consistent, either_consistent
15501550
Style/HashSyntax:
15511551
Exclude:
15521552
- 'example1.rb'
@@ -1583,7 +1583,7 @@ def function(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
15831583
.to eq(<<~YAML)
15841584
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
15851585
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
1586-
# SupportedShorthandSyntax: always, never, either, consistent, consistent_either
1586+
# SupportedShorthandSyntax: always, never, either, consistent, either_consistent
15871587
Style/HashSyntax:
15881588
Exclude:
15891589
- 'example1.rb'

spec/rubocop/cop/style/hash_syntax_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ def buz(foo:, bar:); end
16831683
{
16841684
'EnforcedStyle' => 'ruby19',
16851685
'SupportedStyles' => %w[ruby19 hash_rockets],
1686-
'EnforcedShorthandSyntax' => 'consistent_either'
1686+
'EnforcedShorthandSyntax' => 'either_consistent'
16871687
}
16881688
end
16891689

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy