haml_lint 0.59.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: 15d3baf951722e2a699bc903a0848affa4a05b38939c67554e0410dfb9b817bb
4
- data.tar.gz: d143ca9d7330ff3f4d7e32fa306be4a520258627f34b0ddd7536964ebdd45c05
3
+ metadata.gz: 62ac7e2f95151a5906ccd99c47f5d948db8502aedf5423fa421666e90922d79e
4
+ data.tar.gz: 39f4f0952d37d191662215f919a1ee62bf38a4a9f93b4b5ad87545f334a97f6b
5
5
  SHA512:
6
- metadata.gz: 85296a42fbb76f5033401ecd2825efafe5efad954ec2e312af2133a468afe1b92f1c95269a571cbfe9cc9366ecc244a257d7e3e4b756911c921820f7d181beb1
7
- data.tar.gz: 90309db3dbfa97deb00561fd6479d82e14519fe3ba59bcc80da456731ab3c830afe389bd958df382748b3d0906fdde4a3c7abe110b99151d1be797e4e1cde63f
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
 
@@ -45,6 +45,18 @@ Layout/EndAlignment:
45
45
  Layout/EndOfLine:
46
46
  Enabled: false
47
47
 
48
+ # Complying with this lint requires the use of pipes which causes a conflict with MultilinePipe.
49
+ Layout/FirstArrayElementLineBreak:
50
+ Enabled: false
51
+
52
+ # Complying with this lint requires the use of pipes which causes a conflict with MultilinePipe.
53
+ Layout/FirstHashElementLineBreak:
54
+ Enabled: false
55
+
56
+ # Complying with this lint requires the use of pipes which causes a conflict with MultilinePipe.
57
+ Layout/FirstMethodArgumentLineBreak:
58
+ Enabled: false
59
+
48
60
  # Turning this cop on can turn
49
61
  # = content_tag(:span) do
50
62
  # - foo
@@ -21,7 +21,7 @@ module HamlLint
21
21
  return unless enabled?
22
22
 
23
23
  if node.parsed_script.contains_instance_variables?
24
- record_lint(node, "Avoid using instance variables in #{file_types} views")
24
+ record_lint(node, failure_message)
25
25
  end
26
26
  end
27
27
 
@@ -41,10 +41,27 @@ module HamlLint
41
41
 
42
42
  visit_script(node) ||
43
43
  if node.parsed_attributes.contains_instance_variables?
44
- record_lint(node, "Avoid using instance variables in #{file_types} views")
44
+ record_lint(node, failure_message)
45
45
  end
46
46
  end
47
47
 
48
+ # Checks for instance variables in :ruby filters when the linter is enabled.
49
+ #
50
+ # @param [HamlLint::Tree::FilterNode]
51
+ # @return [void]
52
+ def visit_filter(node)
53
+ return unless enabled?
54
+ return unless node.filter_type == 'ruby'
55
+ return unless ast = parse_ruby(node.text)
56
+
57
+ ast.each_node do |i|
58
+ if i.type == :ivar
59
+ record_lint(node, failure_message)
60
+ break
61
+ end
62
+ end
63
+ end
64
+
48
65
  private
49
66
 
50
67
  # Tracks whether the linter is enabled for the file.
@@ -75,5 +92,13 @@ module HamlLint
75
92
  def matcher
76
93
  @matcher ||= Regexp.new(config['matchers'][file_types] || '\A_.*\.haml\z')
77
94
  end
95
+
96
+ # The error message when an ivar is found
97
+ #
98
+ # @api private
99
+ # @return [String]
100
+ def failure_message
101
+ "Avoid using instance variables in #{file_types} views"
102
+ end
78
103
  end
79
104
  end
@@ -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
@@ -10,7 +10,7 @@ module HamlLint
10
10
  # @param args [Array<String>] arguments passed via the command line
11
11
  # @return [Hash] parsed options
12
12
  def parse(args)
13
- @options = {}
13
+ @options = default_options
14
14
 
15
15
  OptionParser.new do |parser|
16
16
  parser.banner = "Usage: #{APP_NAME} [options] [file1, file2, ...]"
@@ -32,6 +32,10 @@ module HamlLint
32
32
 
33
33
  private
34
34
 
35
+ def default_options
36
+ { parallel: true }
37
+ end
38
+
35
39
  def add_linter_options(parser) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
36
40
  parser.on('--auto-gen-config', 'Generate a configuration file acting as a TODO list') do
37
41
  @options[:auto_gen_config] = true
@@ -56,6 +60,10 @@ module HamlLint
56
60
  @options[:parallel] = true
57
61
  end
58
62
 
63
+ parser.on('--no-parallel', 'Disable parallel linter runs') do
64
+ @options[:parallel] = false
65
+ end
66
+
59
67
  parser.on('-a', '--auto-correct', 'Auto-correct offenses (only when it’s safe)') do
60
68
  @options[:autocorrect] = :safe
61
69
  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.59.0'
5
+ VERSION = '0.61.0'
6
6
  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.59.0
4
+ version: 0.61.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: 2024-09-28 00:00:00.000000000 Z
10
+ date: 2025-02-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: haml
@@ -134,6 +133,7 @@ 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
@@ -201,7 +201,6 @@ homepage: https://github.com/sds/haml-lint
201
201
  licenses:
202
202
  - MIT
203
203
  metadata: {}
204
- post_install_message:
205
204
  rdoc_options: []
206
205
  require_paths:
207
206
  - lib
@@ -216,8 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
215
  - !ruby/object:Gem::Version
217
216
  version: '0'
218
217
  requirements: []
219
- rubygems_version: 3.5.9
220
- signing_key:
218
+ rubygems_version: 3.6.2
221
219
  specification_version: 4
222
220
  summary: HAML lint tool
223
221
  test_files: []