haml_lint 0.44.0 → 0.46.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/bin/haml-lint +1 -1
- data/config/default.yml +6 -28
- data/config/forced_rubocop_config.yml +156 -0
- data/lib/haml_lint/adapter/haml_4.rb +18 -0
- data/lib/haml_lint/adapter/haml_5.rb +11 -0
- data/lib/haml_lint/adapter/haml_6.rb +11 -0
- data/lib/haml_lint/cli.rb +8 -3
- data/lib/haml_lint/configuration_loader.rb +13 -12
- data/lib/haml_lint/document.rb +89 -8
- data/lib/haml_lint/exceptions.rb +6 -0
- data/lib/haml_lint/extensions/haml_util_unescape_interpolation_tracking.rb +35 -0
- data/lib/haml_lint/file_finder.rb +2 -2
- data/lib/haml_lint/lint.rb +10 -1
- data/lib/haml_lint/linter/final_newline.rb +4 -3
- data/lib/haml_lint/linter/implicit_div.rb +1 -1
- data/lib/haml_lint/linter/indentation.rb +3 -3
- data/lib/haml_lint/linter/no_placeholders.rb +18 -0
- data/lib/haml_lint/linter/rubocop.rb +351 -59
- data/lib/haml_lint/linter/space_before_script.rb +8 -10
- data/lib/haml_lint/linter/unnecessary_string_output.rb +1 -1
- data/lib/haml_lint/linter/view_length.rb +1 -1
- data/lib/haml_lint/linter.rb +56 -9
- data/lib/haml_lint/linter_registry.rb +3 -5
- data/lib/haml_lint/logger.rb +2 -2
- data/lib/haml_lint/options.rb +26 -2
- data/lib/haml_lint/rake_task.rb +2 -2
- data/lib/haml_lint/reporter/hash_reporter.rb +1 -3
- data/lib/haml_lint/reporter/offense_count_reporter.rb +1 -1
- data/lib/haml_lint/reporter/utils.rb +33 -4
- data/lib/haml_lint/ruby_extraction/ad_hoc_chunk.rb +20 -0
- data/lib/haml_lint/ruby_extraction/base_chunk.rb +113 -0
- data/lib/haml_lint/ruby_extraction/chunk_extractor.rb +504 -0
- data/lib/haml_lint/ruby_extraction/coordinator.rb +181 -0
- data/lib/haml_lint/ruby_extraction/haml_comment_chunk.rb +54 -0
- data/lib/haml_lint/ruby_extraction/implicit_end_chunk.rb +17 -0
- data/lib/haml_lint/ruby_extraction/interpolation_chunk.rb +26 -0
- data/lib/haml_lint/ruby_extraction/non_ruby_filter_chunk.rb +32 -0
- data/lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb +40 -0
- data/lib/haml_lint/ruby_extraction/ruby_filter_chunk.rb +33 -0
- data/lib/haml_lint/ruby_extraction/ruby_source.rb +5 -0
- data/lib/haml_lint/ruby_extraction/script_chunk.rb +132 -0
- data/lib/haml_lint/ruby_extraction/tag_attributes_chunk.rb +39 -0
- data/lib/haml_lint/ruby_extraction/tag_script_chunk.rb +30 -0
- data/lib/haml_lint/ruby_extractor.rb +11 -10
- data/lib/haml_lint/runner.rb +35 -3
- data/lib/haml_lint/spec/matchers/report_lint.rb +22 -7
- data/lib/haml_lint/spec/normalize_indent.rb +2 -2
- data/lib/haml_lint/spec/shared_linter_context.rb +9 -1
- data/lib/haml_lint/spec/shared_rubocop_autocorrect_context.rb +143 -0
- data/lib/haml_lint/spec.rb +1 -0
- data/lib/haml_lint/tree/filter_node.rb +10 -0
- data/lib/haml_lint/tree/node.rb +13 -4
- data/lib/haml_lint/tree/tag_node.rb +5 -9
- data/lib/haml_lint/utils.rb +130 -5
- data/lib/haml_lint/version.rb +1 -1
- data/lib/haml_lint/version_comparer.rb +25 -0
- data/lib/haml_lint.rb +12 -0
- metadata +25 -6
@@ -0,0 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Makes writing tests for linters a lot DRYer by taking any currently `haml`
|
4
|
+
# variable defined via `let` and normalizing it and running the linter against
|
5
|
+
# it, allowing specs to simply specify whether a lint was reported.
|
6
|
+
|
7
|
+
module HamlLint
|
8
|
+
module Spec
|
9
|
+
module SharedRubocopAutocorrectContext
|
10
|
+
RSpec.shared_context 'rubocop_autocorrect' do
|
11
|
+
# Setting ENV['STUB_RUBOCOP'] to 1 or true makes rubocop tests faster by not involving rubocop.
|
12
|
+
# It is sometimes automatically activated for tests which need a different Rubocop version
|
13
|
+
stub_rubocop_env_result = %w[1 true].include?(ENV['STUB_RUBOCOP'])
|
14
|
+
|
15
|
+
let(:stub_rubocop?) do |example|
|
16
|
+
# Tries to match `{% rubocop_version <= '1.2' %}`, extracting the operator and the "number"
|
17
|
+
rubocop_version_regex = /\{%\s*rubocop_version\s*([^\w\s]+?)\s*['"]?(\d+(\.\d+)*)['"]?\s*%\}/
|
18
|
+
requirements = example.metadata[:full_description].scan(rubocop_version_regex)
|
19
|
+
|
20
|
+
# This can be used by the requirements in eval
|
21
|
+
rubocop_version = HamlLint::VersionComparer.for_rubocop
|
22
|
+
|
23
|
+
accepted = requirements.all? do |(operator, version)|
|
24
|
+
rubocop_version.send(operator, version)
|
25
|
+
end
|
26
|
+
|
27
|
+
next true unless accepted
|
28
|
+
|
29
|
+
# Doing this last so that exceptions in the requirements always fail
|
30
|
+
next true if stub_rubocop_env_result
|
31
|
+
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
if stub_rubocop?
|
37
|
+
skip if end_ruby.include?('SKIP')
|
38
|
+
subject.stub(:process_ruby_source).and_return(end_ruby)
|
39
|
+
end
|
40
|
+
subject.stub(:transfer_corrections?).and_return(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
include_context 'linter'
|
44
|
+
# The goal is not to test rubocop the gem, so no need to test the details using both
|
45
|
+
# :safe and :all
|
46
|
+
let(:autocorrect) { :all }
|
47
|
+
|
48
|
+
# We want want to do error handling ourself
|
49
|
+
let(:run_method_to_use) { nil }
|
50
|
+
|
51
|
+
let(:steps_parts) do
|
52
|
+
parts = steps_string.split(/^[ \t]*---[ \t]*\n/, -1)
|
53
|
+
raise "Expected 4 steps, got: #{parts.size}" if parts.size != 4
|
54
|
+
parts
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:start_haml) { steps_parts[0] }
|
58
|
+
|
59
|
+
let(:start_ruby) do
|
60
|
+
lines = steps_parts[1].split("\n", -1)
|
61
|
+
current_matching_line = 1
|
62
|
+
@source_map = {}
|
63
|
+
lines.each.with_index do |line, i|
|
64
|
+
next unless line =~ /\S/
|
65
|
+
mo = line.match(/^(.*?)\$?\s*\$\$(\d+)$/)
|
66
|
+
if mo
|
67
|
+
lines[i] = mo[1]
|
68
|
+
current_matching_line = Integer(mo[2])
|
69
|
+
end
|
70
|
+
@source_map[i + 1] = current_matching_line
|
71
|
+
end
|
72
|
+
lines.join("\n")
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:source_map) do
|
76
|
+
start_ruby
|
77
|
+
@source_map
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:end_ruby) { steps_parts[2] }
|
81
|
+
|
82
|
+
let(:end_haml) { steps_parts[3] }
|
83
|
+
|
84
|
+
# Used by the 'linter' context
|
85
|
+
let(:haml) { start_haml }
|
86
|
+
|
87
|
+
# steps_string is string of multiple lines describing the steps that
|
88
|
+
# the code will take:
|
89
|
+
# 1) input haml
|
90
|
+
# 2) extracted ruby
|
91
|
+
# 3) the corrected ruby
|
92
|
+
# 4) the corrected haml
|
93
|
+
# Each steps is delimited by a line with ---
|
94
|
+
def follows_steps # rubocop:disable Metrics
|
95
|
+
begin
|
96
|
+
subject.run_or_raise(document, autocorrect: autocorrect)
|
97
|
+
rescue StandardError => e
|
98
|
+
exception_while_running = e
|
99
|
+
end
|
100
|
+
|
101
|
+
syntax_lints = subject.lints.select { |lint| lint.message =~ %r{Lint/Syntax} }
|
102
|
+
|
103
|
+
if start_ruby.strip != 'SKIP' && subject.last_extracted_source
|
104
|
+
matcher = eq(start_ruby)
|
105
|
+
subject.last_extracted_source.source.should(
|
106
|
+
matcher,
|
107
|
+
-> { "Extracted Ruby is different from expected. #{matcher.failure_message}\n#{format_lints}" }
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
syntax_lints.should(be_empty, "Generated Ruby has Syntax Lints:\n#{format_lints(syntax_lints)}")
|
112
|
+
|
113
|
+
if end_ruby.strip != 'SKIP' && subject.last_new_ruby_source
|
114
|
+
matcher = eq(end_ruby)
|
115
|
+
subject.last_new_ruby_source.should(
|
116
|
+
matcher,
|
117
|
+
-> { "Ruby generated by RuboCop is different from expected. #{matcher.failure_message}\n#{format_lints}" }
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
raise exception_while_running if exception_while_running
|
122
|
+
|
123
|
+
matcher = eq(end_haml)
|
124
|
+
document.source.should(
|
125
|
+
matcher,
|
126
|
+
-> { "Final HAML is different from expected. #{matcher.failure_message}\n#{format_lints}" }
|
127
|
+
)
|
128
|
+
|
129
|
+
if subject.last_extracted_source && start_ruby.strip != 'SKIP'
|
130
|
+
subject.last_extracted_source.source_map.should == source_map
|
131
|
+
end
|
132
|
+
|
133
|
+
haml_different = start_haml != end_haml
|
134
|
+
document.source_was_changed.should == haml_different
|
135
|
+
end
|
136
|
+
|
137
|
+
def format_lints(lints = subject.lints)
|
138
|
+
lints.map { |lint| "#{lint.line}:#{lint.message}" }.join("\n")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/lib/haml_lint/spec.rb
CHANGED
@@ -7,5 +7,15 @@ module HamlLint::Tree
|
|
7
7
|
def filter_type
|
8
8
|
@value[:name]
|
9
9
|
end
|
10
|
+
|
11
|
+
def text
|
12
|
+
# Seems HAML strips the starting blank lines... without them, line numbers become offset,
|
13
|
+
# breaking the source_map and auto-correct
|
14
|
+
|
15
|
+
nb_blank_lines = 0
|
16
|
+
nb_blank_lines += 1 while @document.source_lines[line + nb_blank_lines]&.empty?
|
17
|
+
|
18
|
+
"#{"\n" * nb_blank_lines}#{super}"
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
data/lib/haml_lint/tree/node.rb
CHANGED
@@ -104,8 +104,13 @@ module HamlLint::Tree
|
|
104
104
|
def line_numbers
|
105
105
|
return (line..line) unless @value && text
|
106
106
|
|
107
|
-
end_line =
|
108
|
-
|
107
|
+
end_line = if !lines.empty?
|
108
|
+
line + lines.count - 1
|
109
|
+
elsif children.empty?
|
110
|
+
nontrivial_end_line
|
111
|
+
else
|
112
|
+
line
|
113
|
+
end
|
109
114
|
|
110
115
|
(line..end_line)
|
111
116
|
end
|
@@ -155,6 +160,10 @@ module HamlLint::Tree
|
|
155
160
|
@value[:text].to_s
|
156
161
|
end
|
157
162
|
|
163
|
+
def keyword
|
164
|
+
@value[:keyword]
|
165
|
+
end
|
166
|
+
|
158
167
|
private
|
159
168
|
|
160
169
|
# Discovers the end line of the node when there are no lines.
|
@@ -164,7 +173,7 @@ module HamlLint::Tree
|
|
164
173
|
if successor
|
165
174
|
successor.line_numbers.begin - 1
|
166
175
|
else
|
167
|
-
@document.
|
176
|
+
@document.last_non_empty_line
|
168
177
|
end
|
169
178
|
end
|
170
179
|
|
@@ -212,7 +221,7 @@ module HamlLint::Tree
|
|
212
221
|
# @param node [HamlLint::Tree::Node]
|
213
222
|
# @return [Array<HamlLint::Tree::Node>]
|
214
223
|
def subsequents(node)
|
215
|
-
siblings[(position(node) + 1)
|
224
|
+
siblings[(position(node) + 1)..]
|
216
225
|
end
|
217
226
|
|
218
227
|
private
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module HamlLint::Tree
|
4
4
|
# Represents a tag node in a HAML document.
|
5
|
-
class TagNode < Node
|
5
|
+
class TagNode < Node
|
6
6
|
# Computed set of attribute hashes code.
|
7
7
|
#
|
8
8
|
# This is a combination of all dynamically calculated attributes from the
|
@@ -49,9 +49,7 @@ module HamlLint::Tree
|
|
49
49
|
# dot removed
|
50
50
|
def static_classes
|
51
51
|
@static_classes ||=
|
52
|
-
|
53
|
-
static_attributes_source.scan(/\.([-:\w]+)/)
|
54
|
-
end
|
52
|
+
static_attributes_source.scan(/\.([-:\w]+)/)
|
55
53
|
end
|
56
54
|
|
57
55
|
# List of ids statically defined for this tag.
|
@@ -63,9 +61,7 @@ module HamlLint::Tree
|
|
63
61
|
# removed
|
64
62
|
def static_ids
|
65
63
|
@static_ids ||=
|
66
|
-
|
67
|
-
static_attributes_source.scan(/#([-:\w]+)/)
|
68
|
-
end
|
64
|
+
static_attributes_source.scan(/#([-:\w]+)/)
|
69
65
|
end
|
70
66
|
|
71
67
|
# Static element attributes defined after the tag name.
|
@@ -101,7 +97,7 @@ module HamlLint::Tree
|
|
101
97
|
@attributes_source ||=
|
102
98
|
begin
|
103
99
|
_explicit_tag, static_attrs, rest =
|
104
|
-
source_code.scan(/\A\s*(%[-:\w]+)?([-:\w
|
100
|
+
source_code.scan(/\A\s*(%[-:\w]+)?([-:\w.\#]*)(.*)/m)[0]
|
105
101
|
|
106
102
|
attr_types = {
|
107
103
|
'{' => [:hash, %w[{ }]],
|
@@ -220,7 +216,7 @@ module HamlLint::Tree
|
|
220
216
|
#
|
221
217
|
# @return [true,false]
|
222
218
|
def remove_outer_whitespace?
|
223
|
-
!!@value[:nuke_outer_whitespace]
|
219
|
+
!!@value[:nuke_outer_whitespace]
|
224
220
|
end
|
225
221
|
|
226
222
|
# Returns the script source that will be evaluated to produce this tag's
|
data/lib/haml_lint/utils.rb
CHANGED
@@ -4,7 +4,7 @@ require 'pathname'
|
|
4
4
|
|
5
5
|
module HamlLint
|
6
6
|
# A miscellaneous set of utility functions.
|
7
|
-
module Utils
|
7
|
+
module Utils # rubocop:disable Metrics/ModuleLength
|
8
8
|
module_function
|
9
9
|
|
10
10
|
# Returns whether a glob pattern (or any of a list of patterns) matches the
|
@@ -52,12 +52,21 @@ module HamlLint
|
|
52
52
|
# the text.
|
53
53
|
# @yieldparam interpolated_code [String] code that was interpolated
|
54
54
|
# @yieldparam line [Integer] line number code appears on in text
|
55
|
-
def extract_interpolated_values(text)
|
55
|
+
def extract_interpolated_values(text) # rubocop:disable Metrics/AbcSize
|
56
56
|
dumped_text = text.dump
|
57
|
-
|
57
|
+
|
58
|
+
# Basically, match pairs of '\' and '\ followed by the letter 'n'
|
59
|
+
quoted_regex_s = "(#{Regexp.quote('\\\\')}|#{Regexp.quote('\\n')})"
|
60
|
+
newline_positions = extract_substring_positions(dumped_text, quoted_regex_s)
|
61
|
+
|
62
|
+
# Filter the matches to only keep those ending in 'n'.
|
63
|
+
# This way, escaped \n will not be considered
|
64
|
+
newline_positions.select! do |pos|
|
65
|
+
dumped_text[pos - 1] == 'n'
|
66
|
+
end
|
58
67
|
|
59
68
|
Haml::Util.handle_interpolation(dumped_text) do |scan|
|
60
|
-
line = (newline_positions.find_index { |marker| scan.
|
69
|
+
line = (newline_positions.find_index { |marker| scan.charpos <= marker } ||
|
61
70
|
newline_positions.size) + 1
|
62
71
|
|
63
72
|
escape_count = (scan[2].size - 1) / 2
|
@@ -70,6 +79,41 @@ module HamlLint
|
|
70
79
|
end
|
71
80
|
end
|
72
81
|
|
82
|
+
def handle_interpolation_with_indexes(text)
|
83
|
+
newline_indexes = extract_substring_positions(text, "\n")
|
84
|
+
|
85
|
+
handle_interpolation_with_newline(text) do |scan|
|
86
|
+
line_index = newline_indexes.find_index { |index| scan.charpos <= index }
|
87
|
+
line_index ||= newline_indexes.size
|
88
|
+
|
89
|
+
line_start_char_index = if line_index == 0
|
90
|
+
0
|
91
|
+
else
|
92
|
+
newline_indexes[line_index - 1]
|
93
|
+
end
|
94
|
+
|
95
|
+
char_index = scan.charpos - line_start_char_index
|
96
|
+
|
97
|
+
yield scan, line_index, char_index
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
if Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5')
|
102
|
+
# Same as Haml::Util.handle_interpolation, but enables multiline mode on the regex
|
103
|
+
def handle_interpolation_with_newline(str)
|
104
|
+
scan = StringScanner.new(str)
|
105
|
+
yield scan while scan.scan(/(.*?)(\\*)#([{@$])/m)
|
106
|
+
scan.rest
|
107
|
+
end
|
108
|
+
else
|
109
|
+
# Same as Haml::Util.handle_interpolation, but enables multiline mode on the regex
|
110
|
+
def handle_interpolation_with_newline(str)
|
111
|
+
scan = StringScanner.new(str)
|
112
|
+
yield scan while scan.scan(/(.*?)(\\*)\#\{/m)
|
113
|
+
scan.rest
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
73
117
|
# Returns indexes of all occurrences of a substring within a string.
|
74
118
|
#
|
75
119
|
# Note, this will not return overlaping substrings, so searching for "aa"
|
@@ -81,7 +125,7 @@ module HamlLint
|
|
81
125
|
def extract_substring_positions(text, substr)
|
82
126
|
positions = []
|
83
127
|
scanner = StringScanner.new(text)
|
84
|
-
positions << scanner.
|
128
|
+
positions << scanner.charpos while scanner.scan(/(.*?)#{substr}/)
|
85
129
|
positions
|
86
130
|
end
|
87
131
|
|
@@ -136,6 +180,22 @@ module HamlLint
|
|
136
180
|
count
|
137
181
|
end
|
138
182
|
|
183
|
+
# Process ERB, providing some values for for versions to it
|
184
|
+
#
|
185
|
+
# @param content [String] the (usually yaml) content to process
|
186
|
+
# @return [String]
|
187
|
+
def process_erb(content)
|
188
|
+
# Variables for use in the ERB's post-processing
|
189
|
+
rubocop_version = HamlLint::VersionComparer.for_rubocop
|
190
|
+
|
191
|
+
ERB.new(content).result(binding)
|
192
|
+
end
|
193
|
+
|
194
|
+
def insert_after_indentation(code, insert)
|
195
|
+
index = code.index(/\S/)
|
196
|
+
"#{code[0...index]}#{insert}#{code[index..]}"
|
197
|
+
end
|
198
|
+
|
139
199
|
# Calls a block of code with a modified set of environment variables,
|
140
200
|
# restoring them once the code has executed.
|
141
201
|
#
|
@@ -151,5 +211,70 @@ module HamlLint
|
|
151
211
|
ensure
|
152
212
|
old_env.each { |var, value| ENV[var.to_s] = value }
|
153
213
|
end
|
214
|
+
|
215
|
+
def indent(string, nb_indent)
|
216
|
+
if nb_indent < 0
|
217
|
+
string.gsub(/^ {1,#{-nb_indent}}/, '')
|
218
|
+
else
|
219
|
+
string.gsub(/^/, ' ' * nb_indent)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def map_subset!(array, range, &block)
|
224
|
+
subset = array[range]
|
225
|
+
return if subset.nil? || subset.empty?
|
226
|
+
|
227
|
+
array[range] = subset.map(&block)
|
228
|
+
end
|
229
|
+
|
230
|
+
def map_after_first!(array, &block)
|
231
|
+
map_subset!(array, 1..-1, &block)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Returns true if line is only whitespace.
|
235
|
+
# Note, this is not like blank? is rails. For nil, this returns false.
|
236
|
+
def is_blank_line?(line)
|
237
|
+
line && line.index(/\S/).nil?
|
238
|
+
end
|
239
|
+
|
240
|
+
def check_error_when_compiling_haml(haml_string)
|
241
|
+
begin
|
242
|
+
ruby_code = ::HamlLint::Adapter.detect_class.new(haml_string).precompile
|
243
|
+
rescue StandardError => e
|
244
|
+
return e
|
245
|
+
end
|
246
|
+
eval("BEGIN {return nil}; #{ruby_code}", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
|
247
|
+
# The eval will return nil
|
248
|
+
rescue ::SyntaxError
|
249
|
+
$!
|
250
|
+
end
|
251
|
+
|
252
|
+
# Overrides the global stdin, stdout and stderr while within the block, to
|
253
|
+
# push a string in stdin, and capture both stdout and stderr which are returned.
|
254
|
+
#
|
255
|
+
# @param stdin_str [String] the string to push in as stdin
|
256
|
+
# @param _block [Block] the block to perform with the overridden std streams
|
257
|
+
# @return [String, String]
|
258
|
+
def with_captured_streams(stdin_str, &_block)
|
259
|
+
original_stdin = $stdin
|
260
|
+
# The dup is needed so that stdin_data isn't altered (encoding-wise at least)
|
261
|
+
$stdin = StringIO.new(stdin_str.dup)
|
262
|
+
begin
|
263
|
+
original_stdout = $stdout
|
264
|
+
$stdout = StringIO.new
|
265
|
+
begin
|
266
|
+
original_stderr = $stderr
|
267
|
+
$stderr = StringIO.new
|
268
|
+
yield
|
269
|
+
[$stdout.string, $stderr.string]
|
270
|
+
ensure
|
271
|
+
$stderr = original_stderr
|
272
|
+
end
|
273
|
+
ensure
|
274
|
+
$stdout = original_stdout
|
275
|
+
end
|
276
|
+
ensure
|
277
|
+
$stdin = original_stdin
|
278
|
+
end
|
154
279
|
end
|
155
280
|
end
|
data/lib/haml_lint/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HamlLint
|
4
|
+
# A simple wrapper around Gem::Version to allow comparison with String instances
|
5
|
+
# This makes code shorter in some places
|
6
|
+
class VersionComparer
|
7
|
+
def initialize(version)
|
8
|
+
@version = Gem::Version.new(version)
|
9
|
+
end
|
10
|
+
|
11
|
+
include Comparable
|
12
|
+
def <=>(other)
|
13
|
+
@version <=> Gem::Version.new(other)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Shortcut to create a version comparer for the current RuboCop's version
|
17
|
+
def self.for_rubocop
|
18
|
+
new(RuboCop::Version::STRING)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.for_haml
|
22
|
+
new(Haml::VERSION)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/haml_lint.rb
CHANGED
@@ -21,8 +21,14 @@ require 'haml_lint/file_finder'
|
|
21
21
|
require 'haml_lint/runner'
|
22
22
|
require 'haml_lint/utils'
|
23
23
|
require 'haml_lint/version'
|
24
|
+
require 'haml_lint/version_comparer'
|
24
25
|
require 'haml_lint/severity'
|
25
26
|
|
27
|
+
# Lead all extensions to external source code
|
28
|
+
Dir[File.expand_path('haml_lint/extensions/*.rb', File.dirname(__FILE__))].sort.each do |file|
|
29
|
+
require file
|
30
|
+
end
|
31
|
+
|
26
32
|
# Load all parse tree node classes
|
27
33
|
require 'haml_lint/tree/node'
|
28
34
|
require 'haml_lint/node_transformer'
|
@@ -39,3 +45,9 @@ end
|
|
39
45
|
Dir[File.expand_path('haml_lint/reporter/*.rb', File.dirname(__FILE__))].sort.each do |file|
|
40
46
|
require file
|
41
47
|
end
|
48
|
+
|
49
|
+
# Load all the chunks for RubyExtraction
|
50
|
+
require 'haml_lint/ruby_extraction/base_chunk'
|
51
|
+
Dir[File.expand_path('haml_lint/ruby_extraction/*.rb', File.dirname(__FILE__))].sort.each do |file|
|
52
|
+
require file
|
53
|
+
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.
|
4
|
+
version: 0.46.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-
|
11
|
+
date: 2023-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -64,14 +64,14 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: '1.0'
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
74
|
+
version: '1.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: sysexits
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,6 +96,7 @@ extra_rdoc_files: []
|
|
96
96
|
files:
|
97
97
|
- bin/haml-lint
|
98
98
|
- config/default.yml
|
99
|
+
- config/forced_rubocop_config.yml
|
99
100
|
- lib/haml_lint.rb
|
100
101
|
- lib/haml_lint/adapter.rb
|
101
102
|
- lib/haml_lint/adapter/haml_4.rb
|
@@ -109,6 +110,7 @@ files:
|
|
109
110
|
- lib/haml_lint/directive.rb
|
110
111
|
- lib/haml_lint/document.rb
|
111
112
|
- lib/haml_lint/exceptions.rb
|
113
|
+
- lib/haml_lint/extensions/haml_util_unescape_interpolation_tracking.rb
|
112
114
|
- lib/haml_lint/file_finder.rb
|
113
115
|
- lib/haml_lint/haml_visitor.rb
|
114
116
|
- lib/haml_lint/lint.rb
|
@@ -132,6 +134,7 @@ files:
|
|
132
134
|
- lib/haml_lint/linter/line_length.rb
|
133
135
|
- lib/haml_lint/linter/multiline_pipe.rb
|
134
136
|
- lib/haml_lint/linter/multiline_script.rb
|
137
|
+
- lib/haml_lint/linter/no_placeholders.rb
|
135
138
|
- lib/haml_lint/linter/object_reference_attributes.rb
|
136
139
|
- lib/haml_lint/linter/repeated_id.rb
|
137
140
|
- lib/haml_lint/linter/rubocop.rb
|
@@ -162,6 +165,20 @@ files:
|
|
162
165
|
- lib/haml_lint/reporter/offense_count_reporter.rb
|
163
166
|
- lib/haml_lint/reporter/progress_reporter.rb
|
164
167
|
- lib/haml_lint/reporter/utils.rb
|
168
|
+
- lib/haml_lint/ruby_extraction/ad_hoc_chunk.rb
|
169
|
+
- lib/haml_lint/ruby_extraction/base_chunk.rb
|
170
|
+
- lib/haml_lint/ruby_extraction/chunk_extractor.rb
|
171
|
+
- lib/haml_lint/ruby_extraction/coordinator.rb
|
172
|
+
- lib/haml_lint/ruby_extraction/haml_comment_chunk.rb
|
173
|
+
- lib/haml_lint/ruby_extraction/implicit_end_chunk.rb
|
174
|
+
- lib/haml_lint/ruby_extraction/interpolation_chunk.rb
|
175
|
+
- lib/haml_lint/ruby_extraction/non_ruby_filter_chunk.rb
|
176
|
+
- lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb
|
177
|
+
- lib/haml_lint/ruby_extraction/ruby_filter_chunk.rb
|
178
|
+
- lib/haml_lint/ruby_extraction/ruby_source.rb
|
179
|
+
- lib/haml_lint/ruby_extraction/script_chunk.rb
|
180
|
+
- lib/haml_lint/ruby_extraction/tag_attributes_chunk.rb
|
181
|
+
- lib/haml_lint/ruby_extraction/tag_script_chunk.rb
|
165
182
|
- lib/haml_lint/ruby_extractor.rb
|
166
183
|
- lib/haml_lint/ruby_parser.rb
|
167
184
|
- lib/haml_lint/runner.rb
|
@@ -170,6 +187,7 @@ files:
|
|
170
187
|
- lib/haml_lint/spec/matchers/report_lint.rb
|
171
188
|
- lib/haml_lint/spec/normalize_indent.rb
|
172
189
|
- lib/haml_lint/spec/shared_linter_context.rb
|
190
|
+
- lib/haml_lint/spec/shared_rubocop_autocorrect_context.rb
|
173
191
|
- lib/haml_lint/tree/comment_node.rb
|
174
192
|
- lib/haml_lint/tree/doctype_node.rb
|
175
193
|
- lib/haml_lint/tree/filter_node.rb
|
@@ -183,6 +201,7 @@ files:
|
|
183
201
|
- lib/haml_lint/tree/tag_node.rb
|
184
202
|
- lib/haml_lint/utils.rb
|
185
203
|
- lib/haml_lint/version.rb
|
204
|
+
- lib/haml_lint/version_comparer.rb
|
186
205
|
homepage: https://github.com/sds/haml-lint
|
187
206
|
licenses:
|
188
207
|
- MIT
|
@@ -195,14 +214,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
214
|
requirements:
|
196
215
|
- - ">="
|
197
216
|
- !ruby/object:Gem::Version
|
198
|
-
version: 2.
|
217
|
+
version: 2.6.0
|
199
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
219
|
requirements:
|
201
220
|
- - ">="
|
202
221
|
- !ruby/object:Gem::Version
|
203
222
|
version: '0'
|
204
223
|
requirements: []
|
205
|
-
rubygems_version: 3.1
|
224
|
+
rubygems_version: 3.0.3.1
|
206
225
|
signing_key:
|
207
226
|
specification_version: 4
|
208
227
|
summary: HAML lint tool
|