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 +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/lib/rufo/formatter.rb +1 -0
- data/lib/rufo/parser.rb +44 -0
- data/lib/rufo/version.rb +1 -1
- data/rufo.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2239283a440e83e68074430ba36c303f94701858ff8983394bf6eda08f588089
|
4
|
+
data.tar.gz: 141195447e27a7cc31b98f66b919142ffa46c49c5221617dcf9b3a6c3d25a306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f71537f4b5741d60dc0b23ed49cff278708ce2d58901b07765be00c34ec87e6a9cba70963fe3e60beaa2bcf9281b03e15535f3b7df76b1cb81235dc18e3616b
|
7
|
+
data.tar.gz: '091c1fe438ad222e6958b5016543882a21e943cde22b56f7a10cc67baf356ae43d3d54646a7576530711e224ae915227c647c6d95c6d51709814432416036d00'
|
data/.github/workflows/ci.yml
CHANGED
data/.rubocop.yml
CHANGED
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
|
data/lib/rufo/formatter.rb
CHANGED
@@ -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
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 = ">=
|
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.
|
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-
|
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:
|
206
|
+
version: 3.0.0
|
207
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
208
|
requirements:
|
209
209
|
- - ">="
|