rufo 0.13.0 → 0.14.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: 67f0bac262d71b5c91c9babdc6d975e88d1b7f04e903b8111f7ccf4f56aa2a35
4
- data.tar.gz: c437092573d817e16b05bf2ddc6a1b5a084bc8a81a06836b2e84528f65db1dca
3
+ metadata.gz: '050197c783154878217024914afe1fc208e624521b5c3c1c4cd182c29ce70795'
4
+ data.tar.gz: 8ec88b8b3bc5fa60afbfa7eb7bcf395a2dd906c2b51e2c256d9f11876540279f
5
5
  SHA512:
6
- metadata.gz: 4e14f22cc80b1566449f65c5b5eb7ceaa4b3f7ed9e98c9dbce35161830049d155c7cc83dd6fe5c3e965ebc085b7cda787b18d4a705b71daebdc1571060a7b545
7
- data.tar.gz: a49e26fe230db7e7c42d6f0a8cb700dec11caac98dfc6bfdc7eda7a0cfe80c3fb7b5da675acf0fd29da6b70253c893183279fd1b042d1f6e450f66b1e6e29813
6
+ metadata.gz: 7cce9d7529456084473d761247402c659950460bb75155d3689d8c89bc89993793d9638fc0bc47d45a40d97eaf2d06d13c175f1db0aeef1356ad12a8124f5bfe
7
+ data.tar.gz: f4e46d300e1a94fc05c1d2aaa99ea6f24fa244faba984e8841f9874e5326ef324cc38b915008948156ec5825c572024dc0e57a0600f6b235fe06f7b7f3695e60
@@ -0,0 +1,60 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ schedule:
9
+ - cron: '0 0 * * 0'
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby_version: ['3.2', '3.1', '3.0', '2.7']
17
+
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+
21
+ - name: Setup Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby_version }}
25
+ bundler-cache: true
26
+
27
+ - name: Bundle update
28
+ run: |
29
+ bundle update
30
+
31
+ - name: Run test
32
+ run: |
33
+ bundle exec rspec --profile 10 \
34
+ --format RspecJunitFormatter \
35
+ --out test_results/rspec.xml \
36
+ --format progress
37
+
38
+ - name: Upload code coverage
39
+ uses: codecov/codecov-action@v3
40
+ with:
41
+ files: ./coverage/coverage.xml
42
+
43
+ - name: Run rubocop
44
+ run: |
45
+ bundle exec rake rubocop
46
+
47
+ - name: Run rufo
48
+ run: |
49
+ bundle exec rake rufo:run
50
+
51
+ - name: Verify rufo works against sample codebases
52
+ run: |
53
+ bin/verify-sample-code
54
+
55
+ - name: Save test results
56
+ uses: actions/upload-artifact@v3
57
+ if: always()
58
+ with:
59
+ name: coverage-ruby-${{ matrix.ruby_version }}
60
+ path: coverage
data/.gitignore CHANGED
@@ -8,6 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /*.gem
11
+ /.ruby-version
11
12
 
12
13
  # rspec failure tracking
13
14
  .rspec_status
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - "spec/**/*"
4
4
  - "vendor/**/*"
5
- TargetRubyVersion: 2.6
5
+ TargetRubyVersion: 2.7
6
6
 
7
7
  Layout:
8
8
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -12,6 +12,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
12
12
 
13
13
  ### Added
14
14
 
15
+ ## [0.14.0] - 2023-01-25
16
+
17
+ ### Fixed
18
+
19
+ - Correctly interpret erb scriptlets with more than one control-flow/block statement
20
+
21
+ ### Changed
22
+
23
+ - Dropped support for Ruby 2.6 as it is end of life.
24
+
25
+ ### Added
26
+
27
+ - Support for partial argument forwarding. (issue [268](https://github.com/ruby-formatter/rufo/issues/268))
28
+ - Support for endless method. (issue [271](https://github.com/ruby-formatter/rufo/issues/271))
29
+ - Add Ruby 3.2.0 to test runs on CI.
30
+
15
31
  ## [0.13.0] - 2021-05-07
16
32
 
17
33
  ### Fixed
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rufo
2
2
 
3
- [![CircleCI](https://circleci.com/gh/ruby-formatter/rufo.svg?style=svg)](https://circleci.com/gh/ruby-formatter/rufo)
3
+ [![GitHub Actions](https://github.com/ruby-formatter/rufo/workflows/CI/badge.svg)](https://github.com/ruby-formatter/rufo/actions/workflows/ci.yml)
4
4
  [![Gem](https://img.shields.io/gem/v/rufo.svg)](https://rubygems.org/gems/rufo)
5
5
 
6
6
  **Ru**by **fo**rmatter
@@ -12,7 +12,7 @@ Unlike the best known Ruby formatter [RuboCop](https://github.com/bbatsov/ruboco
12
12
 
13
13
  RuboCop does much more than just format code though, so feel free to run them both!
14
14
 
15
- Rufo supports all Ruby versions >= 2.4.**5**, due to a bug in Ruby's Ripper parser.
15
+ Rufo supports all Ruby versions >= 2.7.0.
16
16
 
17
17
  ## Installation
18
18
 
@@ -35,7 +35,7 @@ Or install it system wide with:
35
35
  Once the gem is installed, enable format on save integration in your editor of choice with the following libraries:
36
36
 
37
37
  - Atom: [rufo-atom](https://github.com/bmulvihill/rufo-atom) :construction:
38
- - Emacs [emacs-rufo](https://github.com/aleandros/emacs-rufo) :construction: or [rufo.el](https://github.com/danielma/rufo.el)
38
+ - Emacs [emacs-rufo](https://github.com/aleandros/emacs-rufo) :construction: or [rufo.el](https://github.com/danielma/rufo.el) or [run rufo with reformatter](https://gist.github.com/kzkn/5c80c24d39e5e7b7881d55ad04605c5b)
39
39
  - Sublime Text: [sublime-rufo](https://github.com/ruby-formatter/sublime-rufo)
40
40
  - Vim: [rufo-vim](https://github.com/splattael/rufo-vim)
41
41
  - Visual Studio Code: [vscode-rufo](https://marketplace.visualstudio.com/items?itemName=mbessey.vscode-rufo) or [rufo-vscode](https://marketplace.visualstudio.com/items?itemName=siliconsenthil.rufo-vscode)
@@ -9,6 +9,8 @@ repos = {
9
9
  "spec/rspec/core/metadata_spec.rb",
10
10
  "spec/rspec/core/formatters/html_formatter_spec.rb",
11
11
  "spec/rspec/core/formatters_spec.rb",
12
+ "spec/rspec/core/formatters/documentation_formatter_spec.rb",
13
+ "spec/rspec/core/formatters/progress_formatter_spec.rb"
12
14
  ].join(","),
13
15
  },
14
16
  }
@@ -104,11 +104,48 @@ class Rufo::ErbFormatter
104
104
  result.strip
105
105
  end
106
106
 
107
+ def format_affix(affix, levels, type)
108
+ string = ""
109
+ case type
110
+ when :prefix
111
+ count = 0
112
+ while count < levels
113
+ count += 1
114
+ string += (" " * Rufo::Formatter::INDENT_SIZE * (count > 0 ? count - 1 : 0)) + affix
115
+ string += "\n" if count < levels
116
+ end
117
+ when :suffix
118
+ count = levels
119
+ while count > 0
120
+ count -= 1
121
+ string += "\n"
122
+ string += (" " * Rufo::Formatter::INDENT_SIZE * (count > 0 ? count - 1 : 0)) + affix
123
+ end
124
+ end
125
+ string
126
+ end
127
+
107
128
  def determine_code_wrappers(code_str)
108
- return nil, "\nend" if Ripper.sexp("#{code_str}\nend")
129
+ keywords = Ripper.lex("#{code_str}").filter { |lex_token| lex_token[1] == :on_kw }
130
+ lexical_tokens = keywords.filter { |lex_token| lex_token[2] != "when" }.map { |lex_token| lex_token[3].to_s }
131
+ state_tally = lexical_tokens.group_by(&:itself).transform_values(&:count)
132
+ beg_token = state_tally["BEG"] || state_tally["EXPR_BEG"] || 0
133
+ end_token = state_tally["END"] || state_tally["EXPR_END"] || 0
134
+ depth = beg_token - end_token
135
+
136
+ if depth > 0
137
+ affix = format_affix("end", depth.abs, :suffix)
138
+ return nil, affix if Ripper.sexp("#{code_str}#{affix}")
139
+ end
140
+
109
141
  return nil, "}" if Ripper.sexp("#{code_str} }")
110
142
  return "{", nil if Ripper.sexp("{ #{code_str}")
111
- return "begin", nil if Ripper.sexp("begin #{code_str}")
143
+
144
+ if depth < 0
145
+ affix = format_affix("begin", depth.abs, :prefix)
146
+ return affix, nil if Ripper.sexp("#{affix}#{code_str}")
147
+ end
148
+
112
149
  return "begin\n", "\nend" if Ripper.sexp("begin\n#{code_str}\nend")
113
150
  return "if a\n", "\nend" if Ripper.sexp("if a\n#{code_str}\nend")
114
151
  return "case a\n", "\nend" if Ripper.sexp("case a\n#{code_str}\nend")
@@ -1456,14 +1456,10 @@ class Rufo::Formatter
1456
1456
  # check for ||
1457
1457
  if empty_params && !local_params
1458
1458
  # Don't write || as it's meaningless
1459
- if current_token_value == "|"
1460
- next_token
1461
- skip_space_or_newline
1462
- check :on_op
1463
- next_token
1464
- else
1465
- next_token
1466
- end
1459
+ next_token
1460
+ skip_space_or_newline
1461
+ check :on_op
1462
+ next_token
1467
1463
  return
1468
1464
  end
1469
1465
 
@@ -1575,7 +1571,12 @@ class Rufo::Formatter
1575
1571
 
1576
1572
  line = @line
1577
1573
 
1578
- indent_body body
1574
+ endless = body[0].is_a?(Symbol)
1575
+ if endless
1576
+ visit body
1577
+ else
1578
+ indent_body body
1579
+ end
1579
1580
 
1580
1581
  while rescue_body
1581
1582
  # [:rescue, type, name, body, more_rescue]
@@ -1620,7 +1621,7 @@ class Rufo::Formatter
1620
1621
  end
1621
1622
 
1622
1623
  write_indent if @line != line
1623
- consume_keyword "end"
1624
+ consume_keyword "end" unless endless
1624
1625
  end
1625
1626
 
1626
1627
  def visit_rescue_types(node)
@@ -1996,6 +1997,19 @@ class Rufo::Formatter
1996
1997
  # [:@ident, "foo", [1, 6]],
1997
1998
  # [:params, nil, nil, nil, nil, nil, nil, nil],
1998
1999
  # [:bodystmt, [[:void_stmt]], nil, nil, nil]]
2000
+ #
2001
+ # OR For endless methods (in 3.0)
2002
+ # [:def,
2003
+ # [:@ident, "foo", [1, 6]],
2004
+ # nil,
2005
+ # [:string_literal, [:string_content, [:@tstring_content, "bar", [1, 11]
2006
+ # OR For endless methods (in 3.1)
2007
+ # [:def,
2008
+ # [:@ident, "foo", [1, 6]],
2009
+ # nil,
2010
+ # [:bodystmt,
2011
+ # [:string_literal, [:string_content, [:@tstring_content, "bar", [1, 11]
2012
+
1999
2013
  _, name, params, body = node
2000
2014
 
2001
2015
  consume_keyword "def"
@@ -2032,6 +2046,7 @@ class Rufo::Formatter
2032
2046
  def visit_def_from_name(name, params, body)
2033
2047
  visit name
2034
2048
 
2049
+ params = [] if params.nil?
2035
2050
  params = params[1] if params[0] == :paren
2036
2051
 
2037
2052
  skip_space
@@ -2072,6 +2087,7 @@ class Rufo::Formatter
2072
2087
  end
2073
2088
  write ")"
2074
2089
  next_token
2090
+ skip_space
2075
2091
  end
2076
2092
  elsif !empty_params?(params)
2077
2093
  if parens_in_def == :yes
@@ -2085,9 +2101,18 @@ class Rufo::Formatter
2085
2101
  skip_space
2086
2102
  end
2087
2103
 
2104
+ format_endless_method if current_token_kind == :on_op
2105
+
2088
2106
  visit body
2089
2107
  end
2090
2108
 
2109
+ def format_endless_method
2110
+ consume_space
2111
+ consume_op "="
2112
+ consume_space
2113
+ skip_space
2114
+ end
2115
+
2091
2116
  def empty_params?(node)
2092
2117
  _, a, b, c, d, e, f, g = node
2093
2118
  !a && !b && !c && !d && !e && !f && !g
@@ -2143,6 +2168,7 @@ class Rufo::Formatter
2143
2168
  when 0, [:excessed_comma]
2144
2169
  write_params_comma
2145
2170
  when [:args_forward]
2171
+ write_params_comma if needs_comma
2146
2172
  consume_op "..."
2147
2173
  else
2148
2174
  # [:rest_param, [:@ident, "x", [1, 15]]]
@@ -2179,16 +2205,22 @@ class Rufo::Formatter
2179
2205
 
2180
2206
  if double_star_param
2181
2207
  write_params_comma if needs_comma
2182
- consume_op "**"
2183
- skip_space_or_newline
2208
+ case double_star_param
2209
+ when [:args_forward] # may be [:args_forward] in 3.1.0
2210
+ consume_op "..."
2211
+ else
2212
+ consume_op "**" # here
2213
+ skip_space_or_newline
2184
2214
 
2185
- # A nameless double star comes as an... Integer? :-S
2186
- visit double_star_param if double_star_param.is_a?(Array)
2187
- skip_space_or_newline
2188
- needs_comma = true
2215
+ # A nameless double star comes as an... Integer? :-S
2216
+ visit double_star_param if double_star_param.is_a?(Array)
2217
+ skip_space_or_newline
2218
+ needs_comma = true
2219
+ end
2189
2220
  end
2190
2221
 
2191
- if blockarg
2222
+ # In 3.1.0 blockarg may be just a symbol `:&`
2223
+ if blockarg && blockarg.is_a?(Array)
2192
2224
  # [:blockarg, [:@ident, "block", [1, 16]]]
2193
2225
  write_params_comma if needs_comma
2194
2226
  skip_space_or_newline
@@ -3188,13 +3220,6 @@ class Rufo::Formatter
3188
3220
  last_space = current_token
3189
3221
  next_token
3190
3222
  when :on_nl, :on_ignored_nl
3191
- # I don't know why but sometimes a on_ignored_nl
3192
- # can appear with nil as the "text", and that's wrong
3193
- if current_token[2].nil?
3194
- next_token
3195
- next
3196
- end
3197
-
3198
3223
  if last == :newline
3199
3224
  # If we pass through consecutive newlines, don't print them
3200
3225
  # yet, but remember this fact
@@ -3888,11 +3913,7 @@ class Rufo::Formatter
3888
3913
  when :assoclist_from_args
3889
3914
  node_line(beginning ? node[1][0] : node[1].last, beginning: beginning)
3890
3915
  when :dyna_symbol
3891
- if node[1][0].is_a?(Symbol)
3892
- node_line(node[1], beginning: beginning)
3893
- else
3894
- node_line(node[1][0], beginning: beginning)
3895
- end
3916
+ node_line(node[1], beginning: beginning)
3896
3917
  when :@label, :@int, :@ident, :@tstring_content, :@kw
3897
3918
  node[2][0]
3898
3919
  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.13.0"
4
+ VERSION = "0.14.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.6.0"
23
+ spec.required_ruby_version = ">= 2.7.0"
24
24
 
25
25
  spec.add_development_dependency "bundler", ">= 1.15"
26
26
  spec.add_development_dependency "byebug", "~> 11.0.1"
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.13.0
4
+ version: 0.14.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: 2021-05-09 00:00:00.000000000 Z
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,8 +158,8 @@ executables:
158
158
  extensions: []
159
159
  extra_rdoc_files: []
160
160
  files:
161
- - ".circleci/config.yml"
162
161
  - ".github/PULL_REQUEST_TEMPLATE.md"
162
+ - ".github/workflows/ci.yml"
163
163
  - ".gitignore"
164
164
  - ".rspec"
165
165
  - ".rubocop.yml"
@@ -202,14 +202,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
203
  - - ">="
204
204
  - !ruby/object:Gem::Version
205
- version: 2.6.0
205
+ version: 2.7.0
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
208
  - - ">="
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
- rubygems_version: 3.2.17
212
+ rubygems_version: 3.3.7
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: Ruby code formatter
data/.circleci/config.yml DELETED
@@ -1,101 +0,0 @@
1
- "-": &dockerbuild
2
- steps:
3
- - checkout
4
-
5
- # Which version of ruby?
6
- - run:
7
- name: Which ruby?
8
- command: ruby --version | tee ruby-version-for-ci.txt
9
-
10
- # Which version of bundler?
11
- - run:
12
- name: Which bundler?
13
- command: bundle -v
14
-
15
- # Restore bundle cache
16
- - restore_cache:
17
- keys:
18
- - bundler-packages-v2-{{ checksum "ruby-version-for-ci.txt" }}-{{ checksum "rufo.gemspec" }}-{{ checksum "bin/verify-sample-code" }}
19
-
20
- - run:
21
- name: Bundle Install
22
- command: bundle check || bundle install
23
-
24
- - run:
25
- name: Run rspec
26
- command: |
27
- bundle exec rspec --profile 10 \
28
- --format RspecJunitFormatter \
29
- --out test_results/rspec.xml \
30
- --format progress
31
- - run:
32
- name: Upload code coverage
33
- command: bash <(curl -s https://codecov.io/bash) -f 'coverage/coverage.xml'
34
- - run:
35
- name: Run RuboCop
36
- command: |
37
- bundle exec rake rubocop
38
- - run:
39
- name: Run Rufo
40
- command: |
41
- bundle exec rake rufo:run
42
-
43
- - run:
44
- name: Verify rufo works against sample codebases
45
- command: |
46
- bin/verify-sample-code
47
-
48
- # Store bundle cache
49
- - save_cache:
50
- key: bundler-packages-v2-{{ checksum "ruby-version-for-ci.txt" }}-{{ checksum "rufo.gemspec" }}-{{ checksum "bin/verify-sample-code" }}
51
- paths:
52
- - vendor/bundle
53
- - Gemfile.lock
54
-
55
- # Save test results for timing analysis
56
- - store_test_results:
57
- path: test_results
58
-
59
- version: 2
60
- jobs:
61
- build-3-0-1:
62
- <<: *dockerbuild
63
- docker:
64
- - image: circleci/ruby:3.0.1
65
- environment:
66
- BUNDLE_JOBS: "3"
67
- BUNDLE_RETRY: "3"
68
- BUNDLE_PATH: /home/circleci/project/vendor/bundle
69
- build-2-7-3:
70
- <<: *dockerbuild
71
- docker:
72
- - image: circleci/ruby:2.7.3
73
- environment:
74
- BUNDLE_JOBS: "3"
75
- BUNDLE_RETRY: "3"
76
- BUNDLE_PATH: /home/circleci/project/vendor/bundle
77
- build-2-6-7:
78
- <<: *dockerbuild
79
- docker:
80
- - image: circleci/ruby:2.6.7
81
- environment:
82
- BUNDLE_JOBS: "3"
83
- BUNDLE_RETRY: "3"
84
- BUNDLE_PATH: /home/circleci/project/vendor/bundle
85
- build-2-6-1:
86
- <<: *dockerbuild
87
- docker:
88
- - image: circleci/ruby:2.6.1
89
- environment:
90
- BUNDLE_JOBS: "3"
91
- BUNDLE_RETRY: "3"
92
- BUNDLE_PATH: vendor/bundle
93
-
94
- workflows:
95
- version: 2
96
- test:
97
- jobs:
98
- - build-3-0-1
99
- - build-2-7-3
100
- - build-2-6-7
101
- - build-2-6-1