haml_lint 0.73.0 → 0.75.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +10 -5
  3. data/config/forced_rubocop_config.yml +13 -13
  4. data/lib/haml_lint/cli.rb +5 -1
  5. data/lib/haml_lint/document.rb +3 -8
  6. data/lib/haml_lint/exceptions.rb +2 -2
  7. data/lib/haml_lint/extensions/haml_util_unescape_interpolation_tracking.rb +2 -2
  8. data/lib/haml_lint/haml_visitor.rb +1 -1
  9. data/lib/haml_lint/lint.rb +1 -1
  10. data/lib/haml_lint/linter/class_attribute_with_static_value.rb +51 -11
  11. data/lib/haml_lint/linter/classes_before_ids.rb +16 -1
  12. data/lib/haml_lint/linter/consecutive_comments.rb +20 -1
  13. data/lib/haml_lint/linter/empty_object_reference.rb +16 -1
  14. data/lib/haml_lint/linter/empty_script.rb +31 -1
  15. data/lib/haml_lint/linter/final_newline.rb +31 -7
  16. data/lib/haml_lint/linter/implicit_div.rb +14 -1
  17. data/lib/haml_lint/linter/leading_comment_space.rb +13 -1
  18. data/lib/haml_lint/linter/multiline_script.rb +65 -5
  19. data/lib/haml_lint/linter/rubocop.rb +10 -22
  20. data/lib/haml_lint/linter/ruby_comments.rb +14 -4
  21. data/lib/haml_lint/linter/space_before_script.rb +37 -4
  22. data/lib/haml_lint/linter/space_inside_hash_attributes.rb +41 -3
  23. data/lib/haml_lint/linter/tag_name.rb +14 -1
  24. data/lib/haml_lint/linter/trailing_empty_lines.rb +13 -1
  25. data/lib/haml_lint/linter/trailing_whitespace.rb +15 -2
  26. data/lib/haml_lint/linter/unescaped_html.rb +27 -0
  27. data/lib/haml_lint/linter/unnecessary_interpolation.rb +30 -3
  28. data/lib/haml_lint/linter/unnecessary_string_output.rb +35 -3
  29. data/lib/haml_lint/linter.rb +112 -1
  30. data/lib/haml_lint/node_transformer.rb +2 -2
  31. data/lib/haml_lint/reporter/disabled_config_reporter.rb +26 -5
  32. data/lib/haml_lint/reporter/github_reporter.rb +26 -8
  33. data/lib/haml_lint/ruby_extraction/base_chunk.rb +3 -3
  34. data/lib/haml_lint/ruby_extraction/chunk_extractor.rb +37 -13
  35. data/lib/haml_lint/ruby_extraction/coordinator.rb +2 -2
  36. data/lib/haml_lint/ruby_extraction/implicit_end_chunk.rb +1 -1
  37. data/lib/haml_lint/ruby_extraction/non_ruby_filter_chunk.rb +1 -1
  38. data/lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb +1 -1
  39. data/lib/haml_lint/ruby_extraction/script_chunk.rb +1 -1
  40. data/lib/haml_lint/runner.rb +31 -3
  41. data/lib/haml_lint/source.rb +2 -6
  42. data/lib/haml_lint/spec/matchers/report_lint.rb +2 -2
  43. data/lib/haml_lint/tree/comment_node.rb +1 -1
  44. data/lib/haml_lint/tree/doctype_node.rb +1 -1
  45. data/lib/haml_lint/tree/filter_node.rb +14 -1
  46. data/lib/haml_lint/tree/haml_comment_node.rb +2 -2
  47. data/lib/haml_lint/tree/node.rb +3 -3
  48. data/lib/haml_lint/tree/root_node.rb +2 -2
  49. data/lib/haml_lint/tree/silent_script_node.rb +1 -1
  50. data/lib/haml_lint/tree/tag_node.rb +57 -25
  51. data/lib/haml_lint/utils.rb +1 -1
  52. data/lib/haml_lint/version.rb +1 -1
  53. metadata +3 -2
@@ -3,13 +3,13 @@
3
3
  require_relative '../comment_configuration'
4
4
 
5
5
  module HamlLint::Tree
6
- # Decorator class that provides a convenient set of helpers for HAML's
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 HAML parser.
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 HAML's parser
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
@@ -3,7 +3,7 @@
3
3
  require_relative 'null_node'
4
4
 
5
5
  module HamlLint::Tree
6
- # Represents the root node of a HAML document that contains all other nodes.
6
+ # Represents the root node of a Haml document that contains all other nodes.
7
7
  class RootNode < Node
8
8
  # The name of the file parsed to build this tree.
9
9
  #
@@ -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 HAML doesn't leave any trace in the nodes when it merges lines that
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 HAML silent script node (`- some_expression`) which executes
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 HAML document.
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
- @attributes_source ||=
98
- begin
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
- attr_source
120
- end
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
@@ -229,6 +227,40 @@ module HamlLint::Tree
229
227
 
230
228
  private
231
229
 
230
+ # Parses the source code following the tag name once into its attribute
231
+ # sources and the remaining inline content marker.
232
+ #
233
+ # @return [Hash{Symbol => Object}] `:attributes` source hash (keyed by
234
+ # `:static`/`:hash`/`:html`/`:object_ref`) and the `:marker` string
235
+ def parsed_attributes_source
236
+ @parsed_attributes_source ||=
237
+ begin
238
+ _explicit_tag, static_attrs, rest =
239
+ source_code.scan(/\A\s*(%[-:\w]+)?([-:\w.\#]*)(.*)/m)[0]
240
+
241
+ attr_types = {
242
+ '{' => [:hash, %w[{ }]],
243
+ '(' => [:html, %w[( )]],
244
+ '[' => [:object_ref, %w[[ ]]],
245
+ }
246
+
247
+ attr_source = { static: static_attrs }
248
+ while rest
249
+ type, chars = attr_types[rest[0]]
250
+ break unless type # Not an attribute opening character, so we're done
251
+
252
+ # Can't define multiple of the same attribute type (e.g. two {...})
253
+ break if attr_source[type]
254
+
255
+ attr_source[type], rest = Haml::Util.balance(rest, *chars)
256
+ end
257
+
258
+ # Whatever remains after the tag name and attributes begins with the
259
+ # content marker (e.g. `=`, `!=`, `~`, `!~`, or plain text).
260
+ { attributes: attr_source, marker: rest.to_s }
261
+ end
262
+ end
263
+
232
264
  def existing_attributes
233
265
  parsed_attrs = parsed_attributes
234
266
  return {} unless parsed_attrs.respond_to?(:children)
@@ -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
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.73.0'
5
+ VERSION = '0.75.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.73.0
4
+ version: 0.75.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
@@ -138,6 +138,7 @@ files:
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
@@ -218,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
219
  - !ruby/object:Gem::Version
219
220
  version: '0'
220
221
  requirements: []
221
- rubygems_version: 3.6.9
222
+ rubygems_version: 4.0.10
222
223
  specification_version: 4
223
224
  summary: HAML lint tool
224
225
  test_files: []