haml_lint 0.37.1 → 0.40.1

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: 8863f65bfdd024cd8dcb34e0c0f76401798afc1ba86e3f68a1bf128fad4d7a0e
4
- data.tar.gz: c659429275e92bbc87200848bd616c73cf1a9a418ea8c5bc042425cbb0c34dae
3
+ metadata.gz: 1655e5263c92bb0a391c1e56aea103792409f17a72deafb16818844fd5f6d7c8
4
+ data.tar.gz: 65d4539637d4caf656940041040ad33227a0d89eb923207fb5fedafcf357f0bd
5
5
  SHA512:
6
- metadata.gz: 9281eed257dc6972cbe29fe8e9d1f00affd6f1d8bb6880ae4e10a6252722e65feaac262a148b94ed25ebfd401e4ec17403169ea5a0613a0fa56921cbcb34585f
7
- data.tar.gz: 8bd38dfe3c05da8ce82d7a021c22eba361af40d53d07a38b55c2b4452e05fcc3efce99f556f7725a51b21f66b9f36993f77ebc3596cd7bd367e89054b4fafd06
6
+ metadata.gz: 1f08f1952a5a9ab8adc6b5c6730ec0a441ccdc10ac1a59922f77bc54c74fc95db3b49e732400aef960c4bae7581950fb21874e78d3b516e22d5cc61dc914da72
7
+ data.tar.gz: 91af5862db990bc021c1088b0de462f5f3a84ad7509cc62498ee4ac70a11f05b423d7778deead53da353253f38d76d5c84cde5417d1da3ac43bccc23f16a4753
data/lib/haml_lint/cli.rb CHANGED
@@ -94,7 +94,7 @@ module HamlLint
94
94
  # @return [HamlLint::Reporter]
95
95
  def reporter_from_options(options)
96
96
  if options[:auto_gen_config]
97
- HamlLint::Reporter::DisabledConfigReporter.new(log, limit: options[:auto_gen_exclude_limit] || 15) # rubocop:disable Layout/LineLength
97
+ HamlLint::Reporter::DisabledConfigReporter.new(log, limit: options[:auto_gen_exclude_limit] || 15)
98
98
  else
99
99
  options.fetch(:reporter, HamlLint::Reporter::DefaultReporter).new(log)
100
100
  end
@@ -97,7 +97,7 @@ module HamlLint
97
97
  def validate
98
98
  ensure_exclude_option_array_exists
99
99
  ensure_linter_section_exists
100
- ensure_linter_include_exclude_arrays_exist
100
+ ensure_linter_include_exclude_arrays_valid
101
101
  ensure_linter_severity_valid
102
102
  end
103
103
 
@@ -113,11 +113,11 @@ module HamlLint
113
113
 
114
114
  # Ensure `include` and `exclude` options for linters are arrays
115
115
  # (since users can specify a single string glob pattern for convenience)
116
- def ensure_linter_include_exclude_arrays_exist
116
+ def ensure_linter_include_exclude_arrays_valid
117
117
  @hash['linters'].each_key do |linter_name|
118
118
  %w[include exclude].each do |option|
119
119
  linter_config = @hash['linters'][linter_name]
120
- linter_config[option] = Array(linter_config[option])
120
+ linter_config[option] = Array(linter_config[option]) if linter_config[option]
121
121
  end
122
122
  end
123
123
  end
@@ -27,8 +27,6 @@ module HamlLint
27
27
  find_lints(extracted_source.source, extracted_source.source_map)
28
28
  end
29
29
 
30
- private
31
-
32
30
  # A single CLI instance is shared between files to avoid RuboCop
33
31
  # having to repeatedly reload .rubocop.yml.
34
32
  def self.rubocop_cli
@@ -37,6 +35,8 @@ module HamlLint
37
35
  @rubocop_cli ||= ::RuboCop::CLI.new
38
36
  end
39
37
 
38
+ private
39
+
40
40
  # Executes RuboCop against the given Ruby code and records the offenses as
41
41
  # lints.
42
42
  #
@@ -9,7 +9,7 @@ module HamlLint
9
9
 
10
10
  ALLOWED_SEPARATORS = [' ', '#'].freeze
11
11
 
12
- def visit_tag(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
12
+ def visit_tag(node) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
13
13
  # If this tag has inline script
14
14
  return unless node.contains_script?
15
15
 
@@ -9,15 +9,15 @@ module HamlLint
9
9
  STYLE = {
10
10
  'no_space' => {
11
11
  start_regex: /\A\{[^ ]/,
12
- end_regex: /[^ ]\}\z/,
12
+ end_regex: /(?:^\s*\}|[^ ]\})\z/,
13
13
  start_message: 'Hash attribute should start with no space after the opening brace',
14
- end_message: 'Hash attribute should end with no space before the closing brace'
14
+ end_message: 'Hash attribute should end with no space before the closing brace or be on its own line'
15
15
  },
16
16
  'space' => {
17
- start_regex: /\A\{ [^ ]/,
18
- end_regex: /[^ ] \}\z/,
17
+ start_regex: /\A\{(?: [^ ]|$)/,
18
+ end_regex: /(?:^\s*\}|[^ ] \})\z/,
19
19
  start_message: 'Hash attribute should start with one space after the opening brace',
20
- end_message: 'Hash attribute should end with one space before the closing brace'
20
+ end_message: 'Hash attribute should end with one space before the closing brace or be on its own line'
21
21
  }
22
22
  }.freeze
23
23
 
@@ -64,7 +64,7 @@ module HamlLint
64
64
  def run_linter_on_file?(config, linter, file)
65
65
  linter_config = config.for_linter(linter)
66
66
 
67
- if linter_config['include'].any? &&
67
+ if linter_config['include'] &&
68
68
  !HamlLint::Utils.any_glob_matches?(linter_config['include'], file)
69
69
  return false
70
70
  end
@@ -38,7 +38,7 @@ module HamlLint
38
38
  end
39
39
 
40
40
  parser.on('--auto-gen-exclude-limit limit', Integer,
41
- 'Number of failures to allow in the TODO list before the entire rule is excluded') do |limit| # rubocop:disable Layout/LineLength
41
+ 'Number of failures to allow in the TODO list before the entire rule is excluded') do |limit|
42
42
  @options[:auto_gen_exclude_limit] = limit
43
43
  end
44
44
 
@@ -62,7 +62,7 @@ module HamlLint
62
62
  parser.on('-r', '--reporter reporter', String,
63
63
  'Specify which reporter you want to use to generate the output. One of:',
64
64
  *reporters.map { |name| " - #{name}" }) do |reporter|
65
- @options[:reporter] = load_reporter_class(reporter.capitalize)
65
+ @options[:reporter] = load_reporter_class(reporter.split('-').map(&:capitalize).join)
66
66
  end
67
67
 
68
68
  parser.on('--fail-fast', 'Fail after the first file with lint at or above the fail level') do
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: false
2
+
3
+ module HamlLint
4
+ # Outputs the a list of lints with a count of how many of each were found.
5
+ # Ordered by descending count
6
+ class Reporter::OffenseCountReporter < Reporter
7
+ def display_report(report)
8
+ lints = report.lints
9
+ total_count = lints.count
10
+ return if total_count.zero?
11
+
12
+ lints.group_by { |l| lint_type_group(l) }
13
+ .map { |linter, lints_for_this_linter| [linter, lints_for_this_linter.size] }.to_h
14
+ .sort_by { |_linter, lint_count| -lint_count }
15
+ .each do |linter, lint_count|
16
+ log.log "#{lint_count.to_s.ljust(total_count.to_s.length + 2)} #{linter}"
17
+ end
18
+
19
+ log.log '--'
20
+ log.log "#{total_count} Total"
21
+ end
22
+
23
+ private
24
+
25
+ def lint_type_group(lint)
26
+ "#{lint.linter.name}#{offense_type(lint)}"
27
+ end
28
+
29
+ def offense_type(lint)
30
+ ": #{lint.message.to_s.split(':')[0]}" if lint.linter.name == 'RuboCop'
31
+ end
32
+ end
33
+ end
@@ -32,7 +32,13 @@ module HamlLint
32
32
  #
33
33
  # @return [String]
34
34
  def self.cli_name
35
- name.split('::').last.sub(/Reporter$/, '').downcase
35
+ name
36
+ .split('::')
37
+ .last
38
+ .sub(/Reporter$/, '')
39
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2')
40
+ .gsub(/([a-z\d])([A-Z])/, '\1-\2')
41
+ .downcase
36
42
  end
37
43
 
38
44
  # Creates the reporter that will display the given report.
@@ -9,7 +9,13 @@ module HamlLint::Tree
9
9
  #
10
10
  # @return [ParsedRuby] syntax tree in the form returned by Parser gem
11
11
  def parsed_script
12
- HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(script))
12
+ statement =
13
+ if children.empty?
14
+ script
15
+ else
16
+ "#{script}#{@value[:keyword] == 'case' ? ';when 0;end' : ';end'}"
17
+ end
18
+ HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(statement))
13
19
  end
14
20
 
15
21
  # Returns the source for the script following the `-` marker.
@@ -8,7 +8,22 @@ module HamlLint::Tree
8
8
  #
9
9
  # @return [ParsedRuby] syntax tree in the form returned by Parser gem
10
10
  def parsed_script
11
- HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(script))
11
+ statement =
12
+ case keyword = @value[:keyword]
13
+ when 'else', 'elsif'
14
+ 'if 0;' + script + ';end'
15
+ when 'when'
16
+ 'case;' + script + ';end'
17
+ when 'rescue', 'ensure'
18
+ 'begin;' + script + ';end'
19
+ else
20
+ if children.empty?
21
+ script
22
+ else
23
+ "#{script}#{keyword == 'case' ? ';when 0;end' : ';end'}"
24
+ end
25
+ end
26
+ HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(statement))
12
27
  end
13
28
 
14
29
  # Returns the source for the script following the `-` marker.
@@ -52,7 +52,7 @@ module HamlLint
52
52
  # the text.
53
53
  # @yieldparam interpolated_code [String] code that was interpolated
54
54
  # @yieldparam line [Integer] line number code appears on in text
55
- def extract_interpolated_values(text) # rubocop:disable Metrics/AbcSize
55
+ def extract_interpolated_values(text)
56
56
  dumped_text = text.dump
57
57
  newline_positions = extract_substring_positions(dumped_text, '\\\n')
58
58
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.37.1'
5
+ VERSION = '0.40.1'
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.37.1
4
+ version: 0.40.1
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: 2021-06-22 00:00:00.000000000 Z
11
+ date: 2022-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -158,6 +158,7 @@ files:
158
158
  - lib/haml_lint/reporter/hash_reporter.rb
159
159
  - lib/haml_lint/reporter/hooks.rb
160
160
  - lib/haml_lint/reporter/json_reporter.rb
161
+ - lib/haml_lint/reporter/offense_count_reporter.rb
161
162
  - lib/haml_lint/reporter/progress_reporter.rb
162
163
  - lib/haml_lint/reporter/utils.rb
163
164
  - lib/haml_lint/ruby_extractor.rb
@@ -185,7 +186,7 @@ homepage: https://github.com/sds/haml-lint
185
186
  licenses:
186
187
  - MIT
187
188
  metadata: {}
188
- post_install_message:
189
+ post_install_message:
189
190
  rdoc_options: []
190
191
  require_paths:
191
192
  - lib
@@ -200,8 +201,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
201
  - !ruby/object:Gem::Version
201
202
  version: '0'
202
203
  requirements: []
203
- rubygems_version: 3.1.4
204
- signing_key:
204
+ rubygems_version: 3.1.6
205
+ signing_key:
205
206
  specification_version: 4
206
207
  summary: HAML lint tool
207
208
  test_files: []