rubocop-socketry 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 199a4f2c374f6e452459742724b7ba8ba9b0e9d9859ddf4ae12172a95e033bd9
4
- data.tar.gz: ddc2c5a20e4b7181b1cdc0d07c53f85dc7acabb9ea4681616e3000292b45496f
3
+ metadata.gz: 3bdf0fc2d1db810ae5d2bb5d15895f763062e83a4cff437e17f9707b4f9f7d27
4
+ data.tar.gz: f615231a3fa949865a21623f160195da22ad401e2198db990a5ebffa9554dea4
5
5
  SHA512:
6
- metadata.gz: f04815a61b6651a7c4325967a9d193ade2ecb85800cb3ef816afed0a0f51d5849ab8a3aeb758474b93a8927b7fd984826f983749a9ff4824a0cf5beba1d72d95
7
- data.tar.gz: 6b255a3e77c44782ea801bc3de112411896f9395ab0b78191998b8a064528a29cbca77bc50be56223f68c1b2df2e1155332f3985fd6e62bc935f5850a7b91553
6
+ metadata.gz: aa0b76dd902e2bbfc9409a54c242b15912cc850c9c2a3f26618adedc5a6275eb0d2c690eb224b23f0fbe620e777f2f0efbf0c58a3d7c2d7e324e233323e736d7
7
+ data.tar.gz: 40c8ad00c40ee7619c6f3f9ccf3e22bd5a4a71c1920683c326a21a80cd90620bb4f34acaeabe469c01991e4ee304e38aed89381fb05a2a7b66652e50bee9a0ff
checksums.yaml.gz.sig CHANGED
Binary file
@@ -11,19 +11,21 @@ module RuboCop
11
11
  # A RuboCop cop that enforces consistent spacing before block delimiters.
12
12
  #
13
13
  # This cop enforces the following style:
14
- # - `foo {bar}` - space when method has no parentheses and is not chained
15
- # - `foo(1, 2) {bar}` - space after closing paren for standalone methods
16
- # - `array.each{|x| x*2}.reverse` - no space for method chains (even with parens)
17
- # - `->(foo){foo}` - no space for lambdas (stabby lambda syntax)
18
- # - `lambda{foo}` - no space for lambda keyword
19
- # - `proc{foo}` - no space for proc keyword
20
- # - `Proc.new{foo}` - no space for Proc.new
14
+ # - `foo {bar}` - space for top-level statements without parentheses.
15
+ # - `x = foo{bar}` - no space when part of an expression (assignment, argument, etc).
16
+ # - `foo(1, 2) {bar}` - space after closing paren for top-level statements.
17
+ # - `array.each{|x| x*2}.reverse` - no space for method chains.
18
+ # - `->(foo){foo}` - no space for lambdas (stabby lambda syntax).
19
+ # - `lambda{foo}` - no space for lambda keyword.
20
+ # - `proc{foo}` - no space for proc keyword.
21
+ # - `Proc.new{foo}` - no space for `Proc.new`.
21
22
  class BlockDelimiterSpacing < RuboCop::Cop::Base
22
23
  extend Cop::AutoCorrector
23
24
 
24
25
  MSG_ADD_SPACE = "Add a space before the opening brace."
25
26
  MSG_REMOVE_SPACE = "Remove space before the opening brace for method chains."
26
27
  MSG_REMOVE_SPACE_LAMBDA = "Remove space before the opening brace for lambdas/procs."
28
+ MSG_REMOVE_SPACE_EXPRESSION = "Remove space before the opening brace for expressions."
27
29
 
28
30
  def on_block(node)
29
31
  return unless node.braces?
@@ -44,6 +46,12 @@ module RuboCop
44
46
  # array.each{|x| x*2}.reverse - no space
45
47
  # obj.method(1, 2){|x| x}.other - also no space
46
48
  check_no_space_before_brace(node, send_node)
49
+ # Priority 3: Check if it's part of an expression (not top-level)
50
+ # Blocks within expressions should have no space
51
+ elsif part_of_expression?(node)
52
+ # x = Async{server.run} - no space (part of assignment)
53
+ # foo(bar{baz}) - no space (part of argument)
54
+ check_no_space_for_expression(node, send_node)
47
55
  elsif has_parentheses?(send_node)
48
56
  # foo(1, 2) {bar} - space after ) for standalone methods
49
57
  check_space_after_parentheses(node, send_node)
@@ -71,6 +79,18 @@ module RuboCop
71
79
  false
72
80
  end
73
81
 
82
+ # Check if the block is part of an expression (not a top-level statement)
83
+ # Top-level statements are directly inside a :begin node (file/method body)
84
+ # and should have space. Everything else (expressions, nested blocks) should not.
85
+ def part_of_expression?(node)
86
+ parent = node.parent
87
+ return false unless parent
88
+
89
+ # If parent is a :begin node (sequence of statements), this is top-level
90
+ # Otherwise, it's part of an expression or nested context
91
+ parent.type != :begin
92
+ end
93
+
74
94
  # Check that there's no space before the opening brace for lambdas
75
95
  def check_no_space_for_lambda(block_node, send_node)
76
96
  brace_begin = block_node.loc.begin
@@ -105,6 +125,40 @@ module RuboCop
105
125
  end
106
126
  end
107
127
 
128
+ # Check that there's no space before the opening brace for expressions
129
+ def check_no_space_for_expression(block_node, send_node)
130
+ brace_begin = block_node.loc.begin
131
+
132
+ # Find the position just before the brace
133
+ char_before_pos = brace_begin.begin_pos - 1
134
+
135
+ return if char_before_pos < 0
136
+
137
+ char_before = processed_source.buffer.source[char_before_pos]
138
+
139
+ # If there's no space before the brace, we're good
140
+ return unless char_before == " "
141
+
142
+ # Find the extent of whitespace before the brace
143
+ start_pos = char_before_pos
144
+ while start_pos > 0 && processed_source.buffer.source[start_pos - 1] =~ /\s/
145
+ start_pos -= 1
146
+ end
147
+
148
+ space_range = Parser::Source::Range.new(
149
+ processed_source.buffer,
150
+ start_pos,
151
+ brace_begin.begin_pos
152
+ )
153
+
154
+ add_offense(
155
+ space_range,
156
+ message: MSG_REMOVE_SPACE_EXPRESSION
157
+ ) do |corrector|
158
+ corrector.remove(space_range)
159
+ end
160
+ end
161
+
108
162
  # Check if the block is part of a method chain (e.g., foo{}.bar or foo.bar{}.baz)
109
163
  def part_of_method_chain?(block_node)
110
164
  send_node = block_node.send_node
@@ -5,6 +5,6 @@
5
5
 
6
6
  module RuboCop
7
7
  module Socketry
8
- VERSION = "0.6.1"
8
+ VERSION = "0.7.0"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-socketry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.6.9
106
+ rubygems_version: 4.0.3
107
107
  specification_version: 4
108
108
  summary: RuboCop rules for Socketry projects
109
109
  test_files: []
metadata.gz.sig CHANGED
Binary file