haml_lint 0.55.0 → 0.57.0

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: 54085c44173d09dee5402e01e6d0d6daedd8cafcf9bd680c9ff0dd58a56648ad
4
- data.tar.gz: '09cca038ff259c096d34398dc23f07d1c2a89af596eeb72389dc5e14d2aeb0af'
3
+ metadata.gz: '092e548aae63e23d9c6a5c3c11087590219e52792459ee548a5802503e80f6ec'
4
+ data.tar.gz: 120a88fbfb5b78e5d08724dffc9c7cf22292e391633c780da94161295ea745e0
5
5
  SHA512:
6
- metadata.gz: 15dfc1078747b42d5bba6af59adcf98803f05bfbc228e30322420e9c4876ba47c202a6d89412e1e30de72cfba5bc2cf1b9ffebe105717e76ee167df4540de591
7
- data.tar.gz: 0f5d12c1c4336536d3574b5d40ebb8cad94af8124def6b5273148c984271dd7e4e10c8abea51bb69d4d3ee2208fccc5a76d94060d9c6db811c19b8621fbde501
6
+ metadata.gz: 5123d876bb4b79d4fbf14fae8acef295993c909baaee63975f899571fe450cf67f503c761b2628ddb96874f39a4be51a8c489ddb94a87eb95034e3a05ba44431
7
+ data.tar.gz: 152d02d1daa2f51e9c0ddca5602d74642b324e860daa33aeec715ff4e2be297054abaf0d35dd9d15cfafcf15955bfce48823575643b18c4375707f172621eb66
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: false
2
+
3
+ module HamlLint
4
+ # Outputs GitHub workflow commands for GitHub check annotations when run within GitHub actions.
5
+ class Reporter::GithubReporter < Reporter
6
+ ESCAPE_MAP = { '%' => '%25', "\n" => '%0A', "\r" => '%0D' }.freeze
7
+
8
+ include Reporter::Utils
9
+
10
+ def added_lint(lint, report)
11
+ if lint.severity >= report.fail_level
12
+ print_workflow_command(lint: lint)
13
+ else
14
+ print_workflow_command(severity: 'warning', lint: lint)
15
+ end
16
+ end
17
+
18
+ def display_report(report)
19
+ print_summary(report)
20
+ end
21
+
22
+ private
23
+
24
+ def print_workflow_command(lint:, severity: 'error')
25
+ log.log "::#{severity} file=#{lint.filename},line=#{lint.line}::#{github_escape(lint.message)}"
26
+ end
27
+
28
+ def github_escape(string)
29
+ string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
30
+ end
31
+ end
32
+ end
@@ -247,31 +247,29 @@ module HamlLint::RubyExtraction
247
247
  def visit_tag(node)
248
248
  indent = @original_haml_lines[node.line - 1].index(/\S/)
249
249
 
250
+ @ruby_chunks << PlaceholderMarkerChunk.new(node, 'tag', indent: indent)
251
+
252
+ current_line_index = visit_tag_attributes(node, indent: indent)
253
+ visit_tag_script(node, line_index: current_line_index, indent: indent)
254
+
250
255
  # We don't want to use a block because assignments in a block are local to that block,
251
256
  # so the semantics of the extracted ruby would be different from the one generated by
252
257
  # Haml. Those differences can make some cops, such as UselessAssignment, have false
253
258
  # positives
254
259
  code = 'begin'
255
- @ruby_chunks << AdHocChunk.new(node,
256
- [' ' * indent + code])
257
- indent += 2
258
-
259
- tag_chunk = PlaceholderMarkerChunk.new(node, 'tag', indent: indent)
260
- @ruby_chunks << tag_chunk
260
+ begin_chunk = AdHocChunk.new(node, [' ' * indent + code])
261
+ @ruby_chunks << begin_chunk
261
262
 
262
- current_line_index = visit_tag_attributes(node, indent: indent)
263
- visit_tag_script(node, line_index: current_line_index, indent: indent)
263
+ indent += 2
264
264
 
265
265
  yield
266
266
 
267
267
  indent -= 2
268
268
 
269
- if @ruby_chunks.last.equal?(tag_chunk)
269
+ if @ruby_chunks.last.equal?(begin_chunk)
270
270
  # So there is nothing going "in" the tag, remove the wrapping "begin" and replace the PlaceholderMarkerChunk
271
271
  # by one less indented
272
272
  @ruby_chunks.pop
273
- @ruby_chunks.pop
274
- @ruby_chunks << PlaceholderMarkerChunk.new(node, 'tag', indent: indent)
275
273
  else
276
274
  @ruby_chunks << AdHocChunk.new(node,
277
275
  [' ' * indent + 'ensure', ' ' * indent + ' HL.noop', ' ' * indent + 'end'],
@@ -600,9 +598,12 @@ module HamlLint::RubyExtraction
600
598
  return [char_index, [haml_processed_ruby_code]]
601
599
  end
602
600
 
603
- min_non_white_chars_to_add = haml_processed_ruby_code.scan(/\S/).size
601
+ # The +1 is for the closing brace, which we need
602
+ min_non_white_chars_to_add = haml_processed_ruby_code.scan(/\S/).size + 1
604
603
 
605
- regexp = HamlLint::Utils.regexp_for_parts(haml_processed_ruby_code.split(/\s+/), '\\s+')
604
+ regexp = HamlLint::Utils.regexp_for_parts(
605
+ haml_processed_ruby_code.split(/\s+/), '\\s+', prefix: '\s*', suffix: '\s*(?=[)}])'
606
+ )
606
607
 
607
608
  joined_lines = first_line.rstrip
608
609
  process_multiline!(joined_lines)
@@ -624,7 +625,7 @@ module HamlLint::RubyExtraction
624
625
 
625
626
  first_line_offset = match.begin(0)
626
627
  raw_ruby = match[0]
627
- ruby_lines = raw_ruby.split("\n")
628
+ ruby_lines = raw_ruby.split("\n", -1)
628
629
 
629
630
  [first_line_offset, ruby_lines]
630
631
  end
@@ -115,7 +115,7 @@ module HamlLint
115
115
 
116
116
  syntax_lints = subject.lints.select { |lint| lint.message =~ %r{Lint/Syntax} }
117
117
 
118
- if start_ruby.strip != 'SKIP' && subject.last_extracted_source
118
+ if start_ruby.strip != 'SKIP' && subject.last_extracted_source && ENV['UPDATE_EXAMPLES'] != '1'
119
119
  matcher = eq(start_ruby)
120
120
  subject.last_extracted_source.source.should(
121
121
  matcher,
@@ -125,7 +125,7 @@ module HamlLint
125
125
 
126
126
  syntax_lints.should(be_empty, "Generated Ruby has Syntax Lints:\n#{format_lints(syntax_lints)}")
127
127
 
128
- if end_ruby.strip != 'SKIP' && subject.last_new_ruby_source
128
+ if end_ruby.strip != 'SKIP' && subject.last_new_ruby_source && ENV['UPDATE_EXAMPLES'] != '1'
129
129
  matcher = eq(end_ruby)
130
130
  subject.last_new_ruby_source.should(
131
131
  matcher,
@@ -141,10 +141,40 @@ module HamlLint
141
141
  -> { "Final HAML is different from expected. #{matcher.failure_message}\n#{format_lints}" }
142
142
  )
143
143
 
144
- if subject.last_extracted_source && start_ruby.strip != 'SKIP'
144
+ if subject.last_extracted_source && start_ruby.strip != 'SKIP' && ENV['UPDATE_EXAMPLES'] != '1'
145
145
  subject.last_extracted_source.source_map.should == source_map
146
146
  end
147
147
 
148
+ if ENV['UPDATE_EXAMPLES'] == '1' && respond_to?(:example_first_line_no) &&
149
+ start_ruby.strip != 'SKIP' && end_ruby.strip != 'SKIP'
150
+ original_content = File.read(example_path)
151
+ old_steps_string = '---' + steps_string.partition('---').last.rpartition('---').first + '---'
152
+
153
+ if old_steps_string.scan(/\$\$\d+/).tally.values.any? { |v| v > 1 }
154
+ # If the $$3 was there twice, let's not update the example
155
+ return
156
+ end
157
+ original_content.scan(old_steps_string).count
158
+
159
+ new_generated_ruby_lines = subject.last_extracted_source.source.split("\n", -1)
160
+ last_seen_haml_line_no = 1
161
+ subject.last_extracted_source.source_map.each do |ruby_line_no, haml_line_no|
162
+ if haml_line_no != last_seen_haml_line_no
163
+ last_seen_haml_line_no = haml_line_no
164
+ new_generated_ruby_lines[ruby_line_no - 1] += " $$#{haml_line_no}"
165
+ end
166
+ end
167
+
168
+ new_steps_string = <<~NEW.chop # Chop to remove the added newlines
169
+ ---
170
+ #{new_generated_ruby_lines.join("\n")}---
171
+ #{subject.last_new_ruby_source}---
172
+ NEW
173
+
174
+ new_content = original_content.gsub(old_steps_string, new_steps_string)
175
+ File.write(example_path, new_content)
176
+ end
177
+
148
178
  haml_different = start_haml != end_haml
149
179
  document.source_was_changed.should == haml_different
150
180
  end
@@ -277,8 +277,9 @@ module HamlLint
277
277
  $stdin = original_stdin
278
278
  end
279
279
 
280
- def regexp_for_parts(parts, join_regexp)
280
+ def regexp_for_parts(parts, join_regexp, prefix: nil, suffix: nil)
281
281
  regexp_code = parts.map { |c| Regexp.quote(c) }.join(join_regexp)
282
+ regexp_code = "#{prefix}#{regexp_code}#{suffix}"
282
283
  Regexp.new(regexp_code)
283
284
  end
284
285
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.55.0'
5
+ VERSION = '0.57.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.55.0
4
+ version: 0.57.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-23 00:00:00.000000000 Z
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -153,6 +153,7 @@ files:
153
153
  - lib/haml_lint/reporter/checkstyle_reporter.rb
154
154
  - lib/haml_lint/reporter/default_reporter.rb
155
155
  - lib/haml_lint/reporter/disabled_config_reporter.rb
156
+ - lib/haml_lint/reporter/github_reporter.rb
156
157
  - lib/haml_lint/reporter/hash_reporter.rb
157
158
  - lib/haml_lint/reporter/hooks.rb
158
159
  - lib/haml_lint/reporter/json_reporter.rb
@@ -200,7 +201,7 @@ homepage: https://github.com/sds/haml-lint
200
201
  licenses:
201
202
  - MIT
202
203
  metadata: {}
203
- post_install_message:
204
+ post_install_message:
204
205
  rdoc_options: []
205
206
  require_paths:
206
207
  - lib
@@ -215,8 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
216
  - !ruby/object:Gem::Version
216
217
  version: '0'
217
218
  requirements: []
218
- rubygems_version: 3.0.3.1
219
- signing_key:
219
+ rubygems_version: 3.4.10
220
+ signing_key:
220
221
  specification_version: 4
221
222
  summary: HAML lint tool
222
223
  test_files: []