haml_lint 0.53.0 → 0.54.0
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 +4 -4
- data/lib/haml_lint/constants.rb +1 -1
- data/lib/haml_lint/directive.rb +2 -2
- data/lib/haml_lint/document.rb +10 -1
- data/lib/haml_lint/linter/alignment_tabs.rb +1 -1
- data/lib/haml_lint/linter/class_attribute_with_static_value.rb +1 -1
- data/lib/haml_lint/linter/indentation.rb +1 -1
- data/lib/haml_lint/linter/multiline_pipe.rb +1 -1
- data/lib/haml_lint/linter/no_placeholders.rb +2 -2
- data/lib/haml_lint/options.rb +8 -2
- data/lib/haml_lint/runner.rb +39 -29
- data/lib/haml_lint/source.rb +24 -0
- data/lib/haml_lint/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b017823b15563d033480ee99317c4d0c007624b10ad2ed3b53c254c5686289c8
|
4
|
+
data.tar.gz: cf83ac415fb7749551466fcc0b23a5a2019bbecb99a67b2c54051a78523f1a33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17ea23cce399f12712d0f73560553b82068e2ac3be9124c590bbea78948a330811402c15fd2b5f8cbc0b5e8e044bc044e69df78f2e05462580665db814298595
|
7
|
+
data.tar.gz: d619d3018e139b00ce539da9b9f7e1bfef644c71c8e102d146778c3c322770458a16feb89bb44a1a3699eadacc6038c7186407fc8361e6b354f0c4bdbb2dcd57
|
data/lib/haml_lint/constants.rb
CHANGED
data/lib/haml_lint/directive.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module HamlLint
|
4
4
|
# Handles linter configuration transformation via Haml comments.
|
5
5
|
class Directive
|
6
|
-
LINTER_REGEXP = /(?:[A-Z]\w+)
|
6
|
+
LINTER_REGEXP = /(?:[A-Z]\w+)/
|
7
7
|
|
8
8
|
DIRECTIVE_REGEXP = /
|
9
9
|
# "haml-lint:" with optional spacing
|
@@ -14,7 +14,7 @@ module HamlLint
|
|
14
14
|
|
15
15
|
# "all" or a comma-separated list (with optional spaces) of linters
|
16
16
|
(?<linters>all | (?:#{LINTER_REGEXP}\s*,\s*)* #{LINTER_REGEXP})
|
17
|
-
/x
|
17
|
+
/x
|
18
18
|
|
19
19
|
# Constructs a directive from source code as a given line.
|
20
20
|
#
|
data/lib/haml_lint/document.rb
CHANGED
@@ -14,6 +14,9 @@ module HamlLint
|
|
14
14
|
# @return [String] Haml template file path
|
15
15
|
attr_reader :file
|
16
16
|
|
17
|
+
# @return [Boolean] true if source changes (from autocorrect) should be written to stdout instead of disk
|
18
|
+
attr_reader :write_to_stdout
|
19
|
+
|
17
20
|
# @return [HamlLint::Tree::Node] Root of the parse tree
|
18
21
|
attr_reader :tree
|
19
22
|
|
@@ -36,10 +39,12 @@ module HamlLint
|
|
36
39
|
# @param source [String] Haml code to parse
|
37
40
|
# @param options [Hash]
|
38
41
|
# @option options :file [String] file name of document that was parsed
|
42
|
+
# @option options :write_to_stdout [Boolean] true if source changes should be written to stdout
|
39
43
|
# @raise [Haml::Parser::Error] if there was a problem parsing the document
|
40
44
|
def initialize(source, options)
|
41
45
|
@config = options[:config]
|
42
46
|
@file = options.fetch(:file, STRING_SOURCE)
|
47
|
+
@write_to_stdout = options[:write_to_stdout]
|
43
48
|
@source_was_changed = false
|
44
49
|
process_source(source)
|
45
50
|
end
|
@@ -82,7 +87,11 @@ module HamlLint
|
|
82
87
|
if file == STRING_SOURCE
|
83
88
|
raise HamlLint::Exceptions::InvalidFilePath, 'Cannot write without :file option'
|
84
89
|
end
|
85
|
-
|
90
|
+
if @write_to_stdout
|
91
|
+
$stdout << unstrip_frontmatter(source)
|
92
|
+
else
|
93
|
+
File.write(file, unstrip_frontmatter(source))
|
94
|
+
end
|
86
95
|
@source_was_changed = false
|
87
96
|
end
|
88
97
|
|
@@ -20,7 +20,7 @@ module HamlLint
|
|
20
20
|
|
21
21
|
STATIC_TYPES = %i[str sym].freeze
|
22
22
|
|
23
|
-
VALID_CLASS_REGEX = /^-?[_a-zA-Z]+[_a-zA-Z0-9-]
|
23
|
+
VALID_CLASS_REGEX = /^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/
|
24
24
|
|
25
25
|
def visit_tag(node)
|
26
26
|
return unless contains_class_attribute?(node.dynamic_attributes_sources)
|
@@ -6,8 +6,8 @@ module HamlLint
|
|
6
6
|
include LinterRegistry
|
7
7
|
|
8
8
|
MSG = 'Placeholders attributes should not be used.'
|
9
|
-
HASH_REGEXP = /:?['"]?placeholder['"]?(?::| *=>)
|
10
|
-
HTML_REGEXP = /placeholder
|
9
|
+
HASH_REGEXP = /:?['"]?placeholder['"]?(?::| *=>)/
|
10
|
+
HTML_REGEXP = /placeholder=/
|
11
11
|
|
12
12
|
def visit_tag(node)
|
13
13
|
return unless node.hash_attributes_source =~ HASH_REGEXP || node.html_attributes_source =~ HTML_REGEXP
|
data/lib/haml_lint/options.rb
CHANGED
@@ -32,7 +32,7 @@ module HamlLint
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
def add_linter_options(parser) # rubocop:disable Metrics/MethodLength
|
35
|
+
def add_linter_options(parser) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
36
36
|
parser.on('--auto-gen-config', 'Generate a configuration file acting as a TODO list') do
|
37
37
|
@options[:auto_gen_config] = true
|
38
38
|
end
|
@@ -70,7 +70,13 @@ module HamlLint
|
|
70
70
|
@options[:autocorrect] ||= :safe
|
71
71
|
end
|
72
72
|
|
73
|
-
parser.on('--
|
73
|
+
parser.on('-s', '--stdin FILE', 'Pipe source from STDIN, using FILE in ' \
|
74
|
+
'offense when combined with --auto-correct and --stdin.') do |file_path|
|
75
|
+
@options[:stdin] = file_path
|
76
|
+
end
|
77
|
+
|
78
|
+
parser.on('--stderr', 'Write all output to stderr except for the autocorrected source. ' \
|
79
|
+
'This is especially useful when combined with --auto-correct and --stdin') do
|
74
80
|
@options[:stderr] = true
|
75
81
|
end
|
76
82
|
end
|
data/lib/haml_lint/runner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'parallel'
|
4
|
+
require_relative 'source'
|
4
5
|
|
5
6
|
module HamlLint
|
6
7
|
# Responsible for running the applicable linters against the desired files.
|
@@ -20,12 +21,13 @@ module HamlLint
|
|
20
21
|
# @return [HamlLint::Report] a summary of all lints found
|
21
22
|
def run(options = {})
|
22
23
|
@config = load_applicable_config(options)
|
23
|
-
@
|
24
|
+
@sources = extract_applicable_sources(config, options)
|
24
25
|
@linter_selector = HamlLint::LinterSelector.new(config, options)
|
25
26
|
@fail_fast = options.fetch(:fail_fast, false)
|
26
27
|
@cache = {}
|
27
28
|
@autocorrect = options[:autocorrect]
|
28
29
|
@autocorrect_only = options[:autocorrect_only]
|
30
|
+
@autocorrect_stdout = options[:stdin] && options[:stderr]
|
29
31
|
|
30
32
|
report(options)
|
31
33
|
end
|
@@ -48,10 +50,10 @@ module HamlLint
|
|
48
50
|
# @return [true, false]
|
49
51
|
alias fail_fast? fail_fast
|
50
52
|
|
51
|
-
# The list of
|
53
|
+
# The list of sources to lint during this run.
|
52
54
|
#
|
53
|
-
# @return [Array<
|
54
|
-
attr_reader :
|
55
|
+
# @return [Array<HamlLint::Source>]
|
56
|
+
attr_reader :sources
|
55
57
|
|
56
58
|
# The selector for which linters to run during this run.
|
57
59
|
#
|
@@ -79,18 +81,20 @@ module HamlLint
|
|
79
81
|
# Runs all provided linters using the specified config against the given
|
80
82
|
# file.
|
81
83
|
#
|
82
|
-
# @param
|
84
|
+
# @param source [HamlLint::Source] source to lint
|
83
85
|
# @param linter_selector [HamlLint::LinterSelector]
|
84
86
|
# @param config [HamlLint::Configuration]
|
85
|
-
def collect_lints(
|
87
|
+
def collect_lints(source, linter_selector, config)
|
86
88
|
begin
|
87
|
-
document = HamlLint::Document.new
|
89
|
+
document = HamlLint::Document.new source.contents, file: source.path,
|
90
|
+
config: config,
|
91
|
+
write_to_stdout: @autocorrect_stdout
|
88
92
|
rescue HamlLint::Exceptions::ParseError => e
|
89
|
-
return [HamlLint::Lint.new(HamlLint::Linter::Syntax.new(config),
|
93
|
+
return [HamlLint::Lint.new(HamlLint::Linter::Syntax.new(config), source.path,
|
90
94
|
e.line, e.to_s, :error)]
|
91
95
|
end
|
92
96
|
|
93
|
-
linters = linter_selector.linters_for_file(
|
97
|
+
linters = linter_selector.linters_for_file(source.path)
|
94
98
|
lint_arrays = []
|
95
99
|
|
96
100
|
if @autocorrect
|
@@ -125,40 +129,46 @@ module HamlLint
|
|
125
129
|
lint_arrays
|
126
130
|
end
|
127
131
|
|
128
|
-
# Returns the list of
|
132
|
+
# Returns the list of sources that should be linted given the specified
|
129
133
|
# configuration and options.
|
130
134
|
#
|
131
135
|
# @param config [HamlLint::Configuration]
|
132
136
|
# @param options [Hash]
|
133
|
-
# @return [Array<
|
134
|
-
def
|
135
|
-
|
136
|
-
|
137
|
-
|
137
|
+
# @return [Array<HamlLint::Source>]
|
138
|
+
def extract_applicable_sources(config, options)
|
139
|
+
if options[:stdin]
|
140
|
+
[HamlLint::Source.new($stdin, options[:stdin])]
|
141
|
+
else
|
142
|
+
included_patterns = options[:files]
|
143
|
+
excluded_patterns = config['exclude']
|
144
|
+
excluded_patterns += options.fetch(:excluded_files, [])
|
138
145
|
|
139
|
-
|
146
|
+
HamlLint::FileFinder.new(config).find(included_patterns, excluded_patterns).map do |file_path|
|
147
|
+
HamlLint::Source.new File.new(file_path), file_path
|
148
|
+
end
|
149
|
+
end
|
140
150
|
end
|
141
151
|
|
142
|
-
# Process the
|
152
|
+
# Process the sources and add them to the given report.
|
143
153
|
#
|
144
154
|
# @param report [HamlLint::Report]
|
145
155
|
# @return [void]
|
146
|
-
def
|
147
|
-
|
148
|
-
|
156
|
+
def process_sources(report)
|
157
|
+
sources.each do |source|
|
158
|
+
process_source(source, report)
|
149
159
|
break if report.failed? && fail_fast?
|
150
160
|
end
|
151
161
|
end
|
152
162
|
|
153
163
|
# Process a file and add it to the given report.
|
154
164
|
#
|
155
|
-
# @param
|
165
|
+
# @param source [HamlLint::Source] the source to process
|
156
166
|
# @param report [HamlLint::Report]
|
157
167
|
# @return [void]
|
158
|
-
def
|
159
|
-
lints = @cache[
|
168
|
+
def process_source(source, report)
|
169
|
+
lints = @cache[source.path] || collect_lints(source, linter_selector, config)
|
160
170
|
lints.each { |lint| report.add_lint(lint) }
|
161
|
-
report.finish_file(
|
171
|
+
report.finish_file(source.path, lints)
|
162
172
|
end
|
163
173
|
|
164
174
|
# Generates a report based on the given options.
|
@@ -168,9 +178,9 @@ module HamlLint
|
|
168
178
|
# @return [HamlLint::Report]
|
169
179
|
def report(options)
|
170
180
|
report = HamlLint::Report.new(reporter: options[:reporter], fail_level: options[:fail_level])
|
171
|
-
report.start(
|
181
|
+
report.start(sources.map(&:path))
|
172
182
|
warm_cache if options[:parallel]
|
173
|
-
|
183
|
+
process_sources(report)
|
174
184
|
report
|
175
185
|
end
|
176
186
|
|
@@ -178,9 +188,9 @@ module HamlLint
|
|
178
188
|
#
|
179
189
|
# @return [void]
|
180
190
|
def warm_cache
|
181
|
-
results = Parallel.map(
|
182
|
-
lints = collect_lints(
|
183
|
-
[
|
191
|
+
results = Parallel.map(sources) do |source|
|
192
|
+
lints = collect_lints(source, linter_selector, config)
|
193
|
+
[source.path, lints]
|
184
194
|
end
|
185
195
|
@cache = results.to_h
|
186
196
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HamlLint
|
4
|
+
# Wrapper class representing a single target for HamlLint::Runner to run against, comprised of an IO object
|
5
|
+
# containing haml code, as well as a file path.
|
6
|
+
class Source
|
7
|
+
# @return [String] File path associated with the given IO object.
|
8
|
+
attr_reader :path
|
9
|
+
|
10
|
+
# Wraps an IO object and file path to a source object.
|
11
|
+
#
|
12
|
+
# @param [IO] io
|
13
|
+
# @param [String] path
|
14
|
+
def initialize(io, path)
|
15
|
+
@io = io
|
16
|
+
@path = path
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] Contents of the given IO object.
|
20
|
+
def contents
|
21
|
+
@contents ||= @io.read
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
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.54.0
|
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: 2024-01-
|
11
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- lib/haml_lint/ruby_parser.rb
|
177
177
|
- lib/haml_lint/runner.rb
|
178
178
|
- lib/haml_lint/severity.rb
|
179
|
+
- lib/haml_lint/source.rb
|
179
180
|
- lib/haml_lint/spec.rb
|
180
181
|
- lib/haml_lint/spec/matchers/report_lint.rb
|
181
182
|
- lib/haml_lint/spec/normalize_indent.rb
|
@@ -199,7 +200,7 @@ homepage: https://github.com/sds/haml-lint
|
|
199
200
|
licenses:
|
200
201
|
- MIT
|
201
202
|
metadata: {}
|
202
|
-
post_install_message:
|
203
|
+
post_install_message:
|
203
204
|
rdoc_options: []
|
204
205
|
require_paths:
|
205
206
|
- lib
|
@@ -207,15 +208,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
207
208
|
requirements:
|
208
209
|
- - ">="
|
209
210
|
- !ruby/object:Gem::Version
|
210
|
-
version:
|
211
|
+
version: '3.0'
|
211
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
213
|
requirements:
|
213
214
|
- - ">="
|
214
215
|
- !ruby/object:Gem::Version
|
215
216
|
version: '0'
|
216
217
|
requirements: []
|
217
|
-
rubygems_version: 3.
|
218
|
-
signing_key:
|
218
|
+
rubygems_version: 3.4.10
|
219
|
+
signing_key:
|
219
220
|
specification_version: 4
|
220
221
|
summary: HAML lint tool
|
221
222
|
test_files: []
|