haml_lint 0.36.0 → 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: 6d2be98b8d977ca5ccbcb29baf2f0fd8d1b527d44b3a9929a55c538df46d5a82
4
- data.tar.gz: 7b5a39a010d171a7487b90c4cf1be92ed9d62f6dc2c223fe5e81bb2e75652be8
3
+ metadata.gz: 1655e5263c92bb0a391c1e56aea103792409f17a72deafb16818844fd5f6d7c8
4
+ data.tar.gz: 65d4539637d4caf656940041040ad33227a0d89eb923207fb5fedafcf357f0bd
5
5
  SHA512:
6
- metadata.gz: 16061fce86f6da8868f2f78b19b92e8184efb80e6f73fd2b0101359466c2123abea947e7cb3b1729b005ef6144ddac5604e7ac28a4646b04c3d213c6ceaf052f
7
- data.tar.gz: a355b4893f8a7ada12d66ab61b25150a032b2cdfb5f69a9f3dfbf71f2b338bd946ed164e6b614a2dc6e647be5785d3268353f82a30f31b9efa5d4d4c90b6b356
6
+ metadata.gz: 1f08f1952a5a9ab8adc6b5c6730ec0a441ccdc10ac1a59922f77bc54c74fc95db3b49e732400aef960c4bae7581950fb21874e78d3b516e22d5cc61dc914da72
7
+ data.tar.gz: 91af5862db990bc021c1088b0de462f5f3a84ad7509cc62498ee4ac70a11f05b423d7778deead53da353253f38d76d5c84cde5417d1da3ac43bccc23f16a4753
data/config/default.yml CHANGED
@@ -93,6 +93,7 @@ linters:
93
93
  - Lint/Void
94
94
  - Layout/AlignHash # renamed to Layout/HashAlignment in rubocop 0.77
95
95
  - Layout/AlignParameters # renamed to Layout/ParameterAlignment in rubocop 0.77
96
+ - Layout/ArgumentAlignment
96
97
  - Layout/CaseIndentation
97
98
  - Layout/ElseAlignment
98
99
  - Layout/EndOfLine
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,6 +27,14 @@ module HamlLint
27
27
  find_lints(extracted_source.source, extracted_source.source_map)
28
28
  end
29
29
 
30
+ # A single CLI instance is shared between files to avoid RuboCop
31
+ # having to repeatedly reload .rubocop.yml.
32
+ def self.rubocop_cli
33
+ # The ivar is stored on the class singleton rather than the Linter instance
34
+ # because it can't be Marshal.dump'd (as used by Parallel.map)
35
+ @rubocop_cli ||= ::RuboCop::CLI.new
36
+ end
37
+
30
38
  private
31
39
 
32
40
  # Executes RuboCop against the given Ruby code and records the offenses as
@@ -36,8 +44,6 @@ module HamlLint
36
44
  # @param source_map [Hash] map of Ruby code line numbers to original line
37
45
  # numbers in the template
38
46
  def find_lints(ruby, source_map)
39
- rubocop = ::RuboCop::CLI.new
40
-
41
47
  filename =
42
48
  if document.file
43
49
  "#{document.file}.rb"
@@ -46,7 +52,7 @@ module HamlLint
46
52
  end
47
53
 
48
54
  with_ruby_from_stdin(ruby) do
49
- extract_lints_from_offenses(lint_file(rubocop, filename), source_map)
55
+ extract_lints_from_offenses(lint_file(self.class.rubocop_cli, filename), source_map)
50
56
  end
51
57
  end
52
58
 
@@ -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.36.0'
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.36.0
4
+ version: 0.40.1
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: 2020-10-01 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
@@ -200,7 +201,7 @@ 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.1
204
+ rubygems_version: 3.1.6
204
205
  signing_key:
205
206
  specification_version: 4
206
207
  summary: HAML lint tool