haml_lint 0.40.0 → 0.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +1 -0
- data/lib/haml_lint/adapter/haml_4.rb +2 -0
- data/lib/haml_lint/adapter/haml_6.rb +48 -0
- data/lib/haml_lint/adapter.rb +2 -0
- data/lib/haml_lint/linter/rubocop.rb +2 -1
- data/lib/haml_lint/ruby_extractor.rb +3 -2
- data/lib/haml_lint/tree/script_node.rb +7 -1
- data/lib/haml_lint/tree/silent_script_node.rb +16 -1
- data/lib/haml_lint/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45d676ecd18fa32156a84c6f6d2c5a062a3a74fc8bacfc5ae6ec9e2b2c5436a7
|
4
|
+
data.tar.gz: '038b1f81556d35a4c6037b2ec5e08428465f8d09258d3c603a3ee7cbaf4f1f55'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e69de9bbae167b9f61818498b008dfb4789a41d7b9753b04035951c544385d160e69ccde08dee04ee2a7a786efc14f4657ed468935056ade34fcf0d185d82167
|
7
|
+
data.tar.gz: dc2e034a37c3fb7ede287d16d83b1cdbfbc1597ee5ba96c59571b9b975585112d36880a228d9ea35585a958694d7f322e965f4d927d95de167dd5399cf93417c
|
data/config/default.yml
CHANGED
@@ -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
|
data/lib/haml_lint/adapter.rb
CHANGED
@@ -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
|
@@ -100,8 +100,9 @@ module HamlLint
|
|
100
100
|
#
|
101
101
|
# @return [Array<String>]
|
102
102
|
def rubocop_flags
|
103
|
+
config_file = ENV['HAML_LINT_RUBOCOP_CONF'] || config['config_file']
|
103
104
|
flags = %w[--format HamlLint::OffenseCollector]
|
104
|
-
flags += ['--config',
|
105
|
+
flags += ['--config', config_file] if config_file
|
105
106
|
flags += ['--stdin']
|
106
107
|
flags
|
107
108
|
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*/,
|
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
|
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
|
-
|
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
|
-
|
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.
|
data/lib/haml_lint/version.rb
CHANGED
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.
|
4
|
+
version: 0.42.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-
|
11
|
+
date: 2022-09-27 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: '
|
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: '
|
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
|