haml_lint 0.33.0 → 0.36.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 +6 -1
- 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 +13 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d2be98b8d977ca5ccbcb29baf2f0fd8d1b527d44b3a9929a55c538df46d5a82
|
4
|
+
data.tar.gz: 7b5a39a010d171a7487b90c4cf1be92ed9d62f6dc2c223fe5e81bb2e75652be8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16061fce86f6da8868f2f78b19b92e8184efb80e6f73fd2b0101359466c2123abea947e7cb3b1729b005ef6144ddac5604e7ac28a4646b04c3d213c6ceaf052f
|
7
|
+
data.tar.gz: a355b4893f8a7ada12d66ab61b25150a032b2cdfb5f69a9f3dfbf71f2b338bd946ed164e6b614a2dc6e647be5785d3268353f82a30f31b9efa5d4d4c90b6b356
|
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|
|
@@ -56,7 +56,12 @@ module HamlLint
|
|
56
56
|
# @param file [String]
|
57
57
|
# @return [Array<RuboCop::Cop::Offense>]
|
58
58
|
def lint_file(rubocop, file)
|
59
|
-
rubocop.run(rubocop_flags << file)
|
59
|
+
status = rubocop.run(rubocop_flags << file)
|
60
|
+
unless [::RuboCop::CLI::STATUS_SUCCESS, ::RuboCop::CLI::STATUS_OFFENSES].include?(status)
|
61
|
+
raise HamlLint::Exceptions::ConfigurationError,
|
62
|
+
"RuboCop exited unsuccessfully with status #{status}." \
|
63
|
+
' Check the stack trace to see if there was a misconfiguration.'
|
64
|
+
end
|
60
65
|
OffenseCollector.offenses
|
61
66
|
end
|
62
67
|
|
@@ -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.36.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: 2020-10-01 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,41 +29,35 @@ dependencies:
|
|
29
29
|
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '5.
|
32
|
+
version: '5.3'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: parallel
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '1.10'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '1.10'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: rainbow
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
54
|
-
- - "<"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '13'
|
53
|
+
version: '0'
|
57
54
|
type: :runtime
|
58
55
|
prerelease: false
|
59
56
|
version_requirements: !ruby/object:Gem::Requirement
|
60
57
|
requirements:
|
61
58
|
- - ">="
|
62
59
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
64
|
-
- - "<"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '13'
|
60
|
+
version: '0'
|
67
61
|
- !ruby/object:Gem::Dependency
|
68
62
|
name: rubocop
|
69
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
200
|
- !ruby/object:Gem::Version
|
207
201
|
version: '0'
|
208
202
|
requirements: []
|
209
|
-
rubygems_version: 3.
|
203
|
+
rubygems_version: 3.1.1
|
210
204
|
signing_key:
|
211
205
|
specification_version: 4
|
212
206
|
summary: HAML lint tool
|