syntax_tree 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +1 -1
- data/lib/syntax_tree/cli.rb +38 -18
- data/lib/syntax_tree/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 872e3355e589d7a18b916de52fc30d8ac7e52a9c746550082ed8fc503bd178b8
|
4
|
+
data.tar.gz: d27214567e9b0c9f9cf14b8874e839d7c90d7fec89d9a94c117e4e83028165a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d131267335b65e4ebd9c12c86275a64d556a9314a1d509b4a8c3629f553ed06e304abce59faab2b13a64bdd8a825101a3baf52e97e60cde8b5eeba2488621e7
|
7
|
+
data.tar.gz: 12f8ecf7e54688af0a2bac223320197113012c8b83a1db1135f51bf8192d8012462499f810c05bfb6d8d88f7c59551a467e4104cd12ec4094fd5722c3f940b64
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [1.
|
9
|
+
## [1.1.0] - 2021-12-08
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Better handling for formatting files with errors.
|
14
|
+
- Colorize the output snippet using IRB.
|
15
|
+
|
16
|
+
## [1.0.0] - 2021-12-08
|
10
17
|
|
11
18
|
### Added
|
12
19
|
|
data/Gemfile.lock
CHANGED
data/lib/syntax_tree/cli.rb
CHANGED
@@ -126,6 +126,9 @@ class SyntaxTree
|
|
126
126
|
delta = ((Time.now - start) * 1000).round
|
127
127
|
|
128
128
|
puts "\r#{color} #{delta}ms"
|
129
|
+
rescue
|
130
|
+
puts "\r#{filepath}"
|
131
|
+
raise
|
129
132
|
end
|
130
133
|
end
|
131
134
|
|
@@ -177,25 +180,12 @@ class SyntaxTree
|
|
177
180
|
action.run(filepath, source)
|
178
181
|
rescue ParseError => error
|
179
182
|
warn("Error: #{error.message}")
|
180
|
-
lines = source.lines
|
181
|
-
|
182
|
-
maximum = [error.lineno + 3, lines.length].min
|
183
|
-
digits = Math.log10(maximum).ceil
|
184
|
-
|
185
|
-
([error.lineno - 3, 0].max...maximum).each do |line_index|
|
186
|
-
line_number = line_index + 1
|
187
183
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
part3 = Color.gray(" %#{digits}s |" % " ")
|
194
|
-
warn("#{part3} #{" " * error.column}#{Color.red("^")}")
|
195
|
-
else
|
196
|
-
prefix = Color.gray(" %#{digits}d |" % line_number)
|
197
|
-
warn("#{prefix} #{lines[line_index]}")
|
198
|
-
end
|
184
|
+
if error.lineno
|
185
|
+
highlight_error(error, source)
|
186
|
+
else
|
187
|
+
warn(error.message)
|
188
|
+
warn(error.backtrace)
|
199
189
|
end
|
200
190
|
|
201
191
|
errored = true
|
@@ -232,6 +222,36 @@ class SyntaxTree
|
|
232
222
|
|
233
223
|
File.read(filepath, encoding: encoding)
|
234
224
|
end
|
225
|
+
|
226
|
+
# Highlights a snippet from a source and parse error.
|
227
|
+
def highlight_error(error, source)
|
228
|
+
lines = source.lines
|
229
|
+
|
230
|
+
maximum = [error.lineno + 3, lines.length].min
|
231
|
+
digits = Math.log10(maximum).ceil
|
232
|
+
|
233
|
+
([error.lineno - 3, 0].max...maximum).each do |line_index|
|
234
|
+
line_number = line_index + 1
|
235
|
+
|
236
|
+
if line_number == error.lineno
|
237
|
+
part1 = Color.red(">")
|
238
|
+
part2 = Color.gray("%#{digits}d |" % line_number)
|
239
|
+
warn("#{part1} #{part2} #{colorize_line(lines[line_index])}")
|
240
|
+
|
241
|
+
part3 = Color.gray(" %#{digits}s |" % " ")
|
242
|
+
warn("#{part3} #{" " * error.column}#{Color.red("^")}")
|
243
|
+
else
|
244
|
+
prefix = Color.gray(" %#{digits}d |" % line_number)
|
245
|
+
warn("#{prefix} #{colorize_line(lines[line_index])}")
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# Take a line of Ruby source and colorize the output.
|
251
|
+
def colorize_line(line)
|
252
|
+
require "irb"
|
253
|
+
IRB::Color.colorize_code(line, complete: false, ignore_error: true)
|
254
|
+
end
|
235
255
|
end
|
236
256
|
end
|
237
257
|
end
|
data/lib/syntax_tree/version.rb
CHANGED