syntax_search 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 520b6bbfe8e63c7045c02a1f209e73097e732a701e306c65ccc2a29f3e7645d1
4
- data.tar.gz: 617a4e7177d8d3fb96624149f2afc7cc8698f43e4d1687e8f32ed45c19ec3ad6
3
+ metadata.gz: 77f054eda8b4e25dcaf0306818ae17bb1ff3da9c52f2d606141ff44cd343c51d
4
+ data.tar.gz: 44f4347d5078d0250286e78a08ff730b02094aeb05897c9088963381a95e9071
5
5
  SHA512:
6
- metadata.gz: 9593ed43b2f33ac12b71630f7ceaa7a971b281c3b476eabad43dd5bd71db76ee37f9b20e303e3a6699ce1e67d467c32237d8c1fbab51d75823b59f63fbe756cc
7
- data.tar.gz: 64567243a2c7404694b5719eb2c82482da882de1e6592e371d39349c1282e65ad05cb7cbe613e232bf7f7fa9440601ecce47b321063f3c9a0c5f2d5af2909cad
6
+ metadata.gz: 6ccc7e2ed620689614bdfae8943b8c15b81b4567d3b42e2c734ac7974699ed231272ce52929eff9d49eb25edd843ae3f7fa2398d0552b77665be779a4412461f
7
+ data.tar.gz: 1e866b4aaafb534f946da5e00efb50536a4d20bf0e1527f8641fb298cca5cc6b7d0e1f744f63da443b9920500d7d4ddf0113ffa8bde2b4689cd6793538a12b6e
@@ -1,5 +1,9 @@
1
1
  ## HEAD (unreleased)
2
2
 
3
+ ## 0.1.5
4
+
5
+ - Strip out heredocs in documents first (https://github.com/zombocom/syntax_search/pull/19)
6
+
3
7
  ## 0.1.4
4
8
 
5
9
  - Parser gem replaced with Ripper (https://github.com/zombocom/syntax_search/pull/17)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_search (0.1.4)
4
+ syntax_search (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -141,3 +141,4 @@ require_relative "syntax_search/parse_blocks_from_indent_line"
141
141
 
142
142
  require_relative "syntax_search/code_search"
143
143
  require_relative "syntax_search/who_dis_syntax_error"
144
+ require_relative "syntax_search/heredoc_block_parse"
@@ -31,6 +31,10 @@ module SyntaxErrorSearch
31
31
  to_s.strip == "end"
32
32
  end
33
33
 
34
+ def hidden?
35
+ @lines.all?(&:hidden?)
36
+ end
37
+
34
38
  def starts_at
35
39
  @starts_at ||= @lines.first&.line_number
36
40
  end
@@ -28,13 +28,14 @@ module SyntaxErrorSearch
28
28
  private; attr_reader :frontier; public
29
29
  public; attr_reader :invalid_blocks, :record_dir, :code_lines
30
30
 
31
- def initialize(string, record_dir: ENV["SYNTAX_SEARCH_RECORD_DIR"])
31
+ def initialize(source, record_dir: ENV["SYNTAX_SEARCH_RECORD_DIR"])
32
+ @source = source
32
33
  if record_dir
33
34
  @time = Time.now.strftime('%Y-%m-%d-%H-%M-%s-%N')
34
35
  @record_dir = Pathname(record_dir).join(@time).tap {|p| p.mkpath }
35
36
  @write_count = 0
36
37
  end
37
- @code_lines = string.lines.map.with_index do |line, i|
38
+ @code_lines = source.lines.map.with_index do |line, i|
38
39
  CodeLine.new(line: line, index: i)
39
40
  end
40
41
  @frontier = CodeFrontier.new(code_lines: @code_lines)
@@ -107,8 +108,19 @@ module SyntaxErrorSearch
107
108
  push(block, name: "expand")
108
109
  end
109
110
 
111
+
112
+ def sweep_heredocs
113
+ HeredocBlockParse.new(
114
+ source: @source,
115
+ code_lines: @code_lines
116
+ ).call.each do |block|
117
+ push(block, name: "heredoc")
118
+ end
119
+ end
120
+
110
121
  # Main search loop
111
122
  def call
123
+ sweep_heredocs
112
124
  until frontier.holds_all_syntax_errors?
113
125
  @tick += 1
114
126
 
@@ -20,7 +20,7 @@ module SyntaxErrorSearch
20
20
  end
21
21
 
22
22
  def call
23
- if @blocks.any?
23
+ if @blocks.any? { |b| !b.hidden? }
24
24
  found_invalid_blocks
25
25
  else
26
26
  @io.puts "Syntax OK"
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SyntaxErrorSearch
4
+ # Takes in a source, and returns blocks containing each heredoc
5
+ class HeredocBlockParse
6
+ private; attr_reader :code_lines, :lex; public
7
+
8
+ def initialize(source:, code_lines: )
9
+ @code_lines = code_lines
10
+ @lex = Ripper.lex(source)
11
+ end
12
+
13
+ def call
14
+ blocks = []
15
+ beginning = []
16
+ @lex.each do |(line, col), event, *_|
17
+ case event
18
+ when :on_heredoc_beg
19
+ beginning << line
20
+ when :on_heredoc_end
21
+ start_index = beginning.pop - 1
22
+ end_index = line - 1
23
+ blocks << CodeBlock.new(lines: code_lines[start_index..end_index])
24
+ end
25
+ end
26
+
27
+ blocks
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SyntaxErrorSearch
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
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
4
+ version: 0.1.5
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-23 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: When you get an "unexpected end" in your syntax this gem helps you find
14
14
  it
@@ -45,6 +45,7 @@ files:
45
45
  - lib/syntax_search/code_search.rb
46
46
  - lib/syntax_search/display_invalid_blocks.rb
47
47
  - lib/syntax_search/fyi.rb
48
+ - lib/syntax_search/heredoc_block_parse.rb
48
49
  - lib/syntax_search/parse_blocks_from_indent_line.rb
49
50
  - lib/syntax_search/version.rb
50
51
  - lib/syntax_search/who_dis_syntax_error.rb
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
73
  requirements: []
73
- rubygems_version: 3.0.3
74
+ rubygems_version: 3.1.4
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Find syntax errors in your source in a snap