haml_lint 0.53.0 → 0.76.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/config/default.yml +17 -5
- data/config/forced_rubocop_config.yml +25 -13
- data/lib/haml_lint/adapter.rb +5 -4
- data/lib/haml_lint/cli.rb +7 -3
- data/lib/haml_lint/constants.rb +1 -1
- data/lib/haml_lint/directive.rb +2 -2
- data/lib/haml_lint/document.rb +14 -5
- data/lib/haml_lint/exceptions.rb +2 -2
- data/lib/haml_lint/extensions/haml_util_unescape_interpolation_tracking.rb +2 -2
- data/lib/haml_lint/haml_visitor.rb +1 -1
- data/lib/haml_lint/lint.rb +8 -3
- data/lib/haml_lint/linter/alignment_tabs.rb +21 -4
- data/lib/haml_lint/linter/class_attribute_with_static_value.rb +52 -12
- data/lib/haml_lint/linter/classes_before_ids.rb +15 -6
- data/lib/haml_lint/linter/consecutive_comments.rb +20 -1
- data/lib/haml_lint/linter/consecutive_silent_scripts.rb +68 -1
- data/lib/haml_lint/linter/empty_object_reference.rb +16 -1
- data/lib/haml_lint/linter/empty_script.rb +32 -2
- data/lib/haml_lint/linter/final_newline.rb +31 -7
- data/lib/haml_lint/linter/html_attributes.rb +71 -2
- data/lib/haml_lint/linter/id_names.rb +1 -1
- data/lib/haml_lint/linter/implicit_div.rb +14 -1
- data/lib/haml_lint/linter/indentation.rb +2 -2
- data/lib/haml_lint/linter/instance_variables.rb +28 -3
- data/lib/haml_lint/linter/leading_comment_space.rb +14 -2
- data/lib/haml_lint/linter/multiline_pipe.rb +3 -3
- data/lib/haml_lint/linter/multiline_script.rb +65 -5
- data/lib/haml_lint/linter/no_placeholders.rb +2 -2
- data/lib/haml_lint/linter/rubocop.rb +87 -76
- data/lib/haml_lint/linter/ruby_comments.rb +14 -4
- data/lib/haml_lint/linter/space_before_script.rb +37 -4
- data/lib/haml_lint/linter/space_inside_hash_attributes.rb +41 -3
- data/lib/haml_lint/linter/strict_locals.rb +69 -0
- data/lib/haml_lint/linter/tag_name.rb +15 -2
- data/lib/haml_lint/linter/trailing_empty_lines.rb +13 -1
- data/lib/haml_lint/linter/trailing_whitespace.rb +16 -3
- data/lib/haml_lint/linter/unescaped_html.rb +27 -0
- data/lib/haml_lint/linter/unnecessary_interpolation.rb +30 -3
- data/lib/haml_lint/linter/unnecessary_string_output.rb +108 -12
- data/lib/haml_lint/linter.rb +119 -5
- data/lib/haml_lint/node_transformer.rb +2 -2
- data/lib/haml_lint/options.rb +17 -3
- data/lib/haml_lint/rake_task.rb +3 -2
- data/lib/haml_lint/reporter/default_reporter.rb +1 -1
- data/lib/haml_lint/reporter/disabled_config_reporter.rb +29 -8
- data/lib/haml_lint/reporter/github_reporter.rb +50 -0
- data/lib/haml_lint/reporter/hash_reporter.rb +2 -0
- data/lib/haml_lint/reporter/json_reporter.rb +1 -1
- data/lib/haml_lint/reporter/progress_reporter.rb +2 -1
- data/lib/haml_lint/reporter/utils.rb +4 -2
- data/lib/haml_lint/reporter.rb +1 -1
- data/lib/haml_lint/ruby_extraction/base_chunk.rb +4 -4
- data/lib/haml_lint/ruby_extraction/chunk_extractor.rb +73 -32
- data/lib/haml_lint/ruby_extraction/coordinator.rb +9 -4
- data/lib/haml_lint/ruby_extraction/implicit_end_chunk.rb +1 -1
- data/lib/haml_lint/ruby_extraction/non_ruby_filter_chunk.rb +2 -2
- data/lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb +1 -1
- data/lib/haml_lint/ruby_extraction/ruby_filter_chunk.rb +1 -1
- data/lib/haml_lint/ruby_extraction/script_chunk.rb +2 -2
- data/lib/haml_lint/runner.rb +70 -30
- data/lib/haml_lint/source.rb +25 -0
- data/lib/haml_lint/spec/matchers/report_lint.rb +17 -6
- data/lib/haml_lint/spec/shared_rubocop_autocorrect_context.rb +34 -4
- data/lib/haml_lint/spec.rb +4 -4
- data/lib/haml_lint/tree/comment_node.rb +1 -1
- data/lib/haml_lint/tree/doctype_node.rb +1 -1
- data/lib/haml_lint/tree/filter_node.rb +14 -1
- data/lib/haml_lint/tree/haml_comment_node.rb +9 -2
- data/lib/haml_lint/tree/node.rb +4 -4
- data/lib/haml_lint/tree/root_node.rb +4 -4
- data/lib/haml_lint/tree/script_node.rb +1 -1
- data/lib/haml_lint/tree/silent_script_node.rb +1 -1
- data/lib/haml_lint/tree/tag_node.rb +69 -25
- data/lib/haml_lint/utils.rb +4 -31
- data/lib/haml_lint/version.rb +1 -1
- data/lib/haml_lint.rb +23 -23
- metadata +14 -10
|
@@ -74,7 +74,7 @@ module HamlLint
|
|
|
74
74
|
current_matching_line = 1
|
|
75
75
|
@source_map = {}
|
|
76
76
|
lines.each.with_index do |line, i|
|
|
77
|
-
next unless
|
|
77
|
+
next unless /\S/.match?(line)
|
|
78
78
|
mo = line.match(/^(.*?)\$?\s*\$\$(\d+)$/)
|
|
79
79
|
if mo
|
|
80
80
|
lines[i] = mo[1]
|
|
@@ -115,7 +115,7 @@ module HamlLint
|
|
|
115
115
|
|
|
116
116
|
syntax_lints = subject.lints.select { |lint| lint.message =~ %r{Lint/Syntax} }
|
|
117
117
|
|
|
118
|
-
if start_ruby.strip != 'SKIP' && subject.last_extracted_source
|
|
118
|
+
if start_ruby.strip != 'SKIP' && subject.last_extracted_source && ENV['UPDATE_EXAMPLES'] != '1'
|
|
119
119
|
matcher = eq(start_ruby)
|
|
120
120
|
subject.last_extracted_source.source.should(
|
|
121
121
|
matcher,
|
|
@@ -125,7 +125,7 @@ module HamlLint
|
|
|
125
125
|
|
|
126
126
|
syntax_lints.should(be_empty, "Generated Ruby has Syntax Lints:\n#{format_lints(syntax_lints)}")
|
|
127
127
|
|
|
128
|
-
if end_ruby.strip != 'SKIP' && subject.last_new_ruby_source
|
|
128
|
+
if end_ruby.strip != 'SKIP' && subject.last_new_ruby_source && ENV['UPDATE_EXAMPLES'] != '1'
|
|
129
129
|
matcher = eq(end_ruby)
|
|
130
130
|
subject.last_new_ruby_source.should(
|
|
131
131
|
matcher,
|
|
@@ -141,10 +141,40 @@ module HamlLint
|
|
|
141
141
|
-> { "Final HAML is different from expected. #{matcher.failure_message}\n#{format_lints}" }
|
|
142
142
|
)
|
|
143
143
|
|
|
144
|
-
if subject.last_extracted_source && start_ruby.strip != 'SKIP'
|
|
144
|
+
if subject.last_extracted_source && start_ruby.strip != 'SKIP' && ENV['UPDATE_EXAMPLES'] != '1'
|
|
145
145
|
subject.last_extracted_source.source_map.should == source_map
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
+
if ENV['UPDATE_EXAMPLES'] == '1' && respond_to?(:example_first_line_no) &&
|
|
149
|
+
start_ruby.strip != 'SKIP' && end_ruby.strip != 'SKIP'
|
|
150
|
+
original_content = File.read(example_path)
|
|
151
|
+
old_steps_string = '---' + steps_string.partition('---').last.rpartition('---').first + '---'
|
|
152
|
+
|
|
153
|
+
if old_steps_string.scan(/\$\$\d+/).tally.values.any? { |v| v > 1 }
|
|
154
|
+
# If the $$3 was there twice, let's not update the example
|
|
155
|
+
return
|
|
156
|
+
end
|
|
157
|
+
original_content.scan(old_steps_string).count
|
|
158
|
+
|
|
159
|
+
new_generated_ruby_lines = subject.last_extracted_source.source.split("\n", -1)
|
|
160
|
+
last_seen_haml_line_no = 1
|
|
161
|
+
subject.last_extracted_source.source_map.each do |ruby_line_no, haml_line_no|
|
|
162
|
+
if haml_line_no != last_seen_haml_line_no
|
|
163
|
+
last_seen_haml_line_no = haml_line_no
|
|
164
|
+
new_generated_ruby_lines[ruby_line_no - 1] += " $$#{haml_line_no}"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
new_steps_string = <<~NEW.chop # Chop to remove the added newlines
|
|
169
|
+
---
|
|
170
|
+
#{new_generated_ruby_lines.join("\n")}---
|
|
171
|
+
#{subject.last_new_ruby_source}---
|
|
172
|
+
NEW
|
|
173
|
+
|
|
174
|
+
new_content = original_content.gsub(old_steps_string, new_steps_string)
|
|
175
|
+
File.write(example_path, new_content)
|
|
176
|
+
end
|
|
177
|
+
|
|
148
178
|
haml_different = start_haml != end_haml
|
|
149
179
|
document.source_was_changed.should == haml_different
|
|
150
180
|
end
|
data/lib/haml_lint/spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
require_relative 'spec/normalize_indent'
|
|
4
|
+
require_relative 'spec/shared_linter_context'
|
|
5
|
+
require_relative 'spec/shared_rubocop_autocorrect_context'
|
|
6
|
+
require_relative 'spec/matchers/report_lint'
|
|
@@ -9,7 +9,7 @@ module HamlLint::Tree
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def text
|
|
12
|
-
# Seems
|
|
12
|
+
# Seems Haml strips the starting blank lines... without them, line numbers become offset,
|
|
13
13
|
# breaking the source_map and auto-correct
|
|
14
14
|
|
|
15
15
|
nb_blank_lines = 0
|
|
@@ -17,5 +17,18 @@ module HamlLint::Tree
|
|
|
17
17
|
|
|
18
18
|
"#{"\n" * nb_blank_lines}#{super}"
|
|
19
19
|
end
|
|
20
|
+
|
|
21
|
+
# The line numbers that are contained within the node.
|
|
22
|
+
#
|
|
23
|
+
# Unlike most nodes, a filter's content begins on the line *after* the
|
|
24
|
+
# `:filtername` declaration, so the span runs from the declaration line
|
|
25
|
+
# through all of the indented content lines.
|
|
26
|
+
#
|
|
27
|
+
# @return [Range]
|
|
28
|
+
def line_numbers
|
|
29
|
+
return super if lines.empty?
|
|
30
|
+
|
|
31
|
+
(line..(line + lines.count))
|
|
32
|
+
end
|
|
20
33
|
end
|
|
21
34
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../directive'
|
|
4
4
|
|
|
5
5
|
module HamlLint::Tree
|
|
6
|
-
# Represents a
|
|
6
|
+
# Represents a Haml comment node.
|
|
7
7
|
class HamlCommentNode < Node
|
|
8
8
|
def directives
|
|
9
9
|
directives = super
|
|
@@ -25,6 +25,13 @@ module HamlLint::Tree
|
|
|
25
25
|
.rstrip
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# Returns whether this comment contains a `locals` directive.
|
|
29
|
+
#
|
|
30
|
+
# @return [Boolean]
|
|
31
|
+
def is_strict_locals? # rubocop:disable Naming
|
|
32
|
+
text.lstrip.start_with?('locals:')
|
|
33
|
+
end
|
|
34
|
+
|
|
28
35
|
private
|
|
29
36
|
|
|
30
37
|
def contained_directives
|
data/lib/haml_lint/tree/node.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative '../comment_configuration'
|
|
4
4
|
|
|
5
5
|
module HamlLint::Tree
|
|
6
|
-
# Decorator class that provides a convenient set of helpers for
|
|
6
|
+
# Decorator class that provides a convenient set of helpers for Haml's
|
|
7
7
|
# {Haml::Parser::ParseNode} struct.
|
|
8
8
|
#
|
|
9
9
|
# The goal is to abstract away the details of the underlying struct and
|
|
10
10
|
# provide a cleaner and more uniform interface for getting information about a
|
|
11
11
|
# node, as there are a number of weird/special cases in the struct returned by
|
|
12
|
-
# the
|
|
12
|
+
# the Haml parser.
|
|
13
13
|
#
|
|
14
14
|
# @abstract
|
|
15
15
|
class Node
|
|
@@ -21,7 +21,7 @@ module HamlLint::Tree
|
|
|
21
21
|
# Creates a node wrapping the given {Haml::Parser::ParseNode} struct.
|
|
22
22
|
#
|
|
23
23
|
# @param document [HamlLint::Document] Haml document that created this node
|
|
24
|
-
# @param parse_node [Haml::Parser::ParseNode] parse node created by
|
|
24
|
+
# @param parse_node [Haml::Parser::ParseNode] parse node created by Haml's parser
|
|
25
25
|
def initialize(document, parse_node)
|
|
26
26
|
@line = parse_node.line
|
|
27
27
|
@document = document
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative 'null_node'
|
|
4
4
|
|
|
5
5
|
module HamlLint::Tree
|
|
6
|
-
# Represents the root node of a
|
|
6
|
+
# Represents the root node of a Haml document that contains all other nodes.
|
|
7
7
|
class RootNode < Node
|
|
8
|
-
# The name
|
|
8
|
+
# The name of the file parsed to build this tree.
|
|
9
9
|
#
|
|
10
10
|
# @return [String] a file name
|
|
11
11
|
def file
|
|
@@ -21,7 +21,7 @@ module HamlLint::Tree
|
|
|
21
21
|
return node if node.line_numbers.cover?(line) && node != self
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
# Because
|
|
24
|
+
# Because Haml doesn't leave any trace in the nodes when it merges lines that
|
|
25
25
|
# end with a comma, it's harder to assign a node to the second line here:
|
|
26
26
|
# = some_call user,
|
|
27
27
|
# foo, bar
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HamlLint::Tree
|
|
4
|
-
# Represents a
|
|
4
|
+
# Represents a Haml silent script node (`- some_expression`) which executes
|
|
5
5
|
# code without producing output.
|
|
6
6
|
class SilentScriptNode < Node
|
|
7
7
|
# The Ruby script contents parsed into a syntax tree.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HamlLint::Tree
|
|
4
|
-
# Represents a tag node in a
|
|
4
|
+
# Represents a tag node in a Haml document.
|
|
5
5
|
class TagNode < Node
|
|
6
6
|
# Computed set of attribute hashes code.
|
|
7
7
|
#
|
|
@@ -33,10 +33,20 @@ module HamlLint::Tree
|
|
|
33
33
|
@value[:parse] && !@value[:value].strip.empty?
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# Whether this tag outputs unescaped HTML via a `!` marker, e.g. `%tag!=` or
|
|
37
|
+
# `%tag!~`.
|
|
38
|
+
#
|
|
39
|
+
# @return [true,false]
|
|
40
|
+
def unescape_html?
|
|
41
|
+
return false unless contains_script?
|
|
42
|
+
|
|
43
|
+
/\A\s*[<>]*\s*!/.match?(inline_marker_source)
|
|
44
|
+
end
|
|
45
|
+
|
|
36
46
|
# Returns whether this tag has a specified attribute.
|
|
37
47
|
#
|
|
38
48
|
# @return [true,false]
|
|
39
|
-
def has_hash_attribute?(attribute)
|
|
49
|
+
def has_hash_attribute?(attribute) # rubocop:disable Naming
|
|
40
50
|
hash_attributes? && existing_attributes.include?(attribute)
|
|
41
51
|
end
|
|
42
52
|
|
|
@@ -94,30 +104,18 @@ module HamlLint::Tree
|
|
|
94
104
|
#
|
|
95
105
|
# @return [Hash]
|
|
96
106
|
def attributes_source
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
_explicit_tag, static_attrs, rest =
|
|
100
|
-
source_code.scan(/\A\s*(%[-:\w]+)?([-:\w.\#]*)(.*)/m)[0]
|
|
101
|
-
|
|
102
|
-
attr_types = {
|
|
103
|
-
'{' => [:hash, %w[{ }]],
|
|
104
|
-
'(' => [:html, %w[( )]],
|
|
105
|
-
'[' => [:object_ref, %w[[ ]]],
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
attr_source = { static: static_attrs }
|
|
109
|
-
while rest
|
|
110
|
-
type, chars = attr_types[rest[0]]
|
|
111
|
-
break unless type # Not an attribute opening character, so we're done
|
|
112
|
-
|
|
113
|
-
# Can't define multiple of the same attribute type (e.g. two {...})
|
|
114
|
-
break if attr_source[type]
|
|
115
|
-
|
|
116
|
-
attr_source[type], rest = Haml::Util.balance(rest, *chars)
|
|
117
|
-
end
|
|
107
|
+
parsed_attributes_source[:attributes]
|
|
108
|
+
end
|
|
118
109
|
|
|
119
|
-
|
|
120
|
-
|
|
110
|
+
# Source that follows the tag name and attributes. It begins with the
|
|
111
|
+
# content marker (e.g. `=`, `!=`, `~`, `!~`, or plain text).
|
|
112
|
+
#
|
|
113
|
+
# @example For `%tag.class!= foo`, this returns:
|
|
114
|
+
# '!= foo'
|
|
115
|
+
#
|
|
116
|
+
# @return [String]
|
|
117
|
+
def inline_marker_source
|
|
118
|
+
parsed_attributes_source[:marker]
|
|
121
119
|
end
|
|
122
120
|
|
|
123
121
|
# Whether this tag node has a set of hash attributes defined via the
|
|
@@ -157,6 +155,18 @@ module HamlLint::Tree
|
|
|
157
155
|
dynamic_attributes_source[:html][/\A\((.*)\)\z/, 1] if html_attributes?
|
|
158
156
|
end
|
|
159
157
|
|
|
158
|
+
# The tag's static (non-Ruby) attributes parsed into a Ruby hash. Keys are
|
|
159
|
+
# strings and values are their literal parsed values (e.g. `true` for a
|
|
160
|
+
# boolean attribute such as `(required)`).
|
|
161
|
+
#
|
|
162
|
+
# @note When the tag uses the `.class`/`#id` shorthand, the resulting
|
|
163
|
+
# `class`/`id` entries are merged into this hash as well.
|
|
164
|
+
#
|
|
165
|
+
# @return [Hash]
|
|
166
|
+
def static_attributes
|
|
167
|
+
@value[:attributes]
|
|
168
|
+
end
|
|
169
|
+
|
|
160
170
|
# ID of the HTML tag.
|
|
161
171
|
#
|
|
162
172
|
# @return [String]
|
|
@@ -229,6 +239,40 @@ module HamlLint::Tree
|
|
|
229
239
|
|
|
230
240
|
private
|
|
231
241
|
|
|
242
|
+
# Parses the source code following the tag name once into its attribute
|
|
243
|
+
# sources and the remaining inline content marker.
|
|
244
|
+
#
|
|
245
|
+
# @return [Hash{Symbol => Object}] `:attributes` source hash (keyed by
|
|
246
|
+
# `:static`/`:hash`/`:html`/`:object_ref`) and the `:marker` string
|
|
247
|
+
def parsed_attributes_source
|
|
248
|
+
@parsed_attributes_source ||=
|
|
249
|
+
begin
|
|
250
|
+
_explicit_tag, static_attrs, rest =
|
|
251
|
+
source_code.scan(/\A\s*(%[-:\w]+)?([-:\w.\#]*)(.*)/m)[0]
|
|
252
|
+
|
|
253
|
+
attr_types = {
|
|
254
|
+
'{' => [:hash, %w[{ }]],
|
|
255
|
+
'(' => [:html, %w[( )]],
|
|
256
|
+
'[' => [:object_ref, %w[[ ]]],
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
attr_source = { static: static_attrs }
|
|
260
|
+
while rest
|
|
261
|
+
type, chars = attr_types[rest[0]]
|
|
262
|
+
break unless type # Not an attribute opening character, so we're done
|
|
263
|
+
|
|
264
|
+
# Can't define multiple of the same attribute type (e.g. two {...})
|
|
265
|
+
break if attr_source[type]
|
|
266
|
+
|
|
267
|
+
attr_source[type], rest = Haml::Util.balance(rest, *chars)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Whatever remains after the tag name and attributes begins with the
|
|
271
|
+
# content marker (e.g. `=`, `!=`, `~`, `!~`, or plain text).
|
|
272
|
+
{ attributes: attr_source, marker: rest.to_s }
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
232
276
|
def existing_attributes
|
|
233
277
|
parsed_attrs = parsed_attributes
|
|
234
278
|
return {} unless parsed_attrs.respond_to?(:children)
|
data/lib/haml_lint/utils.rb
CHANGED
|
@@ -116,7 +116,7 @@ module HamlLint
|
|
|
116
116
|
|
|
117
117
|
# Returns indexes of all occurrences of a substring within a string.
|
|
118
118
|
#
|
|
119
|
-
# Note, this will not return
|
|
119
|
+
# Note, this will not return overlapping substrings, so searching for "aa"
|
|
120
120
|
# in "aaa" will only find one substring, not two.
|
|
121
121
|
#
|
|
122
122
|
# @param text [String] the text to search
|
|
@@ -233,7 +233,7 @@ module HamlLint
|
|
|
233
233
|
|
|
234
234
|
# Returns true if line is only whitespace.
|
|
235
235
|
# Note, this is not like blank? is rails. For nil, this returns false.
|
|
236
|
-
def is_blank_line?(line)
|
|
236
|
+
def is_blank_line?(line) # rubocop:disable Naming
|
|
237
237
|
line && line.index(/\S/).nil?
|
|
238
238
|
end
|
|
239
239
|
|
|
@@ -249,36 +249,9 @@ module HamlLint
|
|
|
249
249
|
$!
|
|
250
250
|
end
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
# push a string in stdin, and capture both stdout and stderr which are returned.
|
|
254
|
-
#
|
|
255
|
-
# @param stdin_str [String] the string to push in as stdin
|
|
256
|
-
# @param _block [Block] the block to perform with the overridden std streams
|
|
257
|
-
# @return [String, String]
|
|
258
|
-
def with_captured_streams(stdin_str, &_block)
|
|
259
|
-
original_stdin = $stdin
|
|
260
|
-
# The dup is needed so that stdin_data isn't altered (encoding-wise at least)
|
|
261
|
-
$stdin = StringIO.new(stdin_str.dup)
|
|
262
|
-
begin
|
|
263
|
-
original_stdout = $stdout
|
|
264
|
-
$stdout = StringIO.new
|
|
265
|
-
begin
|
|
266
|
-
original_stderr = $stderr
|
|
267
|
-
$stderr = StringIO.new
|
|
268
|
-
yield
|
|
269
|
-
[$stdout.string, $stderr.string]
|
|
270
|
-
ensure
|
|
271
|
-
$stderr = original_stderr
|
|
272
|
-
end
|
|
273
|
-
ensure
|
|
274
|
-
$stdout = original_stdout
|
|
275
|
-
end
|
|
276
|
-
ensure
|
|
277
|
-
$stdin = original_stdin
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
def regexp_for_parts(parts, join_regexp)
|
|
252
|
+
def regexp_for_parts(parts, join_regexp, prefix: nil, suffix: nil)
|
|
281
253
|
regexp_code = parts.map { |c| Regexp.quote(c) }.join(join_regexp)
|
|
254
|
+
regexp_code = "#{prefix}#{regexp_code}#{suffix}"
|
|
282
255
|
Regexp.new(regexp_code)
|
|
283
256
|
end
|
|
284
257
|
end
|
data/lib/haml_lint/version.rb
CHANGED
data/lib/haml_lint.rb
CHANGED
|
@@ -3,26 +3,26 @@
|
|
|
3
3
|
# Need to load haml before we can reference some Haml modules in our code
|
|
4
4
|
require 'haml'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
require_relative 'haml_lint/constants'
|
|
7
|
+
require_relative 'haml_lint/exceptions'
|
|
8
|
+
require_relative 'haml_lint/configuration'
|
|
9
|
+
require_relative 'haml_lint/configuration_loader'
|
|
10
|
+
require_relative 'haml_lint/document'
|
|
11
|
+
require_relative 'haml_lint/haml_visitor'
|
|
12
|
+
require_relative 'haml_lint/lint'
|
|
13
|
+
require_relative 'haml_lint/linter_registry'
|
|
14
|
+
require_relative 'haml_lint/ruby_parser'
|
|
15
|
+
require_relative 'haml_lint/linter'
|
|
16
|
+
require_relative 'haml_lint/logger'
|
|
17
|
+
require_relative 'haml_lint/reporter'
|
|
18
|
+
require_relative 'haml_lint/report'
|
|
19
|
+
require_relative 'haml_lint/linter_selector'
|
|
20
|
+
require_relative 'haml_lint/file_finder'
|
|
21
|
+
require_relative 'haml_lint/runner'
|
|
22
|
+
require_relative 'haml_lint/utils'
|
|
23
|
+
require_relative 'haml_lint/version'
|
|
24
|
+
require_relative 'haml_lint/version_comparer'
|
|
25
|
+
require_relative 'haml_lint/severity'
|
|
26
26
|
|
|
27
27
|
# Lead all extensions to external source code
|
|
28
28
|
Dir[File.expand_path('haml_lint/extensions/*.rb', File.dirname(__FILE__))].sort.each do |file|
|
|
@@ -30,8 +30,8 @@ Dir[File.expand_path('haml_lint/extensions/*.rb', File.dirname(__FILE__))].sort.
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
# Load all parse tree node classes
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
require_relative 'haml_lint/tree/node'
|
|
34
|
+
require_relative 'haml_lint/node_transformer'
|
|
35
35
|
Dir[File.expand_path('haml_lint/tree/*.rb', File.dirname(__FILE__))].sort.each do |file|
|
|
36
36
|
require file
|
|
37
37
|
end
|
|
@@ -47,7 +47,7 @@ Dir[File.expand_path('haml_lint/reporter/*.rb', File.dirname(__FILE__))].sort.ea
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# Load all the chunks for RubyExtraction
|
|
50
|
-
|
|
50
|
+
require_relative 'haml_lint/ruby_extraction/base_chunk'
|
|
51
51
|
Dir[File.expand_path('haml_lint/ruby_extraction/*.rb', File.dirname(__FILE__))].sort.each do |file|
|
|
52
52
|
require file
|
|
53
53
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: haml_lint
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.76.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shane da Silva
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: haml
|
|
@@ -28,14 +27,14 @@ dependencies:
|
|
|
28
27
|
name: parallel
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - ">="
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
32
|
version: '1.10'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '1.10'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
@@ -134,10 +133,12 @@ files:
|
|
|
134
133
|
- lib/haml_lint/linter/ruby_comments.rb
|
|
135
134
|
- lib/haml_lint/linter/space_before_script.rb
|
|
136
135
|
- lib/haml_lint/linter/space_inside_hash_attributes.rb
|
|
136
|
+
- lib/haml_lint/linter/strict_locals.rb
|
|
137
137
|
- lib/haml_lint/linter/syntax.rb
|
|
138
138
|
- lib/haml_lint/linter/tag_name.rb
|
|
139
139
|
- lib/haml_lint/linter/trailing_empty_lines.rb
|
|
140
140
|
- lib/haml_lint/linter/trailing_whitespace.rb
|
|
141
|
+
- lib/haml_lint/linter/unescaped_html.rb
|
|
141
142
|
- lib/haml_lint/linter/unnecessary_interpolation.rb
|
|
142
143
|
- lib/haml_lint/linter/unnecessary_string_output.rb
|
|
143
144
|
- lib/haml_lint/linter/view_length.rb
|
|
@@ -153,6 +154,7 @@ files:
|
|
|
153
154
|
- lib/haml_lint/reporter/checkstyle_reporter.rb
|
|
154
155
|
- lib/haml_lint/reporter/default_reporter.rb
|
|
155
156
|
- lib/haml_lint/reporter/disabled_config_reporter.rb
|
|
157
|
+
- lib/haml_lint/reporter/github_reporter.rb
|
|
156
158
|
- lib/haml_lint/reporter/hash_reporter.rb
|
|
157
159
|
- lib/haml_lint/reporter/hooks.rb
|
|
158
160
|
- lib/haml_lint/reporter/json_reporter.rb
|
|
@@ -176,6 +178,7 @@ files:
|
|
|
176
178
|
- lib/haml_lint/ruby_parser.rb
|
|
177
179
|
- lib/haml_lint/runner.rb
|
|
178
180
|
- lib/haml_lint/severity.rb
|
|
181
|
+
- lib/haml_lint/source.rb
|
|
179
182
|
- lib/haml_lint/spec.rb
|
|
180
183
|
- lib/haml_lint/spec/matchers/report_lint.rb
|
|
181
184
|
- lib/haml_lint/spec/normalize_indent.rb
|
|
@@ -198,8 +201,10 @@ files:
|
|
|
198
201
|
homepage: https://github.com/sds/haml-lint
|
|
199
202
|
licenses:
|
|
200
203
|
- MIT
|
|
201
|
-
metadata:
|
|
202
|
-
|
|
204
|
+
metadata:
|
|
205
|
+
bug_tracker_uri: https://github.com/sds/haml-lint/issues
|
|
206
|
+
changelog_uri: https://github.com/sds/haml-lint/blob/main/CHANGELOG.md
|
|
207
|
+
source_code_uri: https://github.com/sds/haml-lint
|
|
203
208
|
rdoc_options: []
|
|
204
209
|
require_paths:
|
|
205
210
|
- lib
|
|
@@ -207,15 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
207
212
|
requirements:
|
|
208
213
|
- - ">="
|
|
209
214
|
- !ruby/object:Gem::Version
|
|
210
|
-
version:
|
|
215
|
+
version: '3.0'
|
|
211
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
217
|
requirements:
|
|
213
218
|
- - ">="
|
|
214
219
|
- !ruby/object:Gem::Version
|
|
215
220
|
version: '0'
|
|
216
221
|
requirements: []
|
|
217
|
-
rubygems_version:
|
|
218
|
-
signing_key:
|
|
222
|
+
rubygems_version: 4.0.10
|
|
219
223
|
specification_version: 4
|
|
220
224
|
summary: HAML lint tool
|
|
221
225
|
test_files: []
|