haml_lint 0.69.0 → 0.70.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: 43c9ee2b963d529fd6fac9ac7da3b0c8250ce9127780a695e3d9019e172d55c4
4
- data.tar.gz: 4cbddbf3128a6ab2430e21b02f119ba7c58bbb576a9a73556ad6c9ef269926f5
3
+ metadata.gz: 7b1a2ca29afbb8764cf0932d560901cd9b2af889701386bf398a464b94d331bc
4
+ data.tar.gz: 82e6c7e54a0bd3c1d8f4159893af0bfb0c16c81dca993a9aaf6e875544d79269
5
5
  SHA512:
6
- metadata.gz: d28e0a5dc9d957b5b1101e5378d45c6eddcf91257907933990050323fb36c960123255c9c5b8a9563ce78b1dd5cd0d74c35499954bed9098335887c5e10b0568
7
- data.tar.gz: 51d29f51cec99314e3b98aa620ee7754f924d3c224eeabe8fa8ce9d0cbb968759161feb29e496dd6716e84e732780375cf43e04e5b045a31180d5d493e5ed44c
6
+ metadata.gz: 754e6ad2de8723a619eb4b24204e8231fead3443c35080c073fbc8e68a15cadace16eb5635c86bea78eee28831de1ef4ba8afadc4e22156f4c6edd6155df42b7
7
+ data.tar.gz: f533a65a21402e75970431c7e82b7b82f111b12d584568b8fd38ff25fd21d258c76e81d562c7b23d439fe1055f01f95897fbc1bc787cc599b8430baa30260857
@@ -94,7 +94,7 @@ module HamlLint
94
94
  @last_extracted_source = nil
95
95
  @last_new_ruby_source = nil
96
96
 
97
- coordinator = HamlLint::RubyExtraction::Coordinator.new(document)
97
+ coordinator = HamlLint::RubyExtraction::Coordinator.new(document, autocorrect: @autocorrect)
98
98
 
99
99
  extracted_source = coordinator.extract_ruby_source
100
100
  if ENV['HAML_LINT_INTERNAL_DEBUG'] == 'true'
@@ -9,7 +9,7 @@ module HamlLint::RubyExtraction
9
9
  class ChunkExtractor
10
10
  include HamlLint::HamlVisitor
11
11
 
12
- attr_reader :script_output_prefix
12
+ attr_reader :script_output_prefix, :autocorrect
13
13
 
14
14
  HAML_PARSER_INSTANCE = if Haml::VERSION >= '5.0.0'
15
15
  ::Haml::Parser.new({})
@@ -21,9 +21,10 @@ module HamlLint::RubyExtraction
21
21
  # We don't. So the regex must be fixed to correctly detect the start of the string.
22
22
  BLOCK_KEYWORD_REGEX = Regexp.new(Haml::Parser::BLOCK_KEYWORD_REGEX.source.sub('^', '\A'))
23
23
 
24
- def initialize(document, script_output_prefix:)
24
+ def initialize(document, script_output_prefix:, autocorrect: nil)
25
25
  @document = document
26
26
  @script_output_prefix = script_output_prefix
27
+ @autocorrect = autocorrect
27
28
  end
28
29
 
29
30
  def extract
@@ -637,8 +638,20 @@ module HamlLint::RubyExtraction
637
638
  def wrap_lines(lines, wrap_depth)
638
639
  lines = lines.dup
639
640
  wrapping_prefix = 'W' * (wrap_depth - 1) + '('
640
- lines[0] = wrapping_prefix + lines[0]
641
- lines[-1] = lines[-1] + ')'
641
+
642
+ # Strip leading/trailing space only when linting (not autocorrecting) to avoid
643
+ # SpaceInsideParens violations. During autocorrect, preserve spaces so RuboCop
644
+ # can fix them and map corrections back correctly.
645
+ if autocorrect
646
+ lines[0] = wrapping_prefix + lines[0]
647
+ lines[-1] = lines[-1] + ')'
648
+ else
649
+ leading_spaces = lines[0][/^\s*/].length
650
+ wrapping_prefix = 'W' * (wrap_depth - 1 + leading_spaces) + '('
651
+ lines[0] = wrapping_prefix + lines[0].lstrip
652
+ lines[-1] = lines[-1].rstrip + ')'
653
+ end
654
+
642
655
  lines
643
656
  end
644
657
 
@@ -28,8 +28,12 @@ module HamlLint::RubyExtraction
28
28
  # @return [Array<String>] The ruby lines after correction by RuboCop
29
29
  attr_reader :corrected_ruby_lines
30
30
 
31
- def initialize(document)
31
+ # @return [Symbol, nil] The autocorrect mode (:safe, :all, or nil)
32
+ attr_reader :autocorrect
33
+
34
+ def initialize(document, autocorrect:)
32
35
  @document = document
36
+ @autocorrect = autocorrect
33
37
  @ruby_chunks = nil
34
38
  @assembled_ruby_lines = nil
35
39
  @corrected_ruby_lines = nil
@@ -46,7 +50,8 @@ module HamlLint::RubyExtraction
46
50
  pick_a_script_output_prefix
47
51
 
48
52
  @ruby_chunks = HamlLint::RubyExtraction::ChunkExtractor.new(@document,
49
- script_output_prefix: @script_output_prefix).extract
53
+ script_output_prefix: @script_output_prefix,
54
+ autocorrect: autocorrect).extract
50
55
  preprocess_chunks
51
56
 
52
57
  @assembled_ruby_lines = []
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.69.0'
5
+ VERSION = '0.70.0'
6
6
  end
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.69.0
4
+ version: 0.70.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva