syntax_search 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/check_changelog.yml +13 -0
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/lib/syntax_search.rb +22 -2
- data/lib/syntax_search/display_invalid_blocks.rb +22 -11
- data/lib/syntax_search/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9efb5d44fe2c979f66237173d1bf7b215a1bcc8003b4a96cb595eabbcac606c6
|
4
|
+
data.tar.gz: 5757f68cdf7dace8980bb31b49a756b858fba8f7260156640621832374b4e635
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9fb23706395a520d52af51ea2a441d972115d6cd85a9e4048d17424d0e7077e679cd23d6ec1a9f43f4fde1e6d29ab8670906dc27451b730f2dab4c5c753789f
|
7
|
+
data.tar.gz: 13209882976145efe8087a5c5d52e1980d5295c4b7ab51628dc92007f6b83900933fb2e08046bac7ccf118056289bba04f3f5597b70400c74c32969468e31409
|
@@ -0,0 +1,13 @@
|
|
1
|
+
name: Check Changelog
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [opened, reopened, edited, synchronize]
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v1
|
11
|
+
- name: Check that CHANGELOG is touched
|
12
|
+
run: |
|
13
|
+
cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
## HEAD (unreleased)
|
2
2
|
|
3
|
+
## 0.1.2
|
4
|
+
|
5
|
+
- Codeblocks in output are now indented with 4 spaces and "code fences" are removed (https://github.com/zombocom/syntax_search/pull/11)
|
6
|
+
- "Unmatched end" and "missing end" not generate different error text instructions (https://github.com/zombocom/syntax_search/pull/10)
|
7
|
+
|
3
8
|
## 0.1.1
|
4
9
|
|
5
|
-
-
|
10
|
+
- Fire search on both unexpected end-of-input and unexected end (https://github.com/zombocom/syntax_search/pull/8)
|
6
11
|
|
7
12
|
## 0.1.0
|
8
13
|
|
data/Gemfile.lock
CHANGED
data/lib/syntax_search.rb
CHANGED
@@ -23,7 +23,7 @@ module SyntaxErrorSearch
|
|
23
23
|
self.call(
|
24
24
|
source: Pathname(filename).read,
|
25
25
|
filename: filename,
|
26
|
-
terminal: true
|
26
|
+
terminal: true,
|
27
27
|
)
|
28
28
|
end
|
29
29
|
|
@@ -40,6 +40,7 @@ module SyntaxErrorSearch
|
|
40
40
|
blocks: blocks,
|
41
41
|
filename: filename,
|
42
42
|
terminal: terminal,
|
43
|
+
invalid_type: invalid_type(source),
|
43
44
|
io: $stderr
|
44
45
|
).call
|
45
46
|
end
|
@@ -122,11 +123,30 @@ module SyntaxErrorSearch
|
|
122
123
|
|
123
124
|
Parser::CurrentRuby.parse(source)
|
124
125
|
true
|
125
|
-
rescue Parser::SyntaxError
|
126
|
+
rescue Parser::SyntaxError => e
|
127
|
+
yield e if block_given?
|
126
128
|
false
|
127
129
|
ensure
|
128
130
|
$stderr = stderr if stderr
|
129
131
|
end
|
132
|
+
|
133
|
+
def self.invalid_type(source)
|
134
|
+
message = nil
|
135
|
+
self.valid?(source) do |error|
|
136
|
+
message = error.message
|
137
|
+
end
|
138
|
+
|
139
|
+
case message
|
140
|
+
when nil
|
141
|
+
:none
|
142
|
+
when /token kEND/
|
143
|
+
:unmatched_end
|
144
|
+
when /token \$end/ #
|
145
|
+
:missing_end
|
146
|
+
else
|
147
|
+
raise "Unexpected message #{message}"
|
148
|
+
end
|
149
|
+
end
|
130
150
|
end
|
131
151
|
|
132
152
|
require_relative "syntax_search/code_line"
|
@@ -5,7 +5,7 @@ module SyntaxErrorSearch
|
|
5
5
|
class DisplayInvalidBlocks
|
6
6
|
attr_reader :filename
|
7
7
|
|
8
|
-
def initialize(blocks:, io: $stderr, filename: nil, terminal: false)
|
8
|
+
def initialize(blocks:, io: $stderr, filename: nil, terminal: false, invalid_type: :unmatched_end)
|
9
9
|
@terminal = terminal
|
10
10
|
@filename = filename
|
11
11
|
@io = io
|
@@ -16,6 +16,7 @@ module SyntaxErrorSearch
|
|
16
16
|
@digit_count = @code_lines.last&.line_number.to_s.length
|
17
17
|
|
18
18
|
@invalid_line_hash = @lines.each_with_object({}) {|line, h| h[line] = true }
|
19
|
+
@invalid_type = invalid_type
|
19
20
|
end
|
20
21
|
|
21
22
|
def call
|
@@ -33,15 +34,28 @@ module SyntaxErrorSearch
|
|
33
34
|
end
|
34
35
|
|
35
36
|
private def found_invalid_blocks
|
36
|
-
@
|
37
|
+
case @invalid_type
|
38
|
+
when :missing_end
|
39
|
+
@io.puts <<~EOM
|
37
40
|
|
38
|
-
|
41
|
+
SyntaxSearch: Missing `end` detected
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
This code has a missing `end`. Ensure that all
|
44
|
+
syntax keywords (`def`, `do`, etc.) have a matching `end`.
|
45
|
+
|
46
|
+
EOM
|
47
|
+
when :unmatched_end
|
48
|
+
@io.puts <<~EOM
|
49
|
+
|
50
|
+
SyntaxSearch: Unmatched `end` detected
|
51
|
+
|
52
|
+
This code has an unmatched `end`. Ensure that all `end` lines
|
53
|
+
in your code have a matching syntax keyword (`def`, `do`, etc.)
|
54
|
+
and that you don't have any extra `end` lines.
|
55
|
+
|
56
|
+
EOM
|
57
|
+
end
|
43
58
|
|
44
|
-
EOM
|
45
59
|
@io.puts("file: #{filename}") if filename
|
46
60
|
@io.puts <<~EOM
|
47
61
|
simplified:
|
@@ -50,16 +64,13 @@ module SyntaxErrorSearch
|
|
50
64
|
EOM
|
51
65
|
end
|
52
66
|
|
53
|
-
def indent(string, with: "
|
67
|
+
def indent(string, with: " ")
|
54
68
|
string.each_line.map {|l| with + l }.join
|
55
69
|
end
|
56
70
|
|
57
71
|
def code_block
|
58
72
|
string = String.new("")
|
59
|
-
string << "```\n"
|
60
|
-
# string << "#".rjust(@digit_count) + " filename: #{filename}\n\n" if filename
|
61
73
|
string << code_with_lines
|
62
|
-
string << "```\n"
|
63
74
|
string
|
64
75
|
end
|
65
76
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- schneems
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -34,6 +34,7 @@ extensions: []
|
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
36
|
- ".circleci/config.yml"
|
37
|
+
- ".github/workflows/check_changelog.yml"
|
37
38
|
- ".gitignore"
|
38
39
|
- ".rspec"
|
39
40
|
- ".travis.yml"
|