slim_lint 0.33.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: '08768fa2264ad994c53a3e0f993fa0caa38e300c77ae64d5531e972c440aeaaf'
4
- data.tar.gz: bff84f96661b0c46c2a5445b37da6932b00ee2e2fa56e2ed1e8e76228db98bf5
3
+ metadata.gz: e9478570d94e93349a03f9f7a67789f3c0ff356bd8bd95ee7fe5628248eaaab9
4
+ data.tar.gz: 23bc11a5e84b251523397d12bcf0c776d8755373fffbfa7ce183353fe8a86b73
5
5
  SHA512:
6
- metadata.gz: 763da1e8ccb05a25e7c54813363fa86ad340d387a3dedf1b3a41ef8f0cada1e413861e7159bda4931bbe45150ae11314c79e51233ac054eb9f7684245d8b0091
7
- data.tar.gz: a5eb859a052ff7276ecef9718b4a0952aa8ddc77738313a047c67773ae7b1556e49a051f101e30de92014f26e8e894b1733e30eacbe4b28b452c9ea0124226f5
6
+ metadata.gz: f40d2b1af0278fd5f2ea727f0a7ee39322df8b7c1ddf155ece528ac7f99c8dd8b0284af8d622e05eec9ef229544fd953b1f6a51cea9e11d35c23bba1d7d7c7c3
7
+ data.tar.gz: 6c96c5b859896bf1a3d04fe1ca336cfae1e7c15bbcb89f5a6143d1b952ec3508febab94dd4fa618fbbed98405bbaed941cd6a94bb3c2e2bad3a1bdc04ddb5574
data/lib/slim_lint/cli.rb CHANGED
@@ -65,7 +65,7 @@ module SlimLint
65
65
  # exception.
66
66
  def handle_exception(exception)
67
67
  case exception
68
- when SlimLint::Exceptions::ConfigurationError
68
+ when SlimLint::Exceptions::ConfigurationError, SlimLint::NoSuchLinter
69
69
  log.error exception.message
70
70
  EX_CONFIG
71
71
  when SlimLint::Exceptions::InvalidCLIOption
@@ -82,9 +82,25 @@ module SlimLint
82
82
  def validate
83
83
  ensure_exclude_option_array_exists
84
84
  ensure_linter_section_exists
85
+ ensure_linter_names_are_valid
85
86
  ensure_linter_include_exclude_arrays_exist
86
87
  end
87
88
 
89
+ # Ensures all linter names in the configuration are valid.
90
+ def ensure_linter_names_are_valid
91
+ return if @hash['linters'].nil?
92
+
93
+ valid_names = SlimLint::LinterRegistry.linter_names
94
+ return if valid_names.empty? # Skip if linters not yet loaded
95
+
96
+ @hash['linters'].each_key do |linter_name|
97
+ next if valid_names.include?(linter_name)
98
+
99
+ raise SlimLint::NoSuchLinter,
100
+ "No such linter: #{linter_name}. Available: #{valid_names.join(', ')}"
101
+ end
102
+ end
103
+
88
104
  # Ensures the `exclude` global option is an array.
89
105
  def ensure_exclude_option_array_exists
90
106
  @hash['exclude'] = Array(@hash['exclude'])
@@ -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
@@ -11,6 +11,13 @@ module SlimLint
11
11
  # List of all registered linters.
12
12
  attr_reader :linters
13
13
 
14
+ # Returns the short names of all registered linters.
15
+ #
16
+ # @return [Array<String>]
17
+ def linter_names
18
+ @linters.map { |linter| linter.name.split('::').last }
19
+ end
20
+
14
21
  # Executed when a linter includes the {LinterRegistry} module.
15
22
  #
16
23
  # This results in the linter being registered with the registry.
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.33.0'
5
+ VERSION = '0.35.0'
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.0
4
+ version: 0.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-21 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rexml
@@ -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.2
185
+ rubygems_version: 4.0.10
186
186
  specification_version: 4
187
187
  summary: Slim template linting tool
188
188
  test_files: []