haml_lint 0.51.0 → 0.53.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: 71dc6acf56f28f4f6878ff300a653d1fb6c5cc6fa9da23c71813463ea9e1b67a
4
- data.tar.gz: af2fa134ec9718c24d019e20c359c9a965d6d09490e6f57fe202654f5f7f95a3
3
+ metadata.gz: 49bb0bec15e96c047439560e80f83eaf6f4c3baec24a12b1f10248f1d2f347d3
4
+ data.tar.gz: 153f65eda76c5751bbae1d02fc49d0d4477f401bb273096ad9308868b9d21288
5
5
  SHA512:
6
- metadata.gz: 73c8a4c7fbd68cfbeacd29e5d313dcf9ae120a624a0359fecf5ca25396a8e68a0cfbad68b0ac9854af82a9233ffb26a9adf7db156f8dd3b5eb8b7a83773db035
7
- data.tar.gz: fcb59570ff3b999f81f12208993ab75118013b0262586478145d7d0eaa9bab78002d9808757e10025324082f895bb0962743133898dd31dbb6c3db73d4c7f68c
6
+ metadata.gz: a4d2c2682e7b12d9aaf8164054f3533c0667f5f6035bfbf5ef6bbb694a40f9a70d9d13a9aa56dabf27131be27e74d346c9eff642a65d0e2aac8992ebc1999fba
7
+ data.tar.gz: 343aee9ed9bf4a766640aabbbaf96af9a5c36261fb6e6943b9a0b9eadcb5c75bc5a15665cae30c3c4c8925b307ecca837130fb04cf1d14a74549978db235f60c
data/bin/haml-lint CHANGED
@@ -4,5 +4,4 @@
4
4
  require 'haml_lint'
5
5
  require 'haml_lint/cli'
6
6
 
7
- logger = HamlLint::Logger.new($stdout)
8
- exit HamlLint::CLI.new(logger).run(ARGV)
7
+ exit HamlLint::CLI.new.run(ARGV)
@@ -46,7 +46,7 @@ module HamlLint
46
46
  # The Haml parser to adapt for HamlLint
47
47
  #
48
48
  # @api private
49
- # @return [Haml::Parser] the Haml 4 parser
49
+ # @return [Haml::Parser] the Haml 5 parser
50
50
  attr_reader :parser
51
51
 
52
52
  # The Haml code to parse
@@ -2,7 +2,7 @@
2
2
 
3
3
  module HamlLint
4
4
  class Adapter
5
- # Adapts the Haml::Parser from Haml 5 for use in HamlLint
5
+ # Adapts the Haml::Parser from Haml 6 for use in HamlLint
6
6
  # :reek:UncommunicativeModuleName
7
7
  class Haml6 < Adapter
8
8
  # Parses the specified Haml code into an abstract syntax tree
@@ -46,7 +46,7 @@ module HamlLint
46
46
  # The Haml parser to adapt for HamlLint
47
47
  #
48
48
  # @api private
49
- # @return [Haml::Parser] the Haml 4 parser
49
+ # @return [Haml::Parser] the Haml 6 parser
50
50
  attr_reader :parser
51
51
 
52
52
  # The Haml code to parse
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'haml_lint/adapter/haml_4'
4
3
  require 'haml_lint/adapter/haml_5'
5
4
  require 'haml_lint/adapter/haml_6'
6
5
  require 'haml_lint/exceptions'
@@ -19,9 +18,8 @@ module HamlLint
19
18
  def self.detect_class
20
19
  version = haml_version
21
20
  case version
22
- when '~> 4.0' then HamlLint::Adapter::Haml4
23
21
  when '~> 5.0', '~> 5.1', '~> 5.2' then HamlLint::Adapter::Haml5
24
- when '~> 6.0', '~> 6.0.a', '~> 6.1', '~> 6.2' then HamlLint::Adapter::Haml6
22
+ when '~> 6.0', '~> 6.0.a', '~> 6.1', '~> 6.2', '~> 6.3' then HamlLint::Adapter::Haml6
25
23
  else fail HamlLint::Exceptions::UnknownHamlVersion, "Cannot handle Haml version: #{version}"
26
24
  end
27
25
  end
data/lib/haml_lint/cli.rb CHANGED
@@ -10,8 +10,8 @@ module HamlLint
10
10
  class CLI
11
11
  # Create a CLI that outputs to the specified logger.
12
12
  #
13
- # @param logger [HamlLint::Logger]
14
- def initialize(logger)
13
+ # @param logger [HamlLint::Logger, nil]
14
+ def initialize(logger = nil)
15
15
  @log = logger
16
16
  end
17
17
 
@@ -63,6 +63,7 @@ module HamlLint
63
63
  #
64
64
  # @return [void]
65
65
  def configure_logger(options)
66
+ @log ||= HamlLint::Logger.new(options[:stderr] ? $stderr : $stdout)
66
67
  log.color_enabled = options.fetch(:color, log.tty?)
67
68
  log.summary_enabled = options.fetch(:summary, true)
68
69
  end
@@ -69,6 +69,10 @@ module HamlLint
69
69
  @options[:autocorrect_only] = true
70
70
  @options[:autocorrect] ||= :safe
71
71
  end
72
+
73
+ parser.on('--stderr', 'Write all output to stderr') do
74
+ @options[:stderr] = true
75
+ end
72
76
  end
73
77
 
74
78
  def add_report_options(parser)
@@ -104,7 +104,7 @@ module HamlLint
104
104
  # @param task_args [Rake::TaskArguments]
105
105
  def run_cli(task_args)
106
106
  cli_args = parse_args
107
- logger = quiet ? HamlLint::Logger.silent : HamlLint::Logger.new($stdout)
107
+ logger = quiet ? HamlLint::Logger.silent : nil
108
108
  result = HamlLint::CLI.new(logger).run(Array(cli_args) + files_to_lint(task_args))
109
109
 
110
110
  fail "#{HamlLint::APP_NAME} failed with exit code #{result}" unless result == 0
@@ -84,7 +84,35 @@ module HamlLint::RubyExtraction
84
84
  def visit_comment(node)
85
85
  line = @original_haml_lines[node.line - 1]
86
86
  indent = line.index(/\S/)
87
+
87
88
  @ruby_chunks << PlaceholderMarkerChunk.new(node, 'comment', indent: indent)
89
+
90
+ # Comment can have subnodes, such as plain. This happens for conditional comments, such as:
91
+ # %head
92
+ # /[if mso]
93
+ # %div
94
+ if node.children
95
+ # We don't want to use a block because assignments in a block are local to that block,
96
+ # so the semantics of the extracted ruby would be different from the one generated by
97
+ # Haml. Those differences can make some cops, such as UselessAssignment, have false
98
+ # positives
99
+ begin_chunk = AdHocChunk.new(node, [' ' * indent + 'begin'])
100
+ @ruby_chunks << begin_chunk
101
+ indent += 2
102
+
103
+ yield
104
+
105
+ indent -= 2
106
+
107
+ if @ruby_chunks.last.equal?(begin_chunk)
108
+ # So there is nothing nesting, remove the wrapping "begin"
109
+ @ruby_chunks.pop
110
+ else
111
+ @ruby_chunks << AdHocChunk.new(node,
112
+ [' ' * indent + 'ensure', ' ' * indent + ' HL.noop', ' ' * indent + 'end'],
113
+ haml_line_index: @ruby_chunks.last.haml_end_line_index)
114
+ end
115
+ end
88
116
  end
89
117
 
90
118
  # Visit a script which outputs. Lines looking like ` = foo`
@@ -16,10 +16,26 @@ module HamlLint::Tree
16
16
  #
17
17
  # @param line [Integer] the line number of the node
18
18
  # @return [HamlLint::Node]
19
- def node_for_line(line)
20
- find(-> { HamlLint::Tree::NullNode.new }) do |node|
21
- node.line_numbers.cover?(line) && node != self
19
+ def node_for_line(line) # rubocop:disable Metrics
20
+ each do |node|
21
+ return node if node.line_numbers.cover?(line) && node != self
22
22
  end
23
+
24
+ # Because HAML doesn't leave any trace in the nodes when it merges lines that
25
+ # end with a comma, it's harder to assign a node to the second line here:
26
+ # = some_call user,
27
+ # foo, bar
28
+ # So if the simple strategy (above) doesn't work, we try to see if we check if the last node
29
+ # that was before the requested line was one that could have been merged. If so, we use that one.
30
+ best_guess = nil
31
+ each do |node|
32
+ best_guess = node if node != self && node.line_numbers.end < line
33
+ end
34
+
35
+ # There are the cases were the merging without traces can happen
36
+ return best_guess if best_guess && %i[script silent_script tag].include?(best_guess.type)
37
+
38
+ HamlLint::Tree::NullNode.new
23
39
  end
24
40
  end
25
41
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.51.0'
5
+ VERSION = '0.53.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.0
4
+ version: 0.53.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: parallel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +93,6 @@ files:
93
93
  - config/forced_rubocop_config.yml
94
94
  - lib/haml_lint.rb
95
95
  - lib/haml_lint/adapter.rb
96
- - lib/haml_lint/adapter/haml_4.rb
97
96
  - lib/haml_lint/adapter/haml_5.rb
98
97
  - lib/haml_lint/adapter/haml_6.rb
99
98
  - lib/haml_lint/cli.rb
@@ -200,7 +199,7 @@ homepage: https://github.com/sds/haml-lint
200
199
  licenses:
201
200
  - MIT
202
201
  metadata: {}
203
- post_install_message:
202
+ post_install_message:
204
203
  rdoc_options: []
205
204
  require_paths:
206
205
  - lib
@@ -215,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
214
  - !ruby/object:Gem::Version
216
215
  version: '0'
217
216
  requirements: []
218
- rubygems_version: 3.1.6
219
- signing_key:
217
+ rubygems_version: 3.0.3.1
218
+ signing_key:
220
219
  specification_version: 4
221
220
  summary: HAML lint tool
222
221
  test_files: []
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module HamlLint
6
- class Adapter
7
- # Adapts the Haml::Parser from Haml 4 for use in HamlLint
8
- # :reek:UncommunicativeModuleName
9
- class Haml4 < Adapter
10
- extend Forwardable
11
-
12
- # Parses the specified Haml code into an abstract syntax tree
13
- #
14
- # @example
15
- # HamlLint::Adapter::Haml4.new('%div')
16
- #
17
- # @api public
18
- # @param source [String] Haml code to parse
19
- # @param options [Haml::Options]
20
- def initialize(source, options = Haml::Options.new)
21
- @source = source
22
- @parser = Haml::Parser.new(source, options)
23
- end
24
-
25
- def precompile
26
- # Haml uses the filters as part of precompilation... we don't care about those,
27
- # but without this tweak, it would fail on filters that are not loaded.
28
- real_defined = Haml::Filters.defined
29
- Haml::Filters.instance_variable_set(:@defined, Hash.new { real_defined['plain'] })
30
-
31
- ::Haml::Engine.new(source).precompiled
32
- ensure
33
- Haml::Filters.instance_variable_set(:@defined, real_defined)
34
- end
35
-
36
- # @!method
37
- # Parses the source code into an abstract syntax tree
38
- #
39
- # @example
40
- # HamlLint::Adapter::Haml4.new('%div')
41
- #
42
- # @api public
43
- # @return [Haml::Parser::ParseNode]
44
- # @raise [Haml::Error]
45
- def_delegator :parser, :parse
46
-
47
- private
48
-
49
- # The Haml parser to adapt for HamlLint
50
- #
51
- # @api private
52
- # @return [Haml::Parser] the Haml 4 parser
53
- attr_reader :parser
54
-
55
- # The Haml code to parse
56
- #
57
- # @api private
58
- # @return [String] Haml code to parse
59
- attr_reader :source
60
- end
61
- end
62
- end