rubocop-slim 0.3.0 → 0.4.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: e66ccc298ec65e04faa7e04a808599561bf00a5612f894b696e95f5dc0d78133
4
- data.tar.gz: e0cc9efca5b9bb323d40152ddc164d366cbffd991d8687fd7b081681aeb278c0
3
+ metadata.gz: 1412b34e431ea64b3ebb1784f24b0a8fd41fc67f293278c27edd4996c6f1bc4a
4
+ data.tar.gz: 1d80d23726ef31a8204ee3b2e3a06c9b0998035e49dfe7addd97b886d5cb399f
5
5
  SHA512:
6
- metadata.gz: 89e1f4affe662786a84a62185518ebf90a9dabbeab66f4e19e85fa2f97e6b1f4d813d61b9b07d99b7e7159028f591f616939a61f654f9b2df8e16ff50444ecea
7
- data.tar.gz: 72b4f5485a411e9de2bc3e086e78fdf9c41076a4fc0434ce8397fb2abddd5760ef4732499405e52f45874b1fecf7e06646f17a479f4656577afab927c9423b43
6
+ metadata.gz: c31f7ce364db6efc2c4ea2bd7cef636a231cedcdaa0b254f32a17570ce21dca5ab8bd2956e8836c7223bbf3e4d7e98071ee015d794b934df41b8ce91f6198d56
7
+ data.tar.gz: a33f1cf616116690d0f54d0f84d64fc500468e00e0f0c24795a81b7f8000bad8022c08cdd67a843ab26d343ad459382b1ce38cc4c9bd22ff955cd647ef3b72bb
data/.rubocop.yml CHANGED
@@ -12,7 +12,7 @@ AllCops:
12
12
  Exclude:
13
13
  - spec/**/*.slim
14
14
  NewCops: enable
15
- TargetRubyVersion: 2.7
15
+ TargetRubyVersion: 3.3
16
16
 
17
17
  Gemspec/RequireMFA:
18
18
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-slim (0.3.0)
4
+ rubocop-slim (0.4.0)
5
5
  lint_roller (>= 1.1)
6
6
  rubocop (>= 1.72.1)
7
7
  slimi (~> 0.7)
@@ -36,7 +36,7 @@ GEM
36
36
  language_server-protocol (3.17.0.4)
37
37
  lint_roller (1.1.0)
38
38
  logger (1.7.0)
39
- minitest (5.25.5)
39
+ minitest (5.27.0)
40
40
  mutex_m (0.3.0)
41
41
  parallel (1.26.3)
42
42
  parser (3.3.7.4)
@@ -86,18 +86,18 @@ GEM
86
86
  activesupport
87
87
  lint_roller (>= 1.1)
88
88
  rubocop (>= 1.72.1)
89
- slimi (0.7.6)
89
+ slimi (0.10.0)
90
90
  temple
91
91
  thor
92
92
  tilt
93
- temple (0.10.3)
94
- thor (1.3.2)
95
- tilt (2.6.0)
93
+ temple (0.10.7)
94
+ thor (1.5.0)
95
+ tilt (2.9.0)
96
96
  tzinfo (2.0.6)
97
97
  concurrent-ruby (~> 1.0)
98
98
  unicode-display_width (3.1.4)
99
99
  unicode-emoji (~> 4.0, >= 4.0.4)
100
- unicode-emoji (4.0.4)
100
+ unicode-emoji (4.3.0)
101
101
 
102
102
  PLATFORMS
103
103
  ruby
data/config/default.yml CHANGED
@@ -63,6 +63,10 @@ Layout/HashAlignment:
63
63
  Exclude:
64
64
  - '**/*.slim'
65
65
 
66
+ Layout/InitialIndentation:
67
+ Exclude:
68
+ - '**/*.slim'
69
+
66
70
  Layout/IndentationConsistency:
67
71
  Exclude:
68
72
  - '**/*.slim'
@@ -175,6 +179,10 @@ Style/ParallelAssignment:
175
179
  Exclude:
176
180
  - '**/*.slim'
177
181
 
182
+ Style/RedundantParentheses:
183
+ Exclude:
184
+ - '**/*.slim'
185
+
178
186
  Style/RescueModifier:
179
187
  Exclude:
180
188
  - '**/*.slim'
@@ -50,7 +50,7 @@ module RuboCop
50
50
  | for[ \t]+\w+[ \t]+in
51
51
  )
52
52
  \b[ \t]*
53
- /x.freeze
53
+ /x
54
54
 
55
55
  class << self
56
56
  # @param [String] code
@@ -93,7 +93,7 @@ module RuboCop
93
93
  [ \t]*
94
94
  (\#.*)?
95
95
  \Z
96
- /x.freeze
96
+ /x
97
97
 
98
98
  class << self
99
99
  # @param [String] code
@@ -7,6 +7,17 @@ module RuboCop
7
7
  module Slim
8
8
  # Extract Ruby codes from Slim template.
9
9
  class RubyExtractor
10
+ # Keep `ruby:` bodies as is, so that their positions are available.
11
+ class Interpolation < ::Slimi::Filters::Interpolation
12
+ def on_slimi_embedded(
13
+ type,
14
+ expression,
15
+ attributes
16
+ )
17
+ type == 'ruby' ? [:slimi, :embedded, type, expression, attributes] : super
18
+ end
19
+ end
20
+
10
21
  class << self
11
22
  # @param [RuboCop::ProcessedSource] processed_source
12
23
  # @return [Array<RuboCop::ProcessedSource>, nil]
@@ -39,7 +50,7 @@ module RuboCop
39
50
 
40
51
  # @return [Array] Slim AST, represented in S-expression.
41
52
  def ast
42
- ::Slimi::Filters::Interpolation.new.call(
53
+ Interpolation.new.call(
43
54
  ::Slimi::Parser.new(file: file_path).call(template_source)
44
55
  )
45
56
  end
@@ -51,23 +62,24 @@ module RuboCop
51
62
 
52
63
  # @return [Array<RuboCop::Slim::RubyClip]
53
64
  def ruby_clips
54
- ruby_ranges.map do |(begin_, end_)|
55
- RubyClip.new(
65
+ ruby_ranges.flat_map do |(begin_, end_, embedded)|
66
+ ruby_clip = RubyClip.new(
56
67
  code: template_source[begin_...end_],
57
68
  offset: begin_
58
69
  )
59
- end.flat_map do |ruby_clip|
60
- WhenDecomposer.call(@processed_source, ruby_clip)
61
- end.map do |ruby_clip|
62
- KeywordRemover.call(ruby_clip)
70
+ next ruby_clip if embedded
71
+
72
+ WhenDecomposer.call(@processed_source, ruby_clip).map do |decomposed_ruby_clip|
73
+ KeywordRemover.call(decomposed_ruby_clip)
74
+ end
63
75
  end
64
76
  end
65
77
 
66
78
  # @return [Array<Array<Integer>>]
67
79
  def ruby_ranges
68
80
  result = []
69
- traverse(ast) do |begin_, end_|
70
- result << [begin_, end_]
81
+ traverse(ast) do |begin_, end_, embedded|
82
+ result << [begin_, end_, embedded]
71
83
  end
72
84
  result
73
85
  end
@@ -88,6 +100,15 @@ module RuboCop
88
100
  )
89
101
  return unless node.instance_of?(::Array)
90
102
 
103
+ if node[0..2] == [:slimi, :embedded, 'ruby']
104
+ lines = node[3].grep(::Array).select { |child| child[1] == :interpolate }
105
+ unless lines.empty?
106
+ begin_ = (template_source.rindex("\n", lines.first[2] - 1) || -1) + 1
107
+ block.call(begin_, lines.last[3], true)
108
+ end
109
+ return
110
+ end
111
+
91
112
  block.call(node[2], node[3]) if node[0] == :slimi && node[1] == :position
92
113
  node.each do |element|
93
114
  traverse(element, &block)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Slim
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -7,7 +7,7 @@ module RuboCop
7
7
  \A
8
8
  \s*
9
9
  when[ \t]
10
- /x.freeze
10
+ /x
11
11
 
12
12
  class << self
13
13
  # @param [RuboCop::ProcessedSource] processed_source
data/rubocop-slim.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = 'RuboCop plugin for Slim template.'
12
12
  spec.homepage = 'https://github.com/r7kamura/rubocop-slim'
13
13
  spec.license = 'MIT'
14
- spec.required_ruby_version = '>= 2.7'
14
+ spec.required_ruby_version = '>= 3.3'
15
15
 
16
16
  spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = spec.homepage
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-04-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: lint_roller
@@ -52,7 +51,6 @@ dependencies:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0.7'
55
- description:
56
54
  email:
57
55
  - r7kamura@gmail.com
58
56
  executables: []
@@ -87,7 +85,6 @@ metadata:
87
85
  source_code_uri: https://github.com/r7kamura/rubocop-slim
88
86
  changelog_uri: https://github.com/r7kamura/rubocop-slim/releases
89
87
  default_lint_roller_plugin: RuboCop::Slim::Plugin
90
- post_install_message:
91
88
  rdoc_options: []
92
89
  require_paths:
93
90
  - lib
@@ -95,15 +92,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
92
  requirements:
96
93
  - - ">="
97
94
  - !ruby/object:Gem::Version
98
- version: '2.7'
95
+ version: '3.3'
99
96
  required_rubygems_version: !ruby/object:Gem::Requirement
100
97
  requirements:
101
98
  - - ">="
102
99
  - !ruby/object:Gem::Version
103
100
  version: '0'
104
101
  requirements: []
105
- rubygems_version: 3.3.27
106
- signing_key:
102
+ rubygems_version: 3.6.9
107
103
  specification_version: 4
108
104
  summary: RuboCop plugin for Slim template.
109
105
  test_files: []