haml_lint 0.60.0 → 0.61.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bf4b2b435129bea13f5c1b32aabf202f5e8731264df179e3e7a9c16017b8654
4
- data.tar.gz: 34a95aa1ac68c54a513d9431be449f5a53963d77e7d451cfa532c60ff08fe08f
3
+ metadata.gz: 61b19bf998b26f91fc8ea0578a3e189b8edb1d3c31a942c873e1e895747bcd82
4
+ data.tar.gz: 66b19273123ec6618faade749c390ded3e5ccdb608e2f64b43a4def9f575a298
5
5
  SHA512:
6
- metadata.gz: a65d869de4f21555cc165baccae390ae09202de3d6aea707404806d0ee40bdd1d5916d7ab3ae9a7b4a0d35c1a4a5a8c89da3cb317389877460e03f48b5577c54
7
- data.tar.gz: 84ccd1349eb889e3b516f42e4919eb0003566f01ba62a01b05cce28aeb801138c6f725eac054c23073997f0e67e452765ac78c03bfe710639c9742828b85521d
6
+ metadata.gz: c279dc5f30fa736cfac959aedfd8dec1bf7e5e25b1a0508989ce1276afa5d8b4ddd802f9a139ab48b773a1a0e4d9f9bd91e599cf63700e3eea383cbfa7407bc4
7
+ data.tar.gz: 88a18703c06bcc0b95e0072d3ca0e3970302d7807bba29bcb05d2ad8f43dcbf184d76015dc13924d41e7acfcd36762cd6c0eefe3e46d58eae4d26dd8ef2cae2a
data/config/default.yml CHANGED
@@ -102,6 +102,13 @@ linters:
102
102
  enabled: true
103
103
  style: space
104
104
 
105
+ StrictLocals:
106
+ enabled: false
107
+ file_types: partials
108
+ matchers:
109
+ all: .*
110
+ partials: \A_.*\.haml\z
111
+
105
112
  TagName:
106
113
  enabled: true
107
114
 
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HamlLint
4
+ # Checks for the presence of a `locals` magic comment at the beginning of a partial.
5
+ class Linter::StrictLocals < Linter
6
+ include LinterRegistry
7
+
8
+ DummyNode = Struct.new(:line)
9
+
10
+ # Enables the linter if the tree is for the right file type.
11
+ #
12
+ # @param [HamlLint::Tree::RootNode] the root of a syntax tree
13
+ # @return [true, false] whether the linter is enabled for the tree
14
+ def visit_root(root)
15
+ return unless enabled?(root)
16
+
17
+ first_child = root.children.first
18
+ return if first_child.is_a?(HamlLint::Tree::HamlCommentNode) &&
19
+ first_child.is_strict_locals?
20
+
21
+ # Check whether this linter is disabled by a comment
22
+ return if first_child.disabled?(self)
23
+
24
+ record_lint(DummyNode.new(1), failure_message)
25
+ end
26
+
27
+ private
28
+
29
+ # Checks whether the linter is enabled for the file.
30
+ #
31
+ # @api private
32
+ # @return [true, false]
33
+ def enabled?(root)
34
+ matcher.match(File.basename(root.file)) ? true : false
35
+ end
36
+
37
+ # The type of files the linter is configured to check.
38
+ #
39
+ # @api private
40
+ # @return [String]
41
+ def file_types
42
+ @file_types ||= config['file_types'] || 'partial'
43
+ end
44
+
45
+ # The matcher to use for testing whether to check a file by file name.
46
+ #
47
+ # @api private
48
+ # @return [Regexp]
49
+ def matcher
50
+ @matcher ||= Regexp.new(config['matchers'][file_types] || '\A_.*\.haml\z')
51
+ end
52
+
53
+ # The error message when an `locals` comment is not found.
54
+ #
55
+ # @api private
56
+ # @return [String]
57
+ def failure_message
58
+ 'Expected a strict `-# locals: ()` comment at the beginning of the file'
59
+ end
60
+ end
61
+ end
@@ -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?
32
+ text.lstrip.start_with?('locals:')
33
+ end
34
+
28
35
  private
29
36
 
30
37
  def contained_directives
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.60.0'
5
+ VERSION = '0.61.1'
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.60.0
4
+ version: 0.61.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-30 00:00:00.000000000 Z
10
+ date: 2025-03-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: haml
@@ -133,6 +133,7 @@ files:
133
133
  - lib/haml_lint/linter/ruby_comments.rb
134
134
  - lib/haml_lint/linter/space_before_script.rb
135
135
  - lib/haml_lint/linter/space_inside_hash_attributes.rb
136
+ - lib/haml_lint/linter/strict_locals.rb
136
137
  - lib/haml_lint/linter/syntax.rb
137
138
  - lib/haml_lint/linter/tag_name.rb
138
139
  - lib/haml_lint/linter/trailing_empty_lines.rb