rubocop-socketry 0.8.0 → 0.10.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: 0dacbb6af420eedc76cec483085c0bac470416faf318a2ddaee52980c3a43f59
4
- data.tar.gz: 4f128fdca62a037f273ee0ab534446e08df7b97bd578b6ca50f287f3f63e8d43
3
+ metadata.gz: 36f3f182b831bb4fbae7b9eddb5504cecb05d10616de4b25307d83baa9e578e1
4
+ data.tar.gz: a12e31b5ad9834c890ecc20afd9d443ba0b6a760078ee4a5550e63b731e45c4e
5
5
  SHA512:
6
- metadata.gz: b87895050fdfd00301e6f3f33bd742f87f6ffcc46963f33f33df285e7f8d3e9079b24fb6be8aee2352c697df1d36d7fddf9cca90e9453da047b3fad2cd5208ab
7
- data.tar.gz: 0b21c56b058e9a97716e37846c52238afb798d5b584f6920820706aa93e11b41a5f1e5258b5171d7842c943916d9b93b53b9674e4c4a0f1e9fd016f2d7ba9839
6
+ metadata.gz: ffe0bfaa3a740753d590f0852f87374976c0a76e931d0184f63fc553f37a4c5547838d6ab1103f658fecdc4cc3c2a7c30502e813f7987e0dad25d3f4e86ac74f
7
+ data.tar.gz: c1b77f49c5bdb0fee928666a1f9436b37ae2d38f35cc17fc5aa274034cd61a31002d7435caf9d4e308fe49ed871e28987d3a9355a255c00c9ec1c06047d4afbe
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2025-2026, by Samuel Williams.
4
+ # Copyright, 2025, by Samuel Williams.
5
5
 
6
6
  require "rubocop"
7
7
 
@@ -81,28 +81,30 @@ module RuboCop
81
81
 
82
82
  # Check if the block is part of an expression (not a top-level statement)
83
83
  # Top-level statements are directly inside a :begin node (file/method body)
84
- # or inside do...end block bodies, and should have space.
85
- # Everything else (expressions, nested arguments, etc.) should not have space.
84
+ # and should have space. Everything else (expressions, nested blocks) should not.
86
85
  def part_of_expression?(node)
87
86
  parent = node.parent
88
87
  return false unless parent
89
88
 
90
- # If parent is a :begin node (sequence of statements), this is top-level
91
- return false if parent.type == :begin
92
-
93
- # If parent is a :block node, check if it's a do...end block
94
- # do...end blocks contain statements (no space)
95
- # {...} blocks contain expressions (space required)
96
- if parent.type == :block
97
- # do...end blocks use keywords, {...} blocks use braces
98
- return false unless parent.braces?
89
+ case parent.type
90
+ when :begin
91
+ # Sequence of statements — this is a top-level statement.
92
+ false
93
+ when :block, :numblock
94
+ # When a block is the sole body statement of an outer block there is no
95
+ # :begin wrapper; the outer block node is the direct parent.
96
+ # Only the body slot counts as a statement context, and only when the
97
+ # outer block itself spans multiple lines (e.g. a do…end describe/context
98
+ # block). Single-line inline blocks (`foo {bar{baz}}`) keep their
99
+ # compact style.
100
+ parent.body == node ? !parent.multiline? : true
101
+ when :def, :defs, :class, :module, :sclass
102
+ # Same situation for method / class / module bodies with a single
103
+ # statement — they are always multi-line in practice.
104
+ parent.body != node
105
+ else
106
+ true
99
107
  end
100
-
101
- # Check if we're in a :kwbegin node (begin...end block body)
102
- return false if parent.type == :kwbegin
103
-
104
- # Otherwise, it's part of an expression (assignment, argument, etc.)
105
- true
106
108
  end
107
109
 
108
110
  # Check that there's no space before the opening brace for lambdas
@@ -61,6 +61,7 @@ module RuboCop
61
61
  # Check blank lines for correct indentation:
62
62
  if line.strip.empty?
63
63
  expected_indentation = indentation(current_level)
64
+
64
65
  if line != expected_indentation
65
66
  add_offense(
66
67
  source_range(processed_source.buffer, line_number, 0, line.length),
@@ -84,9 +85,13 @@ module RuboCop
84
85
  # This method walks the AST to identify where indentation should increase or decrease.
85
86
  # @returns [Hash(Integer, Integer)] A hash where keys are line numbers and values are deltas.
86
87
  def build_indentation_deltas
87
- deltas = Hash.new(0)
88
- walk_ast_for_indentation(processed_source.ast, deltas)
89
- deltas
88
+ Hash.new(0).tap do |deltas|
89
+ walk_ast_for_indentation(processed_source.ast, deltas)
90
+
91
+ # Cap deltas to a maximum of +1 or -1 per line to handle cases where
92
+ # multiple structures open/close on the same line (e.g., `[..., {`)
93
+ deltas.transform_values!{|delta| delta.nil? ? nil : delta.clamp(-1, 1)}
94
+ end
90
95
  end
91
96
 
92
97
  STRUCTURAL_NODES = [:array, :hash, :class, :module, :sclass, :def, :defs, :if, :if, :while, :until, :for, :case, :kwbegin, :regexp]
@@ -5,6 +5,6 @@
5
5
 
6
6
  module RuboCop
7
7
  module Socketry
8
- VERSION = "0.8.0"
8
+ VERSION = "0.10.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -27,6 +27,16 @@ Layout/ConsistentBlankLineIndentation:
27
27
 
28
28
  Please see the [project releases](https://socketry.github.io/rubocop-socketry/releases/index) for all releases.
29
29
 
30
+ ### v0.10.0
31
+
32
+ - Fixed `Layout/BlockDelimiterSpacing` to correctly treat a block as a statement (requiring space before `{`) when it is the sole body of a multi-line outer block or method/class/module definition. Previously, the absence of a `:begin` wrapper in the AST caused such blocks (e.g. `Async {foo}` or `let(:bar) {baz}` inside a `describe`/`context` block) to be misclassified as expression-context and have their space incorrectly removed.
33
+ - Single-line inline outer blocks (e.g. `foo {bar{baz}}`) continue to use compact style with no space before the inner brace.
34
+
35
+ ### v0.9.0
36
+
37
+ - Fixed `Layout/ConsistentBlankLineIndentation` to correctly handle files containing multiple blocks.
38
+ - Expanded `Layout/BlockDelimiterSpacing` test coverage to include method chaining scenarios.
39
+
30
40
  ### v0.8.0
31
41
 
32
42
  - Fixed `Layout/BlockDelimiterSpacing` to correctly distinguish between statement and expression contexts for blocks inside `do...end` blocks.
data/releases.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Releases
2
2
 
3
+ ## v0.10.0
4
+
5
+ - Fixed `Layout/BlockDelimiterSpacing` to correctly treat a block as a statement (requiring space before `{`) when it is the sole body of a multi-line outer block or method/class/module definition. Previously, the absence of a `:begin` wrapper in the AST caused such blocks (e.g. `Async {foo}` or `let(:bar) {baz}` inside a `describe`/`context` block) to be misclassified as expression-context and have their space incorrectly removed.
6
+ - Single-line inline outer blocks (e.g. `foo {bar{baz}}`) continue to use compact style with no space before the inner brace.
7
+
8
+ ## v0.9.0
9
+
10
+ - Fixed `Layout/ConsistentBlankLineIndentation` to correctly handle files containing multiple blocks.
11
+ - Expanded `Layout/BlockDelimiterSpacing` test coverage to include method chaining scenarios.
12
+
3
13
  ## v0.8.0
4
14
 
5
15
  - Fixed `Layout/BlockDelimiterSpacing` to correctly distinguish between statement and expression contexts for blocks inside `do...end` blocks.
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.8.0
4
+ version: 0.10.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: 4.0.3
106
+ rubygems_version: 4.0.6
107
107
  specification_version: 4
108
108
  summary: RuboCop rules for Socketry projects
109
109
  test_files: []
metadata.gz.sig CHANGED
Binary file