rufo 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2415782555ad95778ec90751f3c438320fb1797c44213c458c0d0a7f956cf2fc
4
- data.tar.gz: 6e2bed742d8efedef98b59b74acaef679764eeb5911e6fc0b596da1a9cec7807
3
+ metadata.gz: 2239283a440e83e68074430ba36c303f94701858ff8983394bf6eda08f588089
4
+ data.tar.gz: 141195447e27a7cc31b98f66b919142ffa46c49c5221617dcf9b3a6c3d25a306
5
5
  SHA512:
6
- metadata.gz: f103da0397ad0415a031601e14016d0080c9c22cac9d4b3af45a01f7f32a6fd851118d871d09272a8c41c7373ab8e77caac81b815899634eac66941e1f67121c
7
- data.tar.gz: dcc1b6e6430818500a3238c1d403dd23abdfc840757318e1746bd388e0d1f4ce9a0df12a232bad5f6691dc69cd9cf6421ea1c74df8ed58c29453ac5260c91c4b
6
+ metadata.gz: 9f71537f4b5741d60dc0b23ed49cff278708ce2d58901b07765be00c34ec87e6a9cba70963fe3e60beaa2bcf9281b03e15535f3b7df76b1cb81235dc18e3616b
7
+ data.tar.gz: '091c1fe438ad222e6958b5016543882a21e943cde22b56f7a10cc67baf356ae43d3d54646a7576530711e224ae915227c647c6d95c6d51709814432416036d00'
@@ -13,7 +13,7 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  strategy:
15
15
  matrix:
16
- ruby_version: ['3.3', '3.2', '3.1', '3.0', '2.7']
16
+ ruby_version: ['3.3', '3.2', '3.1', '3.0']
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v3
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ AllCops:
3
3
  Exclude:
4
4
  - "spec/**/*"
5
5
  - "vendor/**/*"
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.0
7
7
 
8
8
  Layout:
9
9
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -12,6 +12,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
12
12
 
13
13
  ### Added
14
14
 
15
+ ## [0.18.0] - 2024-05-30
16
+
17
+ ### Fixed
18
+ - Fix error when formatting ERB ([#319](https://github.com/ruby-formatter/rufo/issues/319))
19
+
20
+ ### Changed
21
+ - Dropped support for Ruby 2.7 as it is end of life.
22
+
23
+ ### Added
24
+
25
+ ## [0.17.1] - 2024-02-03
26
+
27
+ ### Fixed
28
+ - Fix incorrect indentation methods call with splat ([#320](https://github.com/ruby-formatter/rufo/pull/320))
29
+
30
+ ### Changed
31
+ - Remove unused internal methods from `Rufo::Formatter` ([#321](https://github.com/ruby-formatter/rufo/pull/321))
32
+ - This change may affect behavior with versions of Ruby not currently supported by Rufo (< 2.7)
33
+
34
+ ### Added
35
+
15
36
  ## [0.17.0] - 2024-01-06
16
37
 
17
38
  ### Fixed
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
  repos = {
4
- "lostisland/faraday" => {
5
- "--format" => "progress",
6
- },
4
+ "rspec/rspec-expectations" => {},
5
+ "rspec/rspec-mocks" => {},
7
6
  }
8
7
 
9
8
  def run_command(cmd, allowed_statuses: [0])
@@ -18,6 +18,7 @@ class Rufo::Formatter
18
18
 
19
19
  @tokens = Rufo::Parser.lex(code).reverse!
20
20
  @sexp = Rufo::Parser.sexp(code)
21
+ @sexp ||= Rufo::Parser.sexp_unparsable_code(code)
21
22
 
22
23
  # sexp being nil means that the code is not valid.
23
24
  # Parse the code so we get better error messages.
@@ -396,8 +397,6 @@ class Rufo::Formatter
396
397
  visit_module(node)
397
398
  when :mrhs_new_from_args
398
399
  visit_mrhs_new_from_args(node)
399
- when :mlhs_paren
400
- visit_mlhs_paren(node)
401
400
  when :mlhs
402
401
  visit_mlhs(node)
403
402
  when :mrhs_add_star
@@ -457,8 +456,6 @@ class Rufo::Formatter
457
456
  visit_alias(node)
458
457
  when :undef
459
458
  visit_undef(node)
460
- when :mlhs_add_star
461
- visit_mlhs_add_star(node)
462
459
  when :rest_param
463
460
  visit_rest_param(node)
464
461
  when :kwrest_param
@@ -906,26 +903,6 @@ class Rufo::Formatter
906
903
  end
907
904
  end
908
905
 
909
- def indentable_value?(value)
910
- return unless current_token_kind == :on_kw
911
-
912
- case current_token_value
913
- when "if", "unless", "case"
914
- true
915
- when "begin"
916
- # Only indent if it's begin/rescue
917
- return false unless value[0] == :begin
918
-
919
- body = value[1]
920
- return false unless body[0] == :bodystmt
921
-
922
- _, _, rescue_body, else_body, ensure_body = body
923
- rescue_body || else_body || ensure_body
924
- else
925
- false
926
- end
927
- end
928
-
929
906
  def current_comment_aligned_to_previous_one?
930
907
  @last_comment &&
931
908
  @last_comment[0][0] + 1 == current_token_line &&
@@ -1541,7 +1518,8 @@ class Rufo::Formatter
1541
1518
 
1542
1519
  skip_space
1543
1520
 
1544
- write_params_comma if comma?
1521
+ # Disable indentation in write_params_comma to avoid double indentation with write_indent
1522
+ write_params_comma(with_indent: !needs_indent) if comma?
1545
1523
  write_indent(base_column) if needs_indent
1546
1524
  consume_op "*"
1547
1525
  skip_space_or_newline
@@ -1551,7 +1529,8 @@ class Rufo::Formatter
1551
1529
  end
1552
1530
 
1553
1531
  if post_args && !post_args.empty?
1554
- write_params_comma
1532
+ # Disable indentation in write_params_comma to avoid double indentation with visit_comma_separated_list
1533
+ write_params_comma(with_indent: !needs_indent)
1555
1534
  visit_comma_separated_list post_args, needs_indent: needs_indent, base_column: base_column
1556
1535
  end
1557
1536
  end
@@ -1659,23 +1638,10 @@ class Rufo::Formatter
1659
1638
  end
1660
1639
  end
1661
1640
 
1662
- def visit_mlhs_paren(node)
1663
- # [:mlhs_paren,
1664
- # [[:mlhs_paren, [:@ident, "x", [1, 12]]]]
1665
- # ]
1666
- _, args = node
1667
-
1668
- visit_mlhs_or_mlhs_paren(args)
1669
- end
1670
-
1671
1641
  def visit_mlhs(node)
1672
1642
  # [:mlsh, *args]
1673
1643
  _, *args = node
1674
1644
 
1675
- visit_mlhs_or_mlhs_paren(args)
1676
- end
1677
-
1678
- def visit_mlhs_or_mlhs_paren(args)
1679
1645
  # Sometimes a paren comes, some times not, so act accordingly.
1680
1646
  has_paren = current_token_kind == :on_lparen
1681
1647
  if has_paren
@@ -1819,35 +1785,6 @@ class Rufo::Formatter
1819
1785
  end
1820
1786
  end
1821
1787
 
1822
- def visit_mlhs_add_star(node)
1823
- # [:mlhs_add_star, before, star, after]
1824
- _, before, star, after = node
1825
-
1826
- if before && !before.empty?
1827
- # Maybe a Ripper bug, but if there's something before a star
1828
- # then a star shouldn't be here... but if it is... handle it
1829
- # somehow...
1830
- if op?("*")
1831
- star = before
1832
- else
1833
- visit_comma_separated_list to_ary(before)
1834
- write_params_comma
1835
- end
1836
- end
1837
-
1838
- consume_op "*"
1839
-
1840
- if star
1841
- skip_space_or_newline
1842
- visit star
1843
- end
1844
-
1845
- if after && !after.empty?
1846
- write_params_comma
1847
- visit_comma_separated_list after
1848
- end
1849
- end
1850
-
1851
1788
  def visit_rest_param(node)
1852
1789
  # [:rest_param, name]
1853
1790
 
@@ -2250,12 +2187,14 @@ class Rufo::Formatter
2250
2187
  end
2251
2188
  end
2252
2189
 
2253
- def write_params_comma
2190
+ def write_params_comma(with_indent: true)
2254
2191
  skip_space
2255
2192
  check :on_comma
2256
2193
  write ","
2257
2194
  next_token
2258
- skip_space_or_newline_using_setting(:one)
2195
+
2196
+ indent_size = with_indent ? @indent : 0
2197
+ skip_space_or_newline_using_setting(:one, indent_size)
2259
2198
  end
2260
2199
 
2261
2200
  def visit_array(node)
data/lib/rufo/parser.rb CHANGED
@@ -10,4 +10,48 @@ class Rufo::Parser < Ripper
10
10
  def on_parse_error(msg)
11
11
  raise ::Rufo::SyntaxError.new(msg, lineno)
12
12
  end
13
+
14
+ def self.sexp_unparsable_code(code)
15
+ code_type = detect_unparsable_code_type(code)
16
+
17
+ case code_type
18
+ when :yield
19
+ extract_original_code_sexp(
20
+ "def __rufo_dummy; #{code}; end",
21
+ ->(exp) { exp => [:def, *, [:bodystmt, exps, *]]; exps }
22
+ )
23
+ when :next, :break, :redo
24
+ extract_original_code_sexp(
25
+ "loop do; #{code}; end",
26
+ ->(exp) { exp => [:method_add_block, *, [:do_block, nil, [:bodystmt, [[:void_stmt], *exps], *]]]; exps }
27
+ )
28
+ when :retry
29
+ extract_original_code_sexp(
30
+ "begin; rescue; #{code}; end",
31
+ ->(exp) { exp => [:begin, [:bodystmt, Array, [:rescue, nil, nil, exps, *], *]]; exps }
32
+ )
33
+ end
34
+ end
35
+
36
+ def self.detect_unparsable_code_type(code)
37
+ tokens = self.lex(code)
38
+ token = tokens.find { |_, kind| kind != :on_sp && kind != :on_ignored_nl }
39
+
40
+ case token
41
+ in [_, :on_kw, "yield" | "next" | "break" | "retry" | "redo" => kw, _]
42
+ kw.to_sym
43
+ else
44
+ nil
45
+ end
46
+ end
47
+
48
+ def self.extract_original_code_sexp(decorated_code, extractor)
49
+ sexp = self.sexp(decorated_code)
50
+ return nil unless sexp
51
+
52
+ # [:program, [exp]]
53
+ exp = sexp[1][0]
54
+ code_exps = extractor.call(exp)
55
+ [:program, code_exps]
56
+ end
13
57
  end
data/lib/rufo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rufo
4
- VERSION = "0.17.0"
4
+ VERSION = "0.18.0"
5
5
  end
data/rufo.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.bindir = "exe"
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
- spec.required_ruby_version = ">= 2.7.0"
23
+ spec.required_ruby_version = ">= 3.0.0"
24
24
  spec.metadata["rubygems_mfa_required"] = "true"
25
25
 
26
26
  spec.add_development_dependency "bundler", ">= 1.15"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ary Borenszweig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-06 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -203,14 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - ">="
205
205
  - !ruby/object:Gem::Version
206
- version: 2.7.0
206
+ version: 3.0.0
207
207
  required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  requirements:
209
209
  - - ">="
210
210
  - !ruby/object:Gem::Version
211
211
  version: '0'
212
212
  requirements: []
213
- rubygems_version: 3.4.10
213
+ rubygems_version: 3.5.3
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: Ruby code formatter