haml_lint 0.40.0 → 0.41.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: 8ef9ca7cc6bbd3b5f9663a2bda75669062b25efeb53af9e32cf152fd7f5aee6c
4
- data.tar.gz: 35e34d39d55e13910ec90f9ee7ece9a4baa2d6bc44f2f6962b230f6387519174
3
+ metadata.gz: 50f707542a5125e9d359aec64947951bc3ec4dc27b4d96995320c8f2253e6f1a
4
+ data.tar.gz: b39a5f05253172bf897eb608bc7ccc4445d8fd76b84d38616c7ad53cacc5a276
5
5
  SHA512:
6
- metadata.gz: 376df9f9c0de3c0949bd2187bb1ba9f3bc5e381644a93c827ca085125ac2922f59f98d048d8bf548b379ebe5def5180f9b182628030f4e66454f3edf71478f9f
7
- data.tar.gz: fa1a9ad202224e1059dd7802b1aea08db8b9d11570feca891a31650dc3b10f0b991b2585ad27faa4425bc2165a2b23e799075c944250a43568e1d17c7f83f8b1
6
+ metadata.gz: fa4d026d1b5ee13a4cb3e98dcff7117cba888a84684404166e5df193355978e2514d581ad6d92d7d92f65dfc2f00fc76fe16067ed2d223366b6e64d440ca6788
7
+ data.tar.gz: b46c4532c31cbd25e57b863b16775bdc496a1e2abad2ef5683dc75ad44f7d8ad13348ed8587e9209896226eea7e36f09c108c41b0da223381cddf9a565a46982
data/config/default.yml CHANGED
@@ -97,6 +97,7 @@ linters:
97
97
  - Layout/CaseIndentation
98
98
  - Layout/ElseAlignment
99
99
  - Layout/EndOfLine
100
+ - Layout/FirstHashElementIndentation
100
101
  - Layout/HashAlignment
101
102
  - Layout/IndentationWidth
102
103
  - Layout/LineLength # renamed from Metrics/LineLength in rubocop 0.79.0
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HamlLint
4
+ class Adapter
5
+ # Adapts the Haml::Parser from Haml 5 for use in HamlLint
6
+ # :reek:UncommunicativeModuleName
7
+ class Haml6 < Adapter
8
+ # Parses the specified Haml code into an abstract syntax tree
9
+ #
10
+ # @example
11
+ # HamlLint::Adapter::Haml6.new('%div')
12
+ #
13
+ # @api public
14
+ # @param source [String] Haml code to parse
15
+ # @param options [private Haml::Parser::ParserOptions]
16
+ def initialize(source, options = {})
17
+ @source = source
18
+ @parser = Haml::Parser.new(options)
19
+ end
20
+
21
+ # Parses the source code into an abstract syntax tree
22
+ #
23
+ # @example
24
+ # HamlLint::Adapter::Haml6.new('%div').parse
25
+ #
26
+ # @api public
27
+ # @return [Haml::Parser::ParseNode]
28
+ # @raise [Haml::Error]
29
+ def parse
30
+ parser.call(source)
31
+ end
32
+
33
+ private
34
+
35
+ # The Haml parser to adapt for HamlLint
36
+ #
37
+ # @api private
38
+ # @return [Haml::Parser] the Haml 4 parser
39
+ attr_reader :parser
40
+
41
+ # The Haml code to parse
42
+ #
43
+ # @api private
44
+ # @return [String] Haml code to parse
45
+ attr_reader :source
46
+ end
47
+ end
48
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'haml_lint/adapter/haml_4'
4
4
  require 'haml_lint/adapter/haml_5'
5
+ require 'haml_lint/adapter/haml_6'
5
6
  require 'haml_lint/exceptions'
6
7
 
7
8
  module HamlLint
@@ -20,6 +21,7 @@ module HamlLint
20
21
  case version
21
22
  when '~> 4.0' then HamlLint::Adapter::Haml4
22
23
  when '~> 5.0', '~> 5.1', '~> 5.2' then HamlLint::Adapter::Haml5
24
+ when '~> 6.0', '~> 6.0.a' then HamlLint::Adapter::Haml6
23
25
  else fail HamlLint::Exceptions::UnknownHamlVersion, "Cannot handle Haml version: #{version}"
24
26
  end
25
27
  end
@@ -69,12 +69,12 @@ module HamlLint
69
69
  # variable" lints)
70
70
  additional_attributes.each do |attributes_code|
71
71
  # Normalize by removing excess whitespace to avoid format lints
72
- attributes_code = attributes_code.gsub(/\s*\n\s*/, ' ').strip
72
+ attributes_code = attributes_code.gsub(/\s*\n\s*/, "\n").strip
73
73
 
74
74
  # Attributes can either be a method call or a literal hash, so wrap it
75
75
  # in a method call itself in order to avoid having to differentiate the
76
76
  # two.
77
- add_line("{}.merge(#{attributes_code.strip})", node)
77
+ add_line("{}.merge(#{attributes_code})", node)
78
78
  end
79
79
 
80
80
  check_tag_static_hash_source(node)
@@ -94,6 +94,7 @@ module HamlLint
94
94
 
95
95
  def visit_script(node)
96
96
  code = node.text
97
+
97
98
  add_line(code.strip, node)
98
99
 
99
100
  start_block = anonymous_block?(code) || start_block_keyword?(code)
@@ -9,7 +9,13 @@ module HamlLint::Tree
9
9
  #
10
10
  # @return [ParsedRuby] syntax tree in the form returned by Parser gem
11
11
  def parsed_script
12
- HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(script))
12
+ statement =
13
+ if children.empty?
14
+ script
15
+ else
16
+ "#{script}#{@value[:keyword] == 'case' ? ';when 0;end' : ';end'}"
17
+ end
18
+ HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(statement))
13
19
  end
14
20
 
15
21
  # Returns the source for the script following the `-` marker.
@@ -8,7 +8,22 @@ module HamlLint::Tree
8
8
  #
9
9
  # @return [ParsedRuby] syntax tree in the form returned by Parser gem
10
10
  def parsed_script
11
- HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(script))
11
+ statement =
12
+ case keyword = @value[:keyword]
13
+ when 'else', 'elsif'
14
+ 'if 0;' + script + ';end'
15
+ when 'when'
16
+ 'case;' + script + ';end'
17
+ when 'rescue', 'ensure'
18
+ 'begin;' + script + ';end'
19
+ else
20
+ if children.empty?
21
+ script
22
+ else
23
+ "#{script}#{keyword == 'case' ? ';when 0;end' : ';end'}"
24
+ end
25
+ end
26
+ HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(statement))
12
27
  end
13
28
 
14
29
  # Returns the source for the script following the `-` marker.
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.40.0'
5
+ VERSION = '0.41.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.40.0
4
+ version: 0.41.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: 2022-02-27 00:00:00.000000000 Z
11
+ date: 2022-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.3'
22
+ version: '6.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.3'
32
+ version: '6.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: parallel
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,7 @@ files:
100
100
  - lib/haml_lint/adapter.rb
101
101
  - lib/haml_lint/adapter/haml_4.rb
102
102
  - lib/haml_lint/adapter/haml_5.rb
103
+ - lib/haml_lint/adapter/haml_6.rb
103
104
  - lib/haml_lint/cli.rb
104
105
  - lib/haml_lint/comment_configuration.rb
105
106
  - lib/haml_lint/configuration.rb