slim_lint 0.34.0 → 0.35.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: 3586e4fdad857cd9982603d97fd17acca434ef45caabe63ad6df523d1ca7ed76
4
- data.tar.gz: 56bf2830ea686935a7ab26b6128fc4a3aa367ddb0de20a0ed6cbcd3f1b771338
3
+ metadata.gz: e9478570d94e93349a03f9f7a67789f3c0ff356bd8bd95ee7fe5628248eaaab9
4
+ data.tar.gz: 23bc11a5e84b251523397d12bcf0c776d8755373fffbfa7ce183353fe8a86b73
5
5
  SHA512:
6
- metadata.gz: 0b8b60196d99f38fff022cd248b40bfbcd5ce7d0fd82ce2ff8eb3e1e1bdf1a7582537e7d4b2a2c9c9eb7713d0dc6f58a002e029889a11f69d76b7d0b61636d4c
7
- data.tar.gz: 324ef5fbb06bf9b81134ff9fbf698bf02482f66ab0f42f10f2685f06524a6d2b1353310a5c9fe4feb001bffcd541c99036904bc4501f9af9607bf9cf6b68bbdc
6
+ metadata.gz: f40d2b1af0278fd5f2ea727f0a7ee39322df8b7c1ddf155ece528ac7f99c8dd8b0284af8d622e05eec9ef229544fd953b1f6a51cea9e11d35c23bba1d7d7c7c3
7
+ data.tar.gz: 6c96c5b859896bf1a3d04fe1ca336cfae1e7c15bbcb89f5a6143d1b952ec3508febab94dd4fa618fbbed98405bbaed941cd6a94bb3c2e2bad3a1bdc04ddb5574
@@ -11,10 +11,11 @@ module SlimLint
11
11
  on [:html, :tag, anything, [],
12
12
  [:slim, :output, anything, capture(:ruby, anything)]] do |sexp|
13
13
  # Fetch original Slim code that contains an element with a control statement.
14
- line = document.source_lines[sexp.line - 1]
14
+ ruby = captures[:ruby]
15
+ line = source_line_for(sexp, /=[=<>]* *#{Regexp.escape(ruby[/[^\n]*/])}/)
16
+ next unless line
15
17
 
16
18
  # Remove any Ruby code, because our regexp below must not match inside Ruby.
17
- ruby = captures[:ruby]
18
19
  line = line.sub(ruby, 'x')
19
20
 
20
21
  next if line =~ /[^ ] ==?<?>? [^ ]/
@@ -23,11 +24,33 @@ module SlimLint
23
24
  end
24
25
 
25
26
  on [:slim, :control] do |sexp|
26
- line = document.source_lines[sexp.line - 1]
27
+ ruby = sexp[2]
28
+ line = source_line_for(sexp, /- *#{Regexp.escape(ruby[/[^\n]*/])}/)
29
+ next unless line
27
30
 
28
31
  next if line =~ /^ *- [^ ]/
29
32
 
30
33
  report_lint(sexp, MESSAGE_CONTROL)
31
34
  end
35
+
36
+ private
37
+
38
+ # Finds the original Slim source line for the given Sexp.
39
+ #
40
+ # Backslash (`\`) and comma (`,`) line continuations in preceding
41
+ # attributes are collapsed by the Slim parser without emitting a newline,
42
+ # which causes the line number reported for subsequent Sexps to be too low
43
+ # (see https://github.com/sds/slim-lint/issues/201). We compensate by
44
+ # searching forward from the reported line for the line that actually
45
+ # contains the statement, falling back to the reported line otherwise.
46
+ #
47
+ # @param sexp [SlimLint::Sexp]
48
+ # @param pattern [Regexp] matches the source line containing the statement
49
+ # @return [String, nil]
50
+ def source_line_for(sexp, pattern)
51
+ index = sexp.line - 1
52
+ lines = document.source_lines[index..] || []
53
+ lines.find { |line| line =~ pattern } || document.source_lines[index]
54
+ end
32
55
  end
33
56
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.34.0'
5
+ VERSION = '0.35.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  requirements: []
185
- rubygems_version: 3.6.9
185
+ rubygems_version: 4.0.10
186
186
  specification_version: 4
187
187
  summary: Slim template linting tool
188
188
  test_files: []