haml_lint 0.56.0 → 0.58.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0bb69db6857a5c9b072203e93e4c9964bd60a9f8e4f1024e4db31453deec8a6
4
- data.tar.gz: 94fcce12ae043e72f638d532fcddccfad2de1c8af33a261c37920fa738c4609e
3
+ metadata.gz: 6962d4b0d9f7f60b473641303f1ef1b8962797bf7abdeb8db4e57b36df65f7d3
4
+ data.tar.gz: 214c0ccb902d9c742af8df5f4e65fc221f6ae9bec572b7a535df0ee682b5dfac
5
5
  SHA512:
6
- metadata.gz: 973dd46634cfde27066acfcd5d44bebc538716f7ca0d34114b183c19808513fc397b688a66664f6bf1b5ae0367762d4daa7f203d894cd3eb068bcbcfdc12edc5
7
- data.tar.gz: ac57887f196f37a3f2f40b77cc5c1e24dd2b29bc29a9d693fc4a675a69ced56f4a49386e2e7a8694cfa04ecbb3ac75bb4fb412c760a0a9fe83d2d20b7bdef40a
6
+ metadata.gz: b161dc044d6a5a22be918384f7cde7b0fd9b20dc2f4408f4a535ae72ed0b7fab75b96f885db83e92ae4cce769b811118978412bbba819e6f38178fb261f040f1
7
+ data.tar.gz: fb2af5b891147f8588cf9ffcd17fccc7ef0674bf11127327addbca55c9a8c094c6e53f8f268550dc160955d4c1c889948d7285fc39027287781d3abba7f66873
@@ -6,7 +6,7 @@ module HamlLint
6
6
  include LinterRegistry
7
7
 
8
8
  def visit_silent_script(node)
9
- return unless node.script =~ /\A\s*\Z/
9
+ return unless /\A\s*\Z/.match?(node.script)
10
10
 
11
11
  record_lint(node, 'Empty script should be removed')
12
12
  end
@@ -24,7 +24,7 @@ module HamlLint
24
24
 
25
25
  style = config['style'] || 'lisp_case'
26
26
  matcher = STYLES[style]
27
- record_lint(node, "`id` attribute must be in #{STYLIZED_NAMES[style]}") unless id =~ matcher
27
+ record_lint(node, "`id` attribute must be in #{STYLIZED_NAMES[style]}") unless id&.match?(matcher)
28
28
  end
29
29
  end
30
30
  end
@@ -30,7 +30,7 @@ module HamlLint
30
30
  dummy_node = Struct.new(:line)
31
31
 
32
32
  document.source_lines.each_with_index do |line, index|
33
- next if line =~ regex
33
+ next if line&.match?(regex)
34
34
 
35
35
  unless root.node_for_line(index).disabled?(self)
36
36
  record_lint dummy_node.new(index + 1), "Line contains #{wrong_characters} in indentation"
@@ -8,7 +8,7 @@ module HamlLint
8
8
  def visit_haml_comment(node)
9
9
  # Skip if the node spans multiple lines starting on the second line,
10
10
  # or starts with a space
11
- return if node.text =~ /\A#*(\s*|\s+\S.*)$/
11
+ return if /\A#*(\s*|\s+\S.*)$/.match?(node.text)
12
12
 
13
13
  record_lint(node, 'Comment should have a space after the `#`')
14
14
  end
@@ -27,8 +27,8 @@ module HamlLint
27
27
  style = STYLE[config['style'] == 'no_space' ? 'no_space' : 'space']
28
28
  source = node.hash_attributes_source
29
29
 
30
- record_lint(node, style[:start_message]) unless source =~ style[:start_regex]
31
- record_lint(node, style[:end_message]) unless source =~ style[:end_regex]
30
+ record_lint(node, style[:start_message]) unless source&.match?(style[:start_regex])
31
+ record_lint(node, style[:end_message]) unless source&.match?(style[:end_regex])
32
32
  end
33
33
  end
34
34
  end
@@ -7,7 +7,7 @@ module HamlLint
7
7
 
8
8
  def visit_tag(node)
9
9
  tag = node.tag_name
10
- return unless tag =~ /[A-Z]/
10
+ return unless /[A-Z]/.match?(tag)
11
11
 
12
12
  record_lint(node, "`#{tag}` should be written in lowercase as `#{tag.downcase}`")
13
13
  end
@@ -9,7 +9,7 @@ module HamlLint
9
9
 
10
10
  def visit_root(root)
11
11
  document.source_lines.each_with_index do |line, index|
12
- next unless line =~ /\s+$/
12
+ next unless /\s+$/.match?(line)
13
13
 
14
14
  node = root.node_for_line(index + 1)
15
15
  unless node.disabled?(self)
@@ -22,7 +22,7 @@ module HamlLint
22
22
  def visit_script(node)
23
23
  # Some script nodes created by the HAML parser aren't actually script
24
24
  # nodes declared via the `=` marker. Check for it.
25
- return if node.source_code !~ /\A\s*=/
25
+ return unless /\A\s*=/.match?(node.source_code)
26
26
 
27
27
  if outputs_string_literal?(node)
28
28
  record_lint(node, MESSAGE)
@@ -37,7 +37,7 @@ module HamlLint
37
37
  :error
38
38
  )
39
39
  rescue StandardError => e
40
- msg = "Couldn't process the file".dup
40
+ msg = +"Couldn't process the file"
41
41
  if @autocorrect
42
42
  # Those lints related to auto-correction were not saved, so don't display them
43
43
  @lints = []
@@ -231,7 +231,7 @@ module HamlLint
231
231
  # excess whitespace
232
232
  @document.source_lines[(tag_node.line - 1)...(following_node_line(tag_node) - 1)]
233
233
  .map do |line|
234
- line.strip.gsub(/\|\z/, '').rstrip
234
+ line.strip.delete_suffix('|').rstrip
235
235
  end.join(' ')
236
236
  end
237
237
  end
@@ -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
@@ -17,6 +17,10 @@ module HamlLint::RubyExtraction
17
17
  ::Haml::Parser.new('', {})
18
18
  end
19
19
 
20
+ # HAML strips newlines when handling multi-line statements (using pipes or trailing comma)
21
+ # We don't. So the regex must be fixed to correctly detect the start of the string.
22
+ BLOCK_KEYWORD_REGEX = Regexp.new(Haml::Parser::BLOCK_KEYWORD_REGEX.source.sub('^', '\A'))
23
+
20
24
  def initialize(document, script_output_prefix:)
21
25
  @document = document
22
26
  @script_output_prefix = script_output_prefix
@@ -390,7 +394,7 @@ module HamlLint::RubyExtraction
390
394
  # is indented by 0.
391
395
  lines = node.text.split("\n")
392
396
  lines.map! do |line|
393
- if line !~ /\S/
397
+ if !/\S/.match?(line)
394
398
  # whitespace or empty
395
399
  ''
396
400
  else
@@ -546,7 +550,7 @@ module HamlLint::RubyExtraction
546
550
  joined_lines = lines.join("\n")
547
551
 
548
552
  if haml_processed_ruby_code.include?("\n")
549
- haml_processed_ruby_code = haml_processed_ruby_code.gsub("\n", ' ')
553
+ haml_processed_ruby_code = haml_processed_ruby_code.tr("\n", ' ')
550
554
  end
551
555
 
552
556
  haml_processed_ruby_code.split(/[, ]/)
@@ -692,7 +696,7 @@ module HamlLint::RubyExtraction
692
696
  return keyword
693
697
  end
694
698
 
695
- return unless keyword = code.scan(Haml::Parser::BLOCK_KEYWORD_REGEX)[0]
699
+ return unless keyword = code.scan(BLOCK_KEYWORD_REGEX)[0]
696
700
  keyword[0] || keyword[1]
697
701
  end
698
702
  end
@@ -14,7 +14,7 @@ module HamlLint::RubyExtraction
14
14
  to_content_lines = to_ruby_lines[1...-1]
15
15
 
16
16
  to_haml_lines = to_content_lines.map do |line|
17
- if line !~ /\S/
17
+ if !/\S/.match?(line)
18
18
  # whitespace or empty
19
19
  ''
20
20
  else
@@ -19,7 +19,7 @@ module HamlLint::RubyExtraction
19
19
  haml_lines[@haml_line_index - 1] = HamlLint::Utils.indent(haml_lines[@haml_line_index - 1], delta_indent)
20
20
 
21
21
  to_haml_lines = to_ruby_lines.map do |line|
22
- if line !~ /\S/
22
+ if !/\S/.match?(line)
23
23
  # whitespace or empty
24
24
  ''
25
25
  else
@@ -113,7 +113,7 @@ module HamlLint::RubyExtraction
113
113
  line_start_indexes_that_need_pipes = []
114
114
  haml_output_prefix = first_output_haml_prefix
115
115
  to_haml_lines = to_ruby_lines.map.with_index do |line, i| # rubocop:disable Metrics/BlockLength
116
- if line !~ /\S/
116
+ if !/\S/.match?(line)
117
117
  # whitespace or empty lines, we don't want any indentation
118
118
  ''
119
119
  elsif statement_start_line_indexes.include?(i)
@@ -74,7 +74,7 @@ module HamlLint
74
74
  current_matching_line = 1
75
75
  @source_map = {}
76
76
  lines.each.with_index do |line, i|
77
- next unless line =~ /\S/
77
+ next unless /\S/.match?(line)
78
78
  mo = line.match(/^(.*?)\$?\s*\$\$(\d+)$/)
79
79
  if mo
80
80
  lines[i] = mo[1]
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.56.0'
5
+ VERSION = '0.58.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.56.0
4
+ version: 0.58.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-04 00:00:00.000000000 Z
11
+ date: 2024-04-27 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
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
216
  - !ruby/object:Gem::Version
216
217
  version: '0'
217
218
  requirements: []
218
- rubygems_version: 3.4.10
219
+ rubygems_version: 3.5.9
219
220
  signing_key:
220
221
  specification_version: 4
221
222
  summary: HAML lint tool