rufo 0.17.1 → 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: f5df151931108df0740d8602c1bf8b931503e3bede6a337f25a9bf75cb549c70
4
- data.tar.gz: 73a321c4a0960f8fc021b062149ccbe3f96ccfc231c780e2612de00e011f590b
3
+ metadata.gz: 2239283a440e83e68074430ba36c303f94701858ff8983394bf6eda08f588089
4
+ data.tar.gz: 141195447e27a7cc31b98f66b919142ffa46c49c5221617dcf9b3a6c3d25a306
5
5
  SHA512:
6
- metadata.gz: 8a2176ae1780bce5ec076052b63576fc54370a4a5b2a7837166e8d42ec4f6f4f47cc1b4590f5742a6b7a263d7cb2b59fc7985a2dd9f1a37fa41939c502515253
7
- data.tar.gz: aad26fad18830aad211ba7d16f65643b78648b4f755d0a43ac1b65edbba1d7f97e05535f7c2f499dc3a5a7fa2cfff295e2a5da1aa63af859090873598406ab60
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,16 @@ 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
+
15
25
  ## [0.17.1] - 2024-02-03
16
26
 
17
27
  ### Fixed
@@ -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.
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.1"
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.1
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-02-03 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,7 +203,7 @@ 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
  - - ">="