super-slim 3.4.0 → 3.4.1

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: d9189c83ed4be022cdc4c2a3bd54f130e6fe66826811fa47c15149a72dc04419
4
- data.tar.gz: 63648f18984eb4fe426be14a8af378c94703ae4e02793fadd4182608531db72f
3
+ metadata.gz: dc9a3f9a78ca93e94080ea623bc6f9a3a52e184148488861b81b53118d1a794a
4
+ data.tar.gz: ee5e380942cf49f07d8346d7901b4e13b51a5a992a7b5715dc4e4de73a207829
5
5
  SHA512:
6
- metadata.gz: 635a722ab669d1e1f3410592759c5a3055ebaead833178884a848e3bfbcf1cd2af5044c8cd33e5974cf8c17607e1ffde37bc3fb5ae21d282b6337da3f240e049
7
- data.tar.gz: 505ca7cbfdf29e34a6ba0ef46ccb981066ae72e0321a0bf442428b6965f99b20cf247a4bafa10271c533fa6d52144d0d28949bc7eecc918e4f2bda6fc1379249
6
+ metadata.gz: 6597c277f4ab79f1c662e45bc705e0a7ede102ebd391b1cf5a130924735c78d7de9df6089f777c6b7179f767af39f0b5f9ef64df1693ed26c6316dc35374a4e9
7
+ data.tar.gz: 6f6ccfc27211da2295ed4273e10b84a867f18c1763d73c583e4f71fe90a15a837d8496fc174145bda5de14aabe71f84d0dc1faebb7b76536d6460c846497703e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [3.4.1] — 2026-11-07
6
+
7
+ One fix: `super-slim format` no longer writes `-` lines that `super-slim lint` flags.
8
+
9
+ **Fixed**
10
+ - `super-slim format` no longer turns a one- or two-line `ruby:` block into `-` lines that make three in a row with
11
+ the ones around it, which ConsecutiveControlStatements then flagged and a format-then-lint commit hook refused.
12
+ `#{}` in a string no longer keeps a line out of a `ruby:` block.
13
+
5
14
  ## [3.4.0] — 2026-11-07
6
15
 
7
16
  One layout for inline tags, short children, `ruby:` blocks and negated conditions.
@@ -238,7 +247,8 @@ renders what Slim 5 renders with `format: :html, sort_attrs: false`, byte for by
238
247
  - Ruby 3.3 or later, every Ruby still maintained, Rails 8.0 or 8.1 for the railtie, and strscan 3.1.1 or later,
239
248
  newer than the one Ruby 3.3 ships.
240
249
 
241
- [Unreleased]: https://github.com/levups/super-slim/compare/v3.4.0...HEAD
250
+ [Unreleased]: https://github.com/levups/super-slim/compare/v3.4.1...HEAD
251
+ [3.4.1]: https://github.com/levups/super-slim/compare/v3.4.0...v3.4.1
242
252
  [3.4.0]: https://github.com/levups/super-slim/compare/v3.3.0...v3.4.0
243
253
  [3.3.0]: https://github.com/levups/super-slim/compare/v3.2.2...v3.3.0
244
254
  [3.2.2]: https://github.com/levups/super-slim/compare/v3.2.1...v3.2.2
@@ -23,6 +23,7 @@ module SuperSlim
23
23
  CONTROL_CODE = /\A\s*-\s*(\S.*)/
24
24
  # The threshold of the ConsecutiveControlStatements lint rule, plus one.
25
25
  RUBY_BLOCK_MIN_LINES = 3
26
+ SKIPPED_KINDS = %i[blank continuation].freeze
26
27
  RUBY_BLOCK = /\A\s*ruby:\s*\z/
27
28
  CONTROL_RUN = /^( *)- .*\n\1- .*\n\1- /
28
29
  # `while x do` is valid Ruby that nobody writes.
@@ -227,6 +228,7 @@ module SuperSlim
227
228
  # `format off` keeps its lines as written.
228
229
  code_units.reject! { |first_lineno, last_lineno| (first_lineno..last_lineno).any? { unformatted_linenos.include?(_1) } }
229
230
  runs = code_units.sort_by!(&:first).chunk_while { |unit, next_unit| next_unit[0] == unit[1] + 1 && next_unit[2] == unit[2] }
231
+ flat_control_linenos = parser.line_by_node.filter_map { |node, lineno| lineno if node.is_a?(AST::Control) && AST.empty?(node.children) }.to_set
230
232
  code_lines_by_lineno = {}
231
233
  rewritten_linenos = Set.new
232
234
  runs.each do |run|
@@ -241,6 +243,8 @@ module SuperSlim
241
243
  ruby_block = code.size >= RUBY_BLOCK_MIN_LINES
242
244
  layout_changes = ruby_block || units.any? { _1[0] != _1[1] }
243
245
  next unless parsable && layout_changes
246
+ # `-` lines the run can't take, a comment or code going on below, still count for ConsecutiveControlStatements.
247
+ next if !ruby_block && code.size + flat_controls_beside(units, outline, flat_control_linenos) >= RUBY_BLOCK_MIN_LINES
244
248
 
245
249
  code_lines_by_lineno[units.first[0]] = ruby_block ? ["ruby:", *code.map { (" " * INDENT_WIDTH) + _1 }] : code.map { "- #{_1}" }
246
250
  rewritten_linenos.merge((units.first[0] + 1)..units.last[1])
@@ -249,6 +253,18 @@ module SuperSlim
249
253
  [code_lines_by_lineno, rewritten_linenos]
250
254
  end
251
255
 
256
+ # The `-` lines with no children right before and after the units, at their depth, blank lines aside: the lint
257
+ # counts them in the same run.
258
+ def flat_controls_beside(units, outline, flat_control_linenos)
259
+ depth = units.first[2]
260
+ [(units.first[0] - 1).downto(1), ((units.last[1] + 1)...outline.size).each].sum do |linenos|
261
+ linenos.lazy
262
+ .reject { SKIPPED_KINDS.include?(outline[_1].kind) }
263
+ .take_while { outline[_1].kind == :structure && outline[_1].depth == depth && flat_control_linenos.include?(_1) }
264
+ .count
265
+ end
266
+ end
267
+
252
268
  def goes_on?(outline, lineno)
253
269
  next_info = outline[lineno + 1]
254
270
  next_info&.owner == lineno && next_info.kind != :blank
@@ -258,8 +274,11 @@ module SuperSlim
258
274
  line[CONTROL_CODE, 1]&.rstrip
259
275
  end
260
276
 
277
+ # A comment would end up after code on a `-` line, which Slim can't read; `#{}` in a string is no comment.
261
278
  def movable_code?(code)
262
- !code.include?("#") && !code.match?(Compiler::BLOCK_SELF_OPENING) && !code.match?(END_KEYWORD)
279
+ return false if code.match?(Compiler::BLOCK_SELF_OPENING) || code.match?(END_KEYWORD)
280
+
281
+ !code.include?("#") || Prism.parse(code).comments.empty?
263
282
  end
264
283
 
265
284
  # `tr: td = total` nests each tag in the one before: one per line, whatever the line holds. A line whose text goes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SuperSlim
4
- VERSION = "3.4.0"
4
+ VERSION = "3.4.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super-slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Level UP Solutions