haml_lint 0.46.0 → 0.47.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b477cda9580216bbcc7434f0673bd4e8b36fa53cc22695cce4b25d5082921b5f
4
- data.tar.gz: 8d404a3975a3def789672a4629b4bddb38a7b110083a731b801329369fae773b
3
+ metadata.gz: e7a818da3ed1d58db0ad35b864c6c90d8036173109f6609da452da8b496dd1d5
4
+ data.tar.gz: ca045650d3373d2fa48d840c684c14b3d46a497f39e91eb9058b1827f3bd74b7
5
5
  SHA512:
6
- metadata.gz: 3e5a3e1b34815a356db1eb4ac1f10ca00e7d083a46f7b69cd8d3223ba6785d34eb628737ebd14d1b9867141bec328385794e329e096452df2b8c2868d42c4801
7
- data.tar.gz: 2f27a33785a9f920359767524ab741bcc1edfaf8e52f3b469e264747e7ecf9f5861db308d33efc074634763889c499c187faa0ce8d455eee5618dfa6323d9f5b
6
+ metadata.gz: 0e2d83720d795e4589d534087c4db2be681eeae95cecda6432917345dea5e4c59e8ba7d65633fb2d4cd0ea86eafc0ea89b8fc51f994cc0b7973a50b0fa0a0abd
7
+ data.tar.gz: 11fc0ea04b7dae506bb0e264d204bdcdcaa96a65230ade8416ae56094a46f95deb3a1006200919804769dcc1c7adf7ab407bbfdf863355248eea9b0e7858308a
@@ -45,6 +45,21 @@ Layout/EndAlignment:
45
45
  Layout/EndOfLine:
46
46
  Enabled: false
47
47
 
48
+ # Turning this cop on can turn
49
+ # = content_tag(:span) do
50
+ # - foo
51
+ # - bar
52
+ #
53
+ # Into
54
+ # - HL.out =
55
+ # - content_tag(:span) do
56
+ # - foo
57
+ # - bar
58
+ #
59
+ # Which is wrong... It would take too much analysis to detect and fix that situation.
60
+ Layout/MultilineAssignmentLayout:
61
+ Enabled: false
62
+
48
63
  Layout/ParameterAlignment:
49
64
  # The alternative, with_fixed_indentation, breaks because we sometimes remove indentation when
50
65
  # dealing with multi-line scripts. (Because a line starting with "=" adds a "HL.out = " to the
@@ -52,11 +52,6 @@ module HamlLint
52
52
  return
53
53
  end
54
54
 
55
- user_config_path = ENV['HAML_LINT_RUBOCOP_CONF'] || config['config_file']
56
- user_config_path ||= self.class.rubocop_config_store.user_rubocop_config_path_for(document.file)
57
- user_config_path = File.absolute_path(user_config_path)
58
- @rubocop_config = self.class.rubocop_config_store.config_object_pointing_to(user_config_path)
59
-
60
55
  @last_extracted_source = nil
61
56
  @last_new_ruby_source = nil
62
57
 
@@ -102,6 +97,13 @@ module HamlLint
102
97
 
103
98
  private
104
99
 
100
+ def rubocop_config_for(path)
101
+ user_config_path = ENV['HAML_LINT_RUBOCOP_CONF'] || config['config_file']
102
+ user_config_path ||= self.class.rubocop_config_store.user_rubocop_config_path_for(path)
103
+ user_config_path = File.absolute_path(user_config_path)
104
+ self.class.rubocop_config_store.config_object_pointing_to(user_config_path)
105
+ end
106
+
105
107
  # Extracted here so that tests can stub this to always return true
106
108
  def transfer_corrections?(initial_ruby_code, new_ruby_code)
107
109
  initial_ruby_code != new_ruby_code
@@ -205,7 +207,7 @@ module HamlLint
205
207
  def run_rubocop(rubocop_cli, ruby_code, path) # rubocop:disable Metrics
206
208
  rubocop_status = nil
207
209
  stdout_str, stderr_str = HamlLint::Utils.with_captured_streams(ruby_code) do
208
- rubocop_cli.config_store.instance_variable_set(:@options_config, @rubocop_config)
210
+ rubocop_cli.config_store.instance_variable_set(:@options_config, rubocop_config_for(path))
209
211
  rubocop_status = rubocop_cli.run(rubocop_flags + ['--stdin', path])
210
212
  end
211
213
 
@@ -332,7 +334,7 @@ module HamlLint
332
334
  # anymore or don't exist yet.
333
335
  # This is not exhaustive, it's only for the cops that are in config/default.yml
334
336
  def ignored_cops_flags
335
- ignored_cops = config['ignored_cops']
337
+ ignored_cops = config.fetch('ignored_cops', [])
336
338
 
337
339
  if @autocorrect
338
340
  ignored_cops += self.class.cops_names_not_supporting_autocorrect
@@ -112,8 +112,11 @@ module HamlLint
112
112
  #
113
113
  # @return [AST::Node]
114
114
  def parse_ruby(source)
115
+ self.class.ruby_parser.parse(source)
116
+ end
117
+
118
+ def self.ruby_parser # rubocop:disable Lint/IneffectiveAccessModifier
115
119
  @ruby_parser ||= HamlLint::RubyParser.new
116
- @ruby_parser.parse(source)
117
120
  end
118
121
 
119
122
  # Remove the surrounding double quotes from a string, ignoring any
@@ -16,5 +16,9 @@ module HamlLint::RubyExtraction
16
16
  end
17
17
 
18
18
  def transfer_correction(coordinator, all_corrected_ruby_lines, haml_lines); end
19
+
20
+ def skip_line_indexes_in_source_map
21
+ (0...@ruby_lines.size).to_a
22
+ end
19
23
  end
20
24
  end
@@ -78,7 +78,8 @@ module HamlLint::RubyExtraction
78
78
  end
79
79
 
80
80
  def haml_end_line_index
81
- @haml_line_index + nb_haml_lines - 1
81
+ # the .max is needed to handle cases with 0 nb_haml_lines
82
+ [@haml_line_index + nb_haml_lines - 1, @haml_line_index].max
82
83
  end
83
84
 
84
85
  def nb_haml_lines
@@ -190,7 +190,7 @@ module HamlLint::RubyExtraction
190
190
  # so the semantics of the extracted ruby would be different from the one generated by
191
191
  # Haml. Those differences can make some cops, such as UselessAssignment, have false
192
192
  # positives
193
- code = 'begin # rubocop:disable Style/RedundantBegin,Lint/RedundantCopDisableDirective'
193
+ code = 'begin'
194
194
  @ruby_chunks << AdHocChunk.new(node,
195
195
  [' ' * indent + code])
196
196
  indent += 2
@@ -204,7 +204,8 @@ module HamlLint::RubyExtraction
204
204
  if has_children
205
205
  yield
206
206
  indent -= 2
207
- @ruby_chunks << AdHocChunk.new(node, [' ' * indent + 'end'],
207
+ @ruby_chunks << AdHocChunk.new(node,
208
+ [' ' * indent + 'ensure', ' ' * indent + ' HL.noop', ' ' * indent + 'end'],
208
209
  haml_line_index: @ruby_chunks.last.haml_end_line_index)
209
210
  end
210
211
  end
@@ -425,6 +426,10 @@ module HamlLint::RubyExtraction
425
426
  regexp = Regexp.new(regexp_code)
426
427
 
427
428
  match = raw_haml.match(regexp)
429
+ # This can happen when pipes are used as marker for multiline parts, and when tag attributes change lines
430
+ # without ending by a comma. This is quite a can of worm and is probably not too frequent, so for now,
431
+ # these cases are not supported.
432
+ return if match.nil?
428
433
 
429
434
  raw_ruby = match[0]
430
435
  ruby_lines = raw_ruby.split("\n")
@@ -32,6 +32,19 @@ module HamlLint
32
32
  false
33
33
  end
34
34
 
35
+ let(:supported_haml?) do |example|
36
+ # Tries to match `{% haml_version >= '5' %}`, extracting the operator and the "number"
37
+ haml_version_regex = /\{%\s*haml_version\s*([^\w\s]+?)\s*['"]?(\d+(\.\d+)*)['"]?\s*%\}/
38
+ requirements = example.metadata[:full_description].scan(haml_version_regex)
39
+
40
+ # This can be used by the requirements in eval
41
+ haml_version = HamlLint::VersionComparer.for_haml
42
+
43
+ requirements.all? do |(operator, version)|
44
+ haml_version.send(operator, version)
45
+ end
46
+ end
47
+
35
48
  before do
36
49
  if stub_rubocop?
37
50
  skip if end_ruby.include?('SKIP')
@@ -92,6 +105,8 @@ module HamlLint
92
105
  # 4) the corrected haml
93
106
  # Each steps is delimited by a line with ---
94
107
  def follows_steps # rubocop:disable Metrics
108
+ skip unless supported_haml?
109
+
95
110
  begin
96
111
  subject.run_or_raise(document, autocorrect: autocorrect)
97
112
  rescue StandardError => e
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.46.0'
5
+ VERSION = '0.47.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.46.0
4
+ version: 0.47.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-06-21 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml