haml_lint 0.51.0 → 0.52.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71dc6acf56f28f4f6878ff300a653d1fb6c5cc6fa9da23c71813463ea9e1b67a
4
- data.tar.gz: af2fa134ec9718c24d019e20c359c9a965d6d09490e6f57fe202654f5f7f95a3
3
+ metadata.gz: 24f37fc2b314359fb58b5209e58399fa01f53d51c977a4c60b66d9497e2acde5
4
+ data.tar.gz: afb033a6021882a269ec1fdf989d06c83c6df8047a3f60233ac83ac9f234469d
5
5
  SHA512:
6
- metadata.gz: 73c8a4c7fbd68cfbeacd29e5d313dcf9ae120a624a0359fecf5ca25396a8e68a0cfbad68b0ac9854af82a9233ffb26a9adf7db156f8dd3b5eb8b7a83773db035
7
- data.tar.gz: fcb59570ff3b999f81f12208993ab75118013b0262586478145d7d0eaa9bab78002d9808757e10025324082f895bb0962743133898dd31dbb6c3db73d4c7f68c
6
+ metadata.gz: abb4758509d1aca40826e598c8d1bdfb7daffbbbeb9d1955c18463e44c4799ce5102151ae34b58799198336d87ba2c4e922a699b8f9c28b13f94479d80f4607a
7
+ data.tar.gz: f585fb701da7d6ca46ab9612055a25be83c640c97da530fa19ca20684e27056955ca80714a666fef1568fb8fa4bceba5830005167b3f4a76dc575732876d125e
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
@@ -21,7 +21,7 @@ module HamlLint
21
21
  case version
22
22
  when '~> 4.0' then HamlLint::Adapter::Haml4
23
23
  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
24
+ when '~> 6.0', '~> 6.0.a', '~> 6.1', '~> 6.2', '~> 6.3' then HamlLint::Adapter::Haml6
25
25
  else fail HamlLint::Exceptions::UnknownHamlVersion, "Cannot handle Haml version: #{version}"
26
26
  end
27
27
  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
@@ -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.52.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.52.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml