haml_lint 0.34.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +7 -3
- data/lib/haml_lint.rb +3 -3
- data/lib/haml_lint/adapter.rb +1 -1
- data/lib/haml_lint/cli.rb +1 -1
- data/lib/haml_lint/file_finder.rb +1 -1
- data/lib/haml_lint/linter/repeated_id.rb +1 -1
- data/lib/haml_lint/linter/rubocop.rb +15 -4
- data/lib/haml_lint/linter/space_before_script.rb +1 -1
- data/lib/haml_lint/linter/unnecessary_string_output.rb +2 -2
- data/lib/haml_lint/options.rb +5 -1
- data/lib/haml_lint/runner.rb +16 -1
- data/lib/haml_lint/tree/root_node.rb +3 -1
- data/lib/haml_lint/tree/tag_node.rb +1 -1
- data/lib/haml_lint/utils.rb +1 -1
- data/lib/haml_lint/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a68b2308ea5b74941d9db3d5dfe22fa181bac800f89049c61db6ed533f381ca8
|
4
|
+
data.tar.gz: 78fc8f6241ad3cccace23abd95818ba461097ef4a11e51d5ec091de82de9e2ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 145a57a93ecf9960435ccd40fb02819e560bf4557be450494b5d3d1c920e65089925959b2377156172ed5cb10cbfbfd79a690b6b7c0ea99eb282ce2a3c7f5cd0
|
7
|
+
data.tar.gz: 81e45f26624c737b2cf750027aaca241d3c4c08ab0c05ad0233d802e75f4de803d5401ccf90c527416aec7987d00b1fe5a8ce8856c7bedba70a86243c5d3b26b
|
data/config/default.yml
CHANGED
@@ -91,13 +91,17 @@ linters:
|
|
91
91
|
- Lint/BlockAlignment
|
92
92
|
- Lint/EndAlignment
|
93
93
|
- Lint/Void
|
94
|
-
- Layout/AlignHash
|
95
|
-
- Layout/AlignParameters
|
94
|
+
- Layout/AlignHash # renamed to Layout/HashAlignment in rubocop 0.77
|
95
|
+
- Layout/AlignParameters # renamed to Layout/ParameterAlignment in rubocop 0.77
|
96
96
|
- Layout/CaseIndentation
|
97
97
|
- Layout/ElseAlignment
|
98
98
|
- Layout/EndOfLine
|
99
|
+
- Layout/HashAlignment
|
99
100
|
- Layout/IndentationWidth
|
100
|
-
- Layout/
|
101
|
+
- Layout/LineLength # renamed from Metrics/LineLength in rubocop 0.79.0
|
102
|
+
- Layout/ParameterAlignment
|
103
|
+
- Layout/TrailingBlankLines # renamed to Layout/TrailingEmptyLines in rubocop 0.77
|
104
|
+
- Layout/TrailingEmptyLines
|
101
105
|
- Layout/TrailingWhitespace
|
102
106
|
- Metrics/BlockLength
|
103
107
|
- Metrics/BlockNesting
|
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
|
data/lib/haml_lint/adapter.rb
CHANGED
@@ -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
|
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
|
@@ -40,7 +40,7 @@ module HamlLint
|
|
40
40
|
#
|
41
41
|
# @param patterns [Array<String>]
|
42
42
|
# @return [Array<String>]
|
43
|
-
def extract_files_from(patterns) # rubocop:disable MethodLength
|
43
|
+
def extract_files_from(patterns) # rubocop:disable Metrics/MethodLength
|
44
44
|
files = []
|
45
45
|
|
46
46
|
patterns.each do |pattern|
|
@@ -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(
|
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
|
|
@@ -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/
|
12
|
+
def visit_tag(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
13
13
|
# If this tag has inline script
|
14
14
|
return unless node.contains_script?
|
15
15
|
|
@@ -35,7 +35,7 @@ module HamlLint
|
|
35
35
|
return unless tree = parse_ruby(script_node.script)
|
36
36
|
%i[str dstr].include?(tree.type) &&
|
37
37
|
!starts_with_reserved_character?(tree.children.first)
|
38
|
-
rescue ::Parser::SyntaxError # rubocop:disable Lint/
|
38
|
+
rescue ::Parser::SyntaxError # rubocop:disable Lint/SuppressedException
|
39
39
|
# Gracefully ignore syntax errors, as that's managed by a different linter
|
40
40
|
end
|
41
41
|
|
@@ -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
|
data/lib/haml_lint/options.rb
CHANGED
@@ -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
|
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)
|
data/lib/haml_lint/runner.rb
CHANGED
@@ -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 })
|
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
|
data/lib/haml_lint/utils.rb
CHANGED
@@ -66,7 +66,7 @@ module HamlLint
|
|
66
66
|
dumped_interpolated_str = Haml::Util.balance(scan, '{', '}', 1)[0][0...-1]
|
67
67
|
|
68
68
|
# Hacky way to turn a dumped string back into a regular string
|
69
|
-
yield [eval('"' + dumped_interpolated_str + '"'), line] # rubocop:disable Eval
|
69
|
+
yield [eval('"' + dumped_interpolated_str + '"'), line] # rubocop:disable Security/Eval
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
data/lib/haml_lint/version.rb
CHANGED
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.
|
4
|
+
version: 0.37.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:
|
11
|
+
date: 2021-01-07 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.
|
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.
|
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
|
@@ -186,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
200
|
- !ruby/object:Gem::Version
|
187
201
|
version: '0'
|
188
202
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
203
|
+
rubygems_version: 3.1.4
|
190
204
|
signing_key:
|
191
205
|
specification_version: 4
|
192
206
|
summary: HAML lint tool
|