haml_lint 0.21.0 → 0.22.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 +4 -4
- data/config/default.yml +18 -0
- data/lib/haml_lint/adapter/haml_4.rb +40 -0
- data/lib/haml_lint/adapter/haml_5.rb +46 -0
- data/lib/haml_lint/adapter.rb +36 -0
- data/lib/haml_lint/cli.rb +12 -9
- data/lib/haml_lint/comment_configuration.rb +39 -0
- data/lib/haml_lint/directive.rb +128 -0
- data/lib/haml_lint/document.rb +3 -1
- data/lib/haml_lint/exceptions.rb +6 -0
- data/lib/haml_lint/haml_visitor.rb +4 -2
- data/lib/haml_lint/lint.rb +2 -2
- data/lib/haml_lint/linter/alignment_tabs.rb +12 -0
- data/lib/haml_lint/linter/consecutive_comments.rb +19 -2
- data/lib/haml_lint/linter/consecutive_silent_scripts.rb +18 -2
- data/lib/haml_lint/linter/final_newline.rb +6 -5
- data/lib/haml_lint/linter/id_names.rb +28 -0
- data/lib/haml_lint/linter/indentation.rb +4 -2
- data/lib/haml_lint/linter/instance_variables.rb +77 -0
- data/lib/haml_lint/linter/line_length.rb +5 -3
- data/lib/haml_lint/linter/repeated_id.rb +34 -0
- data/lib/haml_lint/linter/syntax.rb +6 -0
- data/lib/haml_lint/linter/trailing_whitespace.rb +5 -4
- data/lib/haml_lint/linter.rb +1 -1
- data/lib/haml_lint/logger.rb +7 -1
- data/lib/haml_lint/options.rb +20 -4
- data/lib/haml_lint/parsed_ruby.rb +22 -0
- data/lib/haml_lint/rake_task.rb +16 -2
- data/lib/haml_lint/report.rb +46 -2
- data/lib/haml_lint/reporter/default_reporter.rb +7 -29
- data/lib/haml_lint/reporter/hash_reporter.rb +51 -0
- data/lib/haml_lint/reporter/hooks.rb +25 -0
- data/lib/haml_lint/reporter/json_reporter.rb +2 -45
- data/lib/haml_lint/reporter/progress_reporter.rb +47 -0
- data/lib/haml_lint/reporter/utils.rb +101 -0
- data/lib/haml_lint/reporter.rb +4 -0
- data/lib/haml_lint/runner.rb +70 -10
- data/lib/haml_lint/severity.rb +95 -0
- data/lib/haml_lint/tree/haml_comment_node.rb +18 -0
- data/lib/haml_lint/tree/node.rb +116 -16
- data/lib/haml_lint/tree/null_node.rb +15 -0
- data/lib/haml_lint/tree/root_node.rb +16 -0
- data/lib/haml_lint/tree/script_node.rb +9 -0
- data/lib/haml_lint/tree/silent_script_node.rb +7 -0
- data/lib/haml_lint/tree/tag_node.rb +24 -5
- data/lib/haml_lint/version.rb +1 -1
- data/lib/haml_lint.rb +1 -0
- metadata +41 -4
data/lib/haml_lint/runner.rb
CHANGED
@@ -10,22 +10,47 @@ module HamlLint
|
|
10
10
|
# @option options :excluded_files [Array<String>]
|
11
11
|
# @option options :included_linters [Array<String>]
|
12
12
|
# @option options :excluded_linters [Array<String>]
|
13
|
+
# @option options :fail_fast [true, false] flag for failing after first failure
|
14
|
+
# @option options :fail_level
|
15
|
+
# @option options :reporter [HamlLint::Reporter]
|
13
16
|
# @return [HamlLint::Report] a summary of all lints found
|
14
17
|
def run(options = {})
|
15
|
-
config = load_applicable_config(options)
|
16
|
-
files = extract_applicable_files(config, options)
|
18
|
+
@config = load_applicable_config(options)
|
19
|
+
@files = extract_applicable_files(config, options)
|
20
|
+
@linter_selector = HamlLint::LinterSelector.new(config, options)
|
21
|
+
@fail_fast = options.fetch(:fail_fast, false)
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
lints = files.map do |file|
|
21
|
-
collect_lints(file, linter_selector, config)
|
22
|
-
end.flatten
|
23
|
-
|
24
|
-
HamlLint::Report.new(lints, files)
|
23
|
+
report(options)
|
25
24
|
end
|
26
25
|
|
27
26
|
private
|
28
27
|
|
28
|
+
# The {HamlLint::Configuration} that should be used for this run.
|
29
|
+
#
|
30
|
+
# @return [HamlLint::Configuration]
|
31
|
+
attr_reader :config
|
32
|
+
|
33
|
+
# A flag for whether to fail after the first failure.
|
34
|
+
#
|
35
|
+
# @return [true, false]
|
36
|
+
attr_reader :fail_fast
|
37
|
+
|
38
|
+
# !@method fail_fast?
|
39
|
+
# Checks whether to fail after the first failure.
|
40
|
+
#
|
41
|
+
# @return [true, false]
|
42
|
+
alias fail_fast? fail_fast
|
43
|
+
|
44
|
+
# The list of files to lint during this run.
|
45
|
+
#
|
46
|
+
# @return [Array<String>]
|
47
|
+
attr_reader :files
|
48
|
+
|
49
|
+
# The selector for which linters to run during this run.
|
50
|
+
#
|
51
|
+
# @return [HamlLint::LinterSelector]
|
52
|
+
attr_reader :linter_selector
|
53
|
+
|
29
54
|
# Returns the {HamlLint::Configuration} that should be used given the
|
30
55
|
# specified options.
|
31
56
|
#
|
@@ -51,7 +76,8 @@ module HamlLint
|
|
51
76
|
begin
|
52
77
|
document = HamlLint::Document.new(File.read(file), file: file, config: config)
|
53
78
|
rescue HamlLint::Exceptions::ParseError => ex
|
54
|
-
return [HamlLint::Lint.new(
|
79
|
+
return [HamlLint::Lint.new(HamlLint::Linter::Syntax.new(config), file,
|
80
|
+
ex.line, ex.to_s, :error)]
|
55
81
|
end
|
56
82
|
|
57
83
|
linter_selector.linters_for_file(file).map do |linter|
|
@@ -72,5 +98,39 @@ module HamlLint
|
|
72
98
|
|
73
99
|
HamlLint::FileFinder.new(config).find(included_patterns, excluded_patterns)
|
74
100
|
end
|
101
|
+
|
102
|
+
# Process the files and add them to the given report.
|
103
|
+
#
|
104
|
+
# @param report [HamlLint::Report]
|
105
|
+
# @return [void]
|
106
|
+
def process_files(report)
|
107
|
+
files.each do |file|
|
108
|
+
process_file(file, report)
|
109
|
+
break if report.failed? && fail_fast?
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Process a file and add it to the given report.
|
114
|
+
#
|
115
|
+
# @param file [String] the name of the file to process
|
116
|
+
# @param report [HamlLint::Report]
|
117
|
+
# @return [void]
|
118
|
+
def process_file(file, report)
|
119
|
+
lints = collect_lints(file, linter_selector, config)
|
120
|
+
lints.each { |lint| report.add_lint(lint) }
|
121
|
+
report.finish_file(file, lints)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Generates a report based on the given options.
|
125
|
+
#
|
126
|
+
# @param options [Hash]
|
127
|
+
# @option options :reporter [HamlLint::Reporter] the reporter to report with
|
128
|
+
# @return [HamlLint::Report]
|
129
|
+
def report(options)
|
130
|
+
report = HamlLint::Report.new(reporter: options[:reporter])
|
131
|
+
report.start(@files)
|
132
|
+
process_files(report)
|
133
|
+
report
|
134
|
+
end
|
75
135
|
end
|
76
136
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module HamlLint
|
4
|
+
# Models the severity of a lint
|
5
|
+
class Severity < SimpleDelegator
|
6
|
+
include Comparable
|
7
|
+
|
8
|
+
SEVERITY_ERROR = :error
|
9
|
+
SEVERITY_WARNING = :warning
|
10
|
+
|
11
|
+
COLORS = { error: :red, warning: :yellow }.freeze
|
12
|
+
MARKS = { error: 'E', warning: 'W' }.freeze
|
13
|
+
NAMES = [SEVERITY_WARNING, SEVERITY_ERROR].freeze
|
14
|
+
|
15
|
+
# Creates a new severity for a lint
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# HamlLint::Severity.new(:warning)
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
# @param name [Symbol] the name of the severity level
|
22
|
+
def initialize(name)
|
23
|
+
name = name.name if name.is_a?(Severity)
|
24
|
+
name ||= :warning
|
25
|
+
fail Exceptions::UnknownSeverity, "Unknown severity: #{name}" unless NAMES.include?(name)
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# The color of the mark in reporters.
|
30
|
+
#
|
31
|
+
# @return [Symbol]
|
32
|
+
def color
|
33
|
+
COLORS[__getobj__]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Checks whether the severity is an error
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# HamlLint::Severity.new(:error).error? #=> true
|
40
|
+
#
|
41
|
+
# @api public
|
42
|
+
# @return [Boolean]
|
43
|
+
def error?
|
44
|
+
__getobj__ == :error
|
45
|
+
end
|
46
|
+
|
47
|
+
# The level of severity for the lint
|
48
|
+
#
|
49
|
+
# @api public
|
50
|
+
# @return [Integer]
|
51
|
+
def level
|
52
|
+
NAMES.index(__getobj__) + 1
|
53
|
+
end
|
54
|
+
|
55
|
+
# The symbol to use in a {HamlLint::Reporter::ProgressReporter}.
|
56
|
+
#
|
57
|
+
# @returns [String]
|
58
|
+
def mark
|
59
|
+
MARKS[__getobj__]
|
60
|
+
end
|
61
|
+
|
62
|
+
# The colorized symbol to use in a reporter.
|
63
|
+
#
|
64
|
+
# @returns [String]
|
65
|
+
def mark_with_color
|
66
|
+
Rainbow.global.wrap(mark).public_send(color)
|
67
|
+
end
|
68
|
+
|
69
|
+
# The name of the severity.
|
70
|
+
#
|
71
|
+
# @returns [Symbol]
|
72
|
+
def name
|
73
|
+
__getobj__
|
74
|
+
end
|
75
|
+
|
76
|
+
# Checks whether the severity is a warning
|
77
|
+
#
|
78
|
+
# @example
|
79
|
+
# HamlLint::Severity.new(:warning).warning? #=> true
|
80
|
+
#
|
81
|
+
# @api public
|
82
|
+
# @return [Boolean]
|
83
|
+
def warning?
|
84
|
+
__getobj__ == :warning
|
85
|
+
end
|
86
|
+
|
87
|
+
# Compares the severity to another severity or a symbol
|
88
|
+
#
|
89
|
+
# @return [Integer]
|
90
|
+
def <=>(other)
|
91
|
+
other = Severity.new(other) unless other.respond_to?(:level)
|
92
|
+
level <=> other.level
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,6 +1,14 @@
|
|
1
|
+
require 'haml_lint/directive'
|
2
|
+
|
1
3
|
module HamlLint::Tree
|
2
4
|
# Represents a HAML comment node.
|
3
5
|
class HamlCommentNode < Node
|
6
|
+
def directives
|
7
|
+
directives = super
|
8
|
+
directives << contained_directives
|
9
|
+
directives.flatten
|
10
|
+
end
|
11
|
+
|
4
12
|
# Returns the full text content of this comment, including newlines if a
|
5
13
|
# single comment spans multiple lines.
|
6
14
|
#
|
@@ -14,5 +22,15 @@ module HamlLint::Tree
|
|
14
22
|
.gsub(/^ /, '')
|
15
23
|
.rstrip
|
16
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def contained_directives
|
29
|
+
text
|
30
|
+
.split("\n")
|
31
|
+
.each_with_index
|
32
|
+
.map { |source, offset| HamlLint::Directive.from_line(source, line + offset) }
|
33
|
+
.reject { |directive| directive.is_a?(HamlLint::Directive::Null) }
|
34
|
+
end
|
17
35
|
end
|
18
36
|
end
|
data/lib/haml_lint/tree/node.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'haml_lint/comment_configuration'
|
2
|
+
|
1
3
|
module HamlLint::Tree
|
2
4
|
# Decorator class that provides a convenient set of helpers for HAML's
|
3
5
|
# {Haml::Parser::ParseNode} struct.
|
@@ -9,6 +11,8 @@ module HamlLint::Tree
|
|
9
11
|
#
|
10
12
|
# @abstract
|
11
13
|
class Node
|
14
|
+
include Enumerable
|
15
|
+
|
12
16
|
attr_accessor :children, :parent
|
13
17
|
attr_reader :line, :type
|
14
18
|
|
@@ -23,24 +27,42 @@ module HamlLint::Tree
|
|
23
27
|
@type = parse_node.type
|
24
28
|
end
|
25
29
|
|
26
|
-
#
|
27
|
-
# block.
|
30
|
+
# Holds any configuration that is created from Haml comments.
|
28
31
|
#
|
29
|
-
#
|
32
|
+
# @return [HamlLint::CommentConfiguration]
|
33
|
+
def comment_configuration
|
34
|
+
@comment_configuration ||= HamlLint::CommentConfiguration.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Checks whether a visitor is disabled due to comment configuration.
|
30
38
|
#
|
31
|
-
# @
|
32
|
-
# @
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
# @param [HamlLint::HamlVisitor]
|
40
|
+
# @return [true, false]
|
41
|
+
def disabled?(visitor)
|
42
|
+
visitor.is_a?(HamlLint::Linter) &&
|
43
|
+
comment_configuration.disabled?(visitor.name)
|
44
|
+
end
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
# Implements the Enumerable interface to walk through an entire tree.
|
47
|
+
#
|
48
|
+
# @return [Enumerator, HamlLint::Tree::Node]
|
49
|
+
def each
|
50
|
+
return to_enum(__callee__) unless block_given?
|
51
|
+
|
52
|
+
node = self
|
53
|
+
loop do
|
54
|
+
yield node
|
55
|
+
break unless (node = node.next_node)
|
41
56
|
end
|
57
|
+
end
|
42
58
|
|
43
|
-
|
59
|
+
# The comment directives to apply to the node.
|
60
|
+
#
|
61
|
+
# @return [Array<HamlLint::Directive>]
|
62
|
+
def directives
|
63
|
+
directives = []
|
64
|
+
directives << predecessor.directives if predecessor
|
65
|
+
directives.flatten
|
44
66
|
end
|
45
67
|
|
46
68
|
# Source code of all lines this node spans (excluding children).
|
@@ -63,6 +85,13 @@ module HamlLint::Tree
|
|
63
85
|
"#<#{self.class.name}>"
|
64
86
|
end
|
65
87
|
|
88
|
+
# The previous node to be traversed in the tree.
|
89
|
+
#
|
90
|
+
# @return [HamlLint::Tree::Node, nil]
|
91
|
+
def predecessor
|
92
|
+
siblings.previous(self) || parent
|
93
|
+
end
|
94
|
+
|
66
95
|
# Returns the node that follows this node, whether it be a sibling or an
|
67
96
|
# ancestor's child, but not a child of this node.
|
68
97
|
#
|
@@ -72,9 +101,7 @@ module HamlLint::Tree
|
|
72
101
|
#
|
73
102
|
# @return [HamlLint::Tree::Node,nil]
|
74
103
|
def successor
|
75
|
-
|
76
|
-
|
77
|
-
next_sibling = siblings[siblings.index(self) + 1] if siblings.count > 1
|
104
|
+
next_sibling = siblings.next(self)
|
78
105
|
return next_sibling if next_sibling
|
79
106
|
|
80
107
|
parent.successor if parent
|
@@ -89,11 +116,84 @@ module HamlLint::Tree
|
|
89
116
|
children.first || successor
|
90
117
|
end
|
91
118
|
|
119
|
+
# The sibling nodes that come after this node in the tree.
|
120
|
+
#
|
121
|
+
# @return [Array<HamlLint::Tree::Node>]
|
122
|
+
def subsequents
|
123
|
+
siblings.subsequents(self)
|
124
|
+
end
|
125
|
+
|
92
126
|
# Returns the text content of this node.
|
93
127
|
#
|
94
128
|
# @return [String]
|
95
129
|
def text
|
96
130
|
@value[:text].to_s
|
97
131
|
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
# The siblings of this node within the tree.
|
136
|
+
#
|
137
|
+
# @api private
|
138
|
+
# @return [Array<HamlLint::Tree::Node>]
|
139
|
+
def siblings
|
140
|
+
@siblings ||= Siblings.new(parent ? parent.children : [self])
|
141
|
+
end
|
142
|
+
|
143
|
+
# Finds the node's siblings within the tree and makes them queryable.
|
144
|
+
class Siblings < SimpleDelegator
|
145
|
+
# Finds the next sibling in the tree for a given node.
|
146
|
+
#
|
147
|
+
# @param node [HamlLint::Tree::Node]
|
148
|
+
# @return [HamlLint::Tree::Node, nil]
|
149
|
+
def next(node)
|
150
|
+
subsequents(node).first
|
151
|
+
end
|
152
|
+
|
153
|
+
# Finds the previous sibling in the tree for a given node.
|
154
|
+
#
|
155
|
+
# @param node [HamlLint::Tree::Node]
|
156
|
+
# @return [HamlLint::Tree::Node, nil]
|
157
|
+
def previous(node)
|
158
|
+
priors(node).last
|
159
|
+
end
|
160
|
+
|
161
|
+
# Finds all sibling notes that appear before a node in the tree.
|
162
|
+
#
|
163
|
+
# @param node [HamlLint::Tree::Node]
|
164
|
+
# @return [Array<HamlLint::Tree::Node>]
|
165
|
+
def priors(node)
|
166
|
+
position = position(node)
|
167
|
+
if position.zero?
|
168
|
+
[]
|
169
|
+
else
|
170
|
+
siblings[0..(position - 1)]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Finds all sibling notes that appear after a node in the tree.
|
175
|
+
#
|
176
|
+
# @param node [HamlLint::Tree::Node]
|
177
|
+
# @return [Array<HamlLint::Tree::Node>]
|
178
|
+
def subsequents(node)
|
179
|
+
siblings[(position(node) + 1)..-1]
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
# The set of siblings within the tree.
|
185
|
+
#
|
186
|
+
# @api private
|
187
|
+
# @return [Array<HamlLint::Tree::Node>]
|
188
|
+
alias siblings __getobj__
|
189
|
+
|
190
|
+
# Finds the position of a node within a set of siblings.
|
191
|
+
#
|
192
|
+
# @api private
|
193
|
+
# @return [Integer, nil]
|
194
|
+
def position(node)
|
195
|
+
siblings.index(node)
|
196
|
+
end
|
197
|
+
end
|
98
198
|
end
|
99
199
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HamlLint::Tree
|
2
|
+
# A null object version of a node that can be used as a safe default.
|
3
|
+
class NullNode < Node
|
4
|
+
# Instantiates a new {HamlLint::Tree::NullNode}, ignoring all input.
|
5
|
+
def initialize(*_args); end
|
6
|
+
|
7
|
+
# Overrides the disabled check to always say the linter is enabled.
|
8
|
+
#
|
9
|
+
# @param _linter [HamlLint::Linter] the linter to check
|
10
|
+
# @return [false]
|
11
|
+
def disabled?(_linter)
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,5 +1,21 @@
|
|
1
|
+
require 'haml_lint/tree/null_node'
|
2
|
+
|
1
3
|
module HamlLint::Tree
|
2
4
|
# Represents the root node of a HAML document that contains all other nodes.
|
3
5
|
class RootNode < Node
|
6
|
+
# The name fo the file parsed to build this tree.
|
7
|
+
#
|
8
|
+
# @return [String] a file name
|
9
|
+
def file
|
10
|
+
@document.file
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets the node of the syntax tree for a given line number.
|
14
|
+
#
|
15
|
+
# @param line [Integer] the line number of the node
|
16
|
+
# @return [HamlLint::Node]
|
17
|
+
def node_for_line(line)
|
18
|
+
find(HamlLint::Tree::NullNode) { |node| node.line == line }
|
19
|
+
end
|
4
20
|
end
|
5
21
|
end
|
@@ -1,6 +1,15 @@
|
|
1
|
+
require 'haml_lint/parsed_ruby'
|
2
|
+
|
1
3
|
module HamlLint::Tree
|
2
4
|
# Represents a node which produces output based on Ruby code.
|
3
5
|
class ScriptNode < Node
|
6
|
+
# The Ruby script contents parsed into a syntax tree.
|
7
|
+
#
|
8
|
+
# @return [ParsedRuby] syntax tree in the form returned by Parser gem
|
9
|
+
def parsed_script
|
10
|
+
HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(script))
|
11
|
+
end
|
12
|
+
|
4
13
|
# Returns the source for the script following the `-` marker.
|
5
14
|
#
|
6
15
|
# @return [String]
|
@@ -2,6 +2,13 @@ module HamlLint::Tree
|
|
2
2
|
# Represents a HAML silent script node (`- some_expression`) which executes
|
3
3
|
# code without producing output.
|
4
4
|
class SilentScriptNode < Node
|
5
|
+
# The Ruby script contents parsed into a syntax tree.
|
6
|
+
#
|
7
|
+
# @return [ParsedRuby] syntax tree in the form returned by Parser gem
|
8
|
+
def parsed_script
|
9
|
+
HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(script))
|
10
|
+
end
|
11
|
+
|
5
12
|
# Returns the source for the script following the `-` marker.
|
6
13
|
#
|
7
14
|
# @return [String]
|
@@ -148,6 +148,13 @@ module HamlLint::Tree
|
|
148
148
|
dynamic_attributes_source[:html][/\A\((.*)\)\z/, 1] if html_attributes?
|
149
149
|
end
|
150
150
|
|
151
|
+
# ID of the HTML tag.
|
152
|
+
#
|
153
|
+
# @return [String]
|
154
|
+
def tag_id
|
155
|
+
@value[:attributes]['id']
|
156
|
+
end
|
157
|
+
|
151
158
|
# Name of the HTML tag.
|
152
159
|
#
|
153
160
|
# @return [String]
|
@@ -173,6 +180,20 @@ module HamlLint::Tree
|
|
173
180
|
@value[:object_ref][/\A\[(.*)\]\z/, 1] if object_reference?
|
174
181
|
end
|
175
182
|
|
183
|
+
# The attributes given to the tag parsed into a Ruby syntax tree.
|
184
|
+
#
|
185
|
+
# @return [ParsedRuby] syntax tree in the form returned by Parser gem
|
186
|
+
def parsed_attributes
|
187
|
+
HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(hash_attributes_source || ''))
|
188
|
+
end
|
189
|
+
|
190
|
+
# The Ruby script contents of a tag parsed into a syntax tree.
|
191
|
+
#
|
192
|
+
# @return [ParsedRuby] syntax tree in the form returned by Parser gem
|
193
|
+
def parsed_script
|
194
|
+
HamlLint::ParsedRuby.new(HamlLint::RubyParser.new.parse(script || ''))
|
195
|
+
end
|
196
|
+
|
176
197
|
# Whether this node had a `<` after it signifying that outer whitespace
|
177
198
|
# should be removed.
|
178
199
|
#
|
@@ -184,9 +205,11 @@ module HamlLint::Tree
|
|
184
205
|
# Whether this node had a `>` after it signifying that outer whitespace
|
185
206
|
# should be removed.
|
186
207
|
#
|
208
|
+
# rubocop:disable Style/DoubleNegation
|
209
|
+
#
|
187
210
|
# @return [true,false]
|
188
211
|
def remove_outer_whitespace?
|
189
|
-
|
212
|
+
!!@value[:nuke_outer_whitespace]
|
190
213
|
end
|
191
214
|
|
192
215
|
# Returns the script source that will be evaluated to produce this tag's
|
@@ -199,10 +222,6 @@ module HamlLint::Tree
|
|
199
222
|
|
200
223
|
private
|
201
224
|
|
202
|
-
def parsed_attributes
|
203
|
-
HamlLint::RubyParser.new.parse(hash_attributes_source)
|
204
|
-
end
|
205
|
-
|
206
225
|
def existing_attributes
|
207
226
|
parsed_attributes.children.collect do |parsed_attribute|
|
208
227
|
parsed_attribute.children.first.to_a.first
|
data/lib/haml_lint/version.rb
CHANGED
data/lib/haml_lint.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brigade Engineering
|
@@ -9,22 +9,42 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: haml
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '4.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '5.1'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- - "
|
28
|
+
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '4.0'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.1'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rainbow
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
28
48
|
- !ruby/object:Gem::Dependency
|
29
49
|
name: rake
|
30
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,16 +105,22 @@ files:
|
|
85
105
|
- bin/haml-lint
|
86
106
|
- config/default.yml
|
87
107
|
- lib/haml_lint.rb
|
108
|
+
- lib/haml_lint/adapter.rb
|
109
|
+
- lib/haml_lint/adapter/haml_4.rb
|
110
|
+
- lib/haml_lint/adapter/haml_5.rb
|
88
111
|
- lib/haml_lint/cli.rb
|
112
|
+
- lib/haml_lint/comment_configuration.rb
|
89
113
|
- lib/haml_lint/configuration.rb
|
90
114
|
- lib/haml_lint/configuration_loader.rb
|
91
115
|
- lib/haml_lint/constants.rb
|
116
|
+
- lib/haml_lint/directive.rb
|
92
117
|
- lib/haml_lint/document.rb
|
93
118
|
- lib/haml_lint/exceptions.rb
|
94
119
|
- lib/haml_lint/file_finder.rb
|
95
120
|
- lib/haml_lint/haml_visitor.rb
|
96
121
|
- lib/haml_lint/lint.rb
|
97
122
|
- lib/haml_lint/linter.rb
|
123
|
+
- lib/haml_lint/linter/alignment_tabs.rb
|
98
124
|
- lib/haml_lint/linter/alt_text.rb
|
99
125
|
- lib/haml_lint/linter/class_attribute_with_static_value.rb
|
100
126
|
- lib/haml_lint/linter/classes_before_ids.rb
|
@@ -104,17 +130,21 @@ files:
|
|
104
130
|
- lib/haml_lint/linter/empty_script.rb
|
105
131
|
- lib/haml_lint/linter/final_newline.rb
|
106
132
|
- lib/haml_lint/linter/html_attributes.rb
|
133
|
+
- lib/haml_lint/linter/id_names.rb
|
107
134
|
- lib/haml_lint/linter/implicit_div.rb
|
108
135
|
- lib/haml_lint/linter/indentation.rb
|
136
|
+
- lib/haml_lint/linter/instance_variables.rb
|
109
137
|
- lib/haml_lint/linter/leading_comment_space.rb
|
110
138
|
- lib/haml_lint/linter/line_length.rb
|
111
139
|
- lib/haml_lint/linter/multiline_pipe.rb
|
112
140
|
- lib/haml_lint/linter/multiline_script.rb
|
113
141
|
- lib/haml_lint/linter/object_reference_attributes.rb
|
142
|
+
- lib/haml_lint/linter/repeated_id.rb
|
114
143
|
- lib/haml_lint/linter/rubocop.rb
|
115
144
|
- lib/haml_lint/linter/ruby_comments.rb
|
116
145
|
- lib/haml_lint/linter/space_before_script.rb
|
117
146
|
- lib/haml_lint/linter/space_inside_hash_attributes.rb
|
147
|
+
- lib/haml_lint/linter/syntax.rb
|
118
148
|
- lib/haml_lint/linter/tag_name.rb
|
119
149
|
- lib/haml_lint/linter/trailing_whitespace.rb
|
120
150
|
- lib/haml_lint/linter/unnecessary_interpolation.rb
|
@@ -124,20 +154,27 @@ files:
|
|
124
154
|
- lib/haml_lint/logger.rb
|
125
155
|
- lib/haml_lint/node_transformer.rb
|
126
156
|
- lib/haml_lint/options.rb
|
157
|
+
- lib/haml_lint/parsed_ruby.rb
|
127
158
|
- lib/haml_lint/rake_task.rb
|
128
159
|
- lib/haml_lint/report.rb
|
129
160
|
- lib/haml_lint/reporter.rb
|
130
161
|
- lib/haml_lint/reporter/checkstyle_reporter.rb
|
131
162
|
- lib/haml_lint/reporter/default_reporter.rb
|
163
|
+
- lib/haml_lint/reporter/hash_reporter.rb
|
164
|
+
- lib/haml_lint/reporter/hooks.rb
|
132
165
|
- lib/haml_lint/reporter/json_reporter.rb
|
166
|
+
- lib/haml_lint/reporter/progress_reporter.rb
|
167
|
+
- lib/haml_lint/reporter/utils.rb
|
133
168
|
- lib/haml_lint/ruby_extractor.rb
|
134
169
|
- lib/haml_lint/ruby_parser.rb
|
135
170
|
- lib/haml_lint/runner.rb
|
171
|
+
- lib/haml_lint/severity.rb
|
136
172
|
- lib/haml_lint/tree/comment_node.rb
|
137
173
|
- lib/haml_lint/tree/doctype_node.rb
|
138
174
|
- lib/haml_lint/tree/filter_node.rb
|
139
175
|
- lib/haml_lint/tree/haml_comment_node.rb
|
140
176
|
- lib/haml_lint/tree/node.rb
|
177
|
+
- lib/haml_lint/tree/null_node.rb
|
141
178
|
- lib/haml_lint/tree/plain_node.rb
|
142
179
|
- lib/haml_lint/tree/root_node.rb
|
143
180
|
- lib/haml_lint/tree/script_node.rb
|