haml_lint 0.34.1 → 0.37.1

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: 2e13afbca153d2eb77c44ea3c266bf1a970ef71aa5d8efaa3c956870f69d76e0
4
- data.tar.gz: 7b48e11ccc6bec1d6750c5905df9b05b48980163a87c2b00dad45a6364ef35df
3
+ metadata.gz: 8863f65bfdd024cd8dcb34e0c0f76401798afc1ba86e3f68a1bf128fad4d7a0e
4
+ data.tar.gz: c659429275e92bbc87200848bd616c73cf1a9a418ea8c5bc042425cbb0c34dae
5
5
  SHA512:
6
- metadata.gz: 17cb994e2f2498745c02b2c584f23b03a81a67fa4f6fb4d1f1b2d9421e4d2426fbe04c39d1d49288d10bf14c7b0dde2d2f2c2dbc991a5e7839f6085438d4984b
7
- data.tar.gz: 553834970edaffca09efba96a422ee73d45251a5c48d1e15a01a3cf0184d2d8e90392cd663d4f836e061a7486b061998859032b090c6916a968b66019ac9b581
6
+ metadata.gz: 9281eed257dc6972cbe29fe8e9d1f00affd6f1d8bb6880ae4e10a6252722e65feaac262a148b94ed25ebfd401e4ec17403169ea5a0613a0fa56921cbcb34585f
7
+ data.tar.gz: 8bd38dfe3c05da8ce82d7a021c22eba361af40d53d07a38b55c2b4452e05fcc3efce99f556f7725a51b21f66b9f36993f77ebc3596cd7bd367e89054b4fafd06
data/config/default.yml CHANGED
@@ -93,11 +93,13 @@ 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
99
100
  - Layout/HashAlignment
100
101
  - Layout/IndentationWidth
102
+ - Layout/LineLength # renamed from Metrics/LineLength in rubocop 0.79.0
101
103
  - Layout/ParameterAlignment
102
104
  - Layout/TrailingBlankLines # renamed to Layout/TrailingEmptyLines in rubocop 0.77
103
105
  - Layout/TrailingEmptyLines
data/lib/haml_lint.rb CHANGED
@@ -26,16 +26,16 @@ require 'haml_lint/severity'
26
26
  # Load all parse tree node classes
27
27
  require 'haml_lint/tree/node'
28
28
  require 'haml_lint/node_transformer'
29
- Dir[File.expand_path('haml_lint/tree/*.rb', File.dirname(__FILE__))].each do |file|
29
+ Dir[File.expand_path('haml_lint/tree/*.rb', File.dirname(__FILE__))].sort.each do |file|
30
30
  require file
31
31
  end
32
32
 
33
33
  # Load all linters
34
- Dir[File.expand_path('haml_lint/linter/*.rb', File.dirname(__FILE__))].each do |file|
34
+ Dir[File.expand_path('haml_lint/linter/*.rb', File.dirname(__FILE__))].sort.each do |file|
35
35
  require file
36
36
  end
37
37
 
38
38
  # Load all reporters
39
- Dir[File.expand_path('haml_lint/reporter/*.rb', File.dirname(__FILE__))].each do |file|
39
+ Dir[File.expand_path('haml_lint/reporter/*.rb', File.dirname(__FILE__))].sort.each do |file|
40
40
  require file
41
41
  end
@@ -19,7 +19,7 @@ module HamlLint
19
19
  version = haml_version
20
20
  case version
21
21
  when '~> 4.0' then HamlLint::Adapter::Haml4
22
- when '~> 5.0', '~> 5.1' then HamlLint::Adapter::Haml5
22
+ when '~> 5.0', '~> 5.1', '~> 5.2' then HamlLint::Adapter::Haml5
23
23
  else fail HamlLint::Exceptions::UnknownHamlVersion, "Cannot handle Haml version: #{version}"
24
24
  end
25
25
  end
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 Metrics/LineLength
97
+ HamlLint::Reporter::DisabledConfigReporter.new(log, limit: options[:auto_gen_exclude_limit] || 15) # rubocop:disable Layout/LineLength
98
98
  else
99
99
  options.fetch(:reporter, HamlLint::Reporter::DefaultReporter).new(log)
100
100
  end
@@ -29,6 +29,14 @@ module HamlLint
29
29
 
30
30
  private
31
31
 
32
+ # A single CLI instance is shared between files to avoid RuboCop
33
+ # having to repeatedly reload .rubocop.yml.
34
+ def self.rubocop_cli
35
+ # The ivar is stored on the class singleton rather than the Linter instance
36
+ # because it can't be Marshal.dump'd (as used by Parallel.map)
37
+ @rubocop_cli ||= ::RuboCop::CLI.new
38
+ end
39
+
32
40
  # Executes RuboCop against the given Ruby code and records the offenses as
33
41
  # lints.
34
42
  #
@@ -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
 
@@ -56,7 +62,12 @@ module HamlLint
56
62
  # @param file [String]
57
63
  # @return [Array<RuboCop::Cop::Offense>]
58
64
  def lint_file(rubocop, file)
59
- rubocop.run(rubocop_flags << file)
65
+ status = rubocop.run(rubocop_flags << file)
66
+ unless [::RuboCop::CLI::STATUS_SUCCESS, ::RuboCop::CLI::STATUS_OFFENSES].include?(status)
67
+ raise HamlLint::Exceptions::ConfigurationError,
68
+ "RuboCop exited unsuccessfully with status #{status}." \
69
+ ' Check the stack trace to see if there was a misconfiguration.'
70
+ end
60
71
  OffenseCollector.offenses
61
72
  end
62
73
 
@@ -43,7 +43,7 @@ module HamlLint
43
43
  # given special treatment, thus making enclosing it in a string necessary.
44
44
  def starts_with_reserved_character?(stringish)
45
45
  string = stringish.respond_to?(:children) ? stringish.children.first : stringish
46
- string =~ %r{\A\s*[/#-=%~]}
46
+ string =~ %r{\A\s*[/#-=%~]} if string.is_a?(String)
47
47
  end
48
48
  end
49
49
  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 Metrics/LineLength
41
+ 'Number of failures to allow in the TODO list before the entire rule is excluded') do |limit| # rubocop:disable Layout/LineLength
42
42
  @options[:auto_gen_exclude_limit] = limit
43
43
  end
44
44
 
@@ -51,6 +51,10 @@ module HamlLint
51
51
  "Specify which linters you don't want to run") do |linters|
52
52
  @options[:excluded_linters] = linters
53
53
  end
54
+
55
+ parser.on('-p', '--parallel', 'Run linters in parallel using available CPUs') do
56
+ @options[:parallel] = true
57
+ end
54
58
  end
55
59
 
56
60
  def add_report_options(parser)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'parallel'
4
+
3
5
  module HamlLint
4
6
  # Responsible for running the applicable linters against the desired files.
5
7
  class Runner
@@ -21,6 +23,7 @@ module HamlLint
21
23
  @files = extract_applicable_files(config, options)
22
24
  @linter_selector = HamlLint::LinterSelector.new(config, options)
23
25
  @fail_fast = options.fetch(:fail_fast, false)
26
+ @cache = {}
24
27
 
25
28
  report(options)
26
29
  end
@@ -121,7 +124,7 @@ module HamlLint
121
124
  # @param report [HamlLint::Report]
122
125
  # @return [void]
123
126
  def process_file(file, report)
124
- lints = collect_lints(file, linter_selector, config)
127
+ lints = @cache[file] || collect_lints(file, linter_selector, config)
125
128
  lints.each { |lint| report.add_lint(lint) }
126
129
  report.finish_file(file, lints)
127
130
  end
@@ -134,8 +137,20 @@ module HamlLint
134
137
  def report(options)
135
138
  report = HamlLint::Report.new(reporter: options[:reporter], fail_level: options[:fail_level])
136
139
  report.start(@files)
140
+ warm_cache if options[:parallel]
137
141
  process_files(report)
138
142
  report
139
143
  end
144
+
145
+ # Cache the result of processing lints in parallel.
146
+ #
147
+ # @return [void]
148
+ def warm_cache
149
+ results = Parallel.map(files) do |file|
150
+ lints = collect_lints(file, linter_selector, config)
151
+ [file, lints]
152
+ end
153
+ @cache = results.to_h
154
+ end
140
155
  end
141
156
  end
@@ -17,7 +17,9 @@ module HamlLint::Tree
17
17
  # @param line [Integer] the line number of the node
18
18
  # @return [HamlLint::Node]
19
19
  def node_for_line(line)
20
- find(-> { HamlLint::Tree::NullNode.new }) { |node| node.line_numbers.cover?(line) }
20
+ find(-> { HamlLint::Tree::NullNode.new }) do |node|
21
+ node.line_numbers.cover?(line) && node != self
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module HamlLint::Tree
4
4
  # Represents a tag node in a HAML document.
5
- class TagNode < Node # rubocop:disable ClassLength
5
+ class TagNode < Node # rubocop:disable Metrics/ClassLength
6
6
  # Computed set of attribute hashes code.
7
7
  #
8
8
  # This is a combination of all dynamically calculated attributes from the
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.34.1'
5
+ VERSION = '0.37.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.34.1
4
+ version: 0.37.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: 2019-12-10 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.2'
22
+ version: '5.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,21 @@ dependencies:
29
29
  version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.2'
32
+ version: '5.3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: parallel
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.10'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.10'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rainbow
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +185,7 @@ homepage: https://github.com/sds/haml-lint
171
185
  licenses:
172
186
  - MIT
173
187
  metadata: {}
174
- post_install_message:
188
+ post_install_message:
175
189
  rdoc_options: []
176
190
  require_paths:
177
191
  - lib
@@ -186,8 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
200
  - !ruby/object:Gem::Version
187
201
  version: '0'
188
202
  requirements: []
189
- rubygems_version: 3.0.3
190
- signing_key:
203
+ rubygems_version: 3.1.4
204
+ signing_key:
191
205
  specification_version: 4
192
206
  summary: HAML lint tool
193
207
  test_files: []