slim_lint 0.32.0 → 0.32.2

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: 57f5ec1042e443a09867926172b5b5b0282902c520d178ab0082ef349b938df7
4
- data.tar.gz: d8edb2714c4c68b4e58dfb4042d00209a0ac250ac669fdf4251f1a4574050f9c
3
+ metadata.gz: fd046a032cb7d554e447d0e2ef1a790ff22f163eb734450d330ab1fc769c575b
4
+ data.tar.gz: 676860f6eb8fce36a54d82efab06fbf38dab1a68139ce330dbd16b4cdc42d7d5
5
5
  SHA512:
6
- metadata.gz: d7c4d11c784321cf40fc1dd5ed8174f14f41f352f7c826604b013a08eb2515cf05d84dffbc1eb9b0f53bd00b0fdd3bee3b0999a31bc25cd9a086d3d9799ce510
7
- data.tar.gz: fe69df4001565d50098eb30239959733ea1abae9a816c36337b6ef4e4931a35a5cd7361ed88a84189eb2cd7f75f5083ad33f661d842502195b1282523121522e
6
+ metadata.gz: d81d8c6bcc920c6d3c676da85d87d7c1792468428bfa3045af11bf45222ee70faf12d4d8383e30889453eb0f08d0fce7b43b65cb8ad7c1fadcd0da27ac4262b6
7
+ data.tar.gz: 887d73d3cec672e79987668bd733ae90a2c60d505b17ba6a7bcb7cf5ffcd71a43fbc5b501b2d51032945d4612baf7a85d57803a6e07c7c56af0e06f4425558bb
@@ -7,29 +7,22 @@ module SlimLint
7
7
 
8
8
  MSG = 'Inconsistent quote style. %s'
9
9
 
10
- on_start do |_sexp|
11
- dummy_node = Struct.new(:line)
12
- document.source_lines.each_with_index do |line, index|
13
- # Skip lines without any quotes
14
- next unless line =~ /['"]/
15
-
16
- # Skip comments
17
- next if line =~ %r{^\s*(/{1,3})}
18
-
19
- # Skip Ruby lines that RuboCop will check
20
- next if skip_ruby_lines && line =~ /^\s*[=-]/
21
-
22
- # Find all quoted strings in attributes (ignoring nested quotes)
23
- single_quotes = line.scan(/^(?:[^'"]*'[^'"]*'[^'"]*)?(?:[^'"]*)('[^'"]*')/)
24
- double_quotes = line.scan(/^(?:[^'"]*'[^'"]*'[^'"]*)?(?:[^'"]*)("[^'"]*")/)
25
-
26
- if enforced_style == :single_quotes && double_quotes.any?
27
- report_lint(dummy_node.new(index + 1),
28
- format(MSG, "Use single quotes for attribute values (')"))
29
- elsif enforced_style == :double_quotes && single_quotes.any?
30
- report_lint(dummy_node.new(index + 1),
31
- format(MSG, 'Use double quotes for attribute values (")'))
32
- end
10
+ on [:html, :attrs] do |node|
11
+ line = document.source_lines[node.line - 1]
12
+
13
+ # Skip lines without any quotes
14
+ next unless line =~ /['"]/
15
+
16
+ # Find all quoted strings in attributes (ignoring nested quotes)
17
+ single_quotes = line.scan(/^(?:[^'"]*'[^'"]*'[^'"]*)?(?:[^'"]*)('[^'"]*')/)
18
+ double_quotes = line.scan(/^(?:[^'"]*'[^'"]*'[^'"]*)?(?:[^'"]*)("[^'"]*")/)
19
+
20
+ if enforced_style == :single_quotes && double_quotes.any?
21
+ report_lint(node,
22
+ format(MSG, "Use single quotes for attribute values (')"))
23
+ elsif enforced_style == :double_quotes && single_quotes.any?
24
+ report_lint(node,
25
+ format(MSG, 'Use double quotes for attribute values (")'))
33
26
  end
34
27
  end
35
28
 
@@ -38,9 +31,5 @@ module SlimLint
38
31
  def enforced_style
39
32
  config['enforced_style']&.to_sym || :single_quotes
40
33
  end
41
-
42
- def skip_ruby_lines
43
- config.fetch('skip_ruby_lines', true)
44
- end
45
34
  end
46
35
  end
@@ -11,6 +11,14 @@ module SlimLint
11
11
  class Linter::RuboCop < Linter
12
12
  include LinterRegistry
13
13
 
14
+ # Initializes a RuboCop linter with the specified configuration.
15
+ #
16
+ # @param config [Hash] configuration for this linter
17
+ def initialize(config)
18
+ super(config)
19
+ @rubocop = ::RuboCop::CLI.new
20
+ end
21
+
14
22
  on_start do |_sexp|
15
23
  processed_sexp = SlimLint::RubyExtractEngine.new.call(document.source)
16
24
 
@@ -31,22 +39,19 @@ module SlimLint
31
39
  # @param source_map [Hash] map of Ruby code line numbers to original line
32
40
  # numbers in the template
33
41
  def find_lints(ruby, source_map)
34
- rubocop = ::RuboCop::CLI.new
35
-
36
42
  filename = document.file ? "#{document.file}.rb" : 'ruby_script.rb'
37
43
 
38
44
  with_ruby_from_stdin(ruby) do
39
- extract_lints_from_offenses(lint_file(rubocop, filename), source_map)
45
+ extract_lints_from_offenses(lint_file(filename), source_map)
40
46
  end
41
47
  end
42
48
 
43
49
  # Defined so we can stub the results in tests
44
50
  #
45
- # @param rubocop [RuboCop::CLI]
46
51
  # @param file [String]
47
52
  # @return [Array<RuboCop::Cop::Offense>]
48
- def lint_file(rubocop, file)
49
- rubocop.run(rubocop_flags << file)
53
+ def lint_file(file)
54
+ @rubocop.run(rubocop_flags << file)
50
55
  OffenseCollector.offenses
51
56
  end
52
57
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.32.0'
5
+ VERSION = '0.32.2'
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.32.0
4
+ version: 0.32.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-03 00:00:00.000000000 Z
10
+ date: 2025-03-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rexml