haml_lint 0.60.0 → 0.61.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bf4b2b435129bea13f5c1b32aabf202f5e8731264df179e3e7a9c16017b8654
4
- data.tar.gz: 34a95aa1ac68c54a513d9431be449f5a53963d77e7d451cfa532c60ff08fe08f
3
+ metadata.gz: 62ac7e2f95151a5906ccd99c47f5d948db8502aedf5423fa421666e90922d79e
4
+ data.tar.gz: 39f4f0952d37d191662215f919a1ee62bf38a4a9f93b4b5ad87545f334a97f6b
5
5
  SHA512:
6
- metadata.gz: a65d869de4f21555cc165baccae390ae09202de3d6aea707404806d0ee40bdd1d5916d7ab3ae9a7b4a0d35c1a4a5a8c89da3cb317389877460e03f48b5577c54
7
- data.tar.gz: 84ccd1349eb889e3b516f42e4919eb0003566f01ba62a01b05cce28aeb801138c6f725eac054c23073997f0e67e452765ac78c03bfe710639c9742828b85521d
6
+ metadata.gz: 21bdfc9e4ac041b44dbf6ca6d1ceca373f54d210c5c6035bc9e47ff0be3c772a4fcbfcbd4b3fe0131facb3e42a816d9a8d7dbae824bf66198a3453daff8c865a
7
+ data.tar.gz: 2a459e90165257a12086205ff8bad69dd39845873e7d95888788f56b538be330f69bca13deb3c993ae77d05e7f8c43586db3be737a9d3af178adcc2919a6f9fd
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,58 @@
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_children = root.children.first
18
+ return if first_children.is_a?(HamlLint::Tree::HamlCommentNode) &&
19
+ first_children.is_strict_locals?
20
+
21
+ record_lint(DummyNode.new(1), failure_message)
22
+ end
23
+
24
+ private
25
+
26
+ # Checks whether the linter is enabled for the file.
27
+ #
28
+ # @api private
29
+ # @return [true, false]
30
+ def enabled?(root)
31
+ matcher.match(File.basename(root.file)) ? true : false
32
+ end
33
+
34
+ # The type of files the linter is configured to check.
35
+ #
36
+ # @api private
37
+ # @return [String]
38
+ def file_types
39
+ @file_types ||= config['file_types'] || 'partial'
40
+ end
41
+
42
+ # The matcher to use for testing whether to check a file by file name.
43
+ #
44
+ # @api private
45
+ # @return [Regexp]
46
+ def matcher
47
+ @matcher ||= Regexp.new(config['matchers'][file_types] || '\A_.*\.haml\z')
48
+ end
49
+
50
+ # The error message when an `locals` comment is not found.
51
+ #
52
+ # @api private
53
+ # @return [String]
54
+ def failure_message
55
+ 'Expected a strict `-# locals: ()` comment at the beginning of the file'
56
+ end
57
+ end
58
+ 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.0'
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.0
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-02-24 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