rubocop-slim 0.2.5 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acd8c1d290c8711b0b4877edb6ec304359d7ad7c6fcfdc191001441d0a3125f6
4
- data.tar.gz: 748d147c34bc080f1f2b944dfe61421d62395a0585103a1b665e75f05dcc5fa2
3
+ metadata.gz: 9947f37c94fc6e24e579dc86a7803631a5634f84de00542747d7704705567233
4
+ data.tar.gz: e807279fde8021198b37d5964903892aa3106d47b594a03bb1ed8a3ad7ce1c2a
5
5
  SHA512:
6
- metadata.gz: f2fa7a6c42f0a089c8f2917c0dff4fc9087d7daebd855b277faeb59c345cdbb32f5805c74247f5d40065a88859757b57dbd0c3f5eb77747597ff19743aa2ba1a
7
- data.tar.gz: add4a21478c6e0340436bfa84264f3e1b645a4da1ba1e0db5d60a7064340e34c328ec3d6e9d46ed0dd8e2f65d1c89c7949bbb3fba50e2374f06f1c17361e0899
6
+ metadata.gz: deae8bef3a1c84680ad008c42b5bf7ae299c0b1a21b7527eb6710b4c6bdd1e36d91f70ce30b053e510c0a4dfbe9e68e271e69f962da4a12288c0b2c026707984
7
+ data.tar.gz: eb7293ff3fc3954ad085af8687f642e7a60349bcb11ff2754af46d77e76083efd4025712a2234ec68d7ca3a8ff280dcf521b713e9a90d336094d9f2536568efb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-slim (0.2.5)
4
+ rubocop-slim (0.2.7)
5
5
  rubocop (~> 1.45)
6
6
  slimi (~> 0.7)
7
7
 
@@ -75,7 +75,7 @@ GEM
75
75
  sevencop (0.43.1)
76
76
  activesupport
77
77
  rubocop
78
- slimi (0.7.4)
78
+ slimi (0.7.5)
79
79
  temple
80
80
  thor
81
81
  tilt
@@ -86,7 +86,7 @@ module RuboCop
86
86
  # Remove trailing `do`.
87
87
  class TrailingDoRemover
88
88
  REGEXP = /
89
- [ \t]
89
+ (?:\b[ \t]*|[ \t])
90
90
  do
91
91
  [ \t]*
92
92
  (\|[^|]*\|)?
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Slim
5
+ class ProcessedSourceBuilder
6
+ class << self
7
+ # Creates a new ProcessedSource, inheriting state from a donor.
8
+ #
9
+ # @param [String] code
10
+ # @param [RuboCop::ProcessedSource] processed_source
11
+ # @return [RuboCop::ProcessedSource]
12
+ def call(
13
+ code:,
14
+ processed_source:
15
+ )
16
+ new(
17
+ code: code,
18
+ processed_source: processed_source
19
+ ).call
20
+ end
21
+ end
22
+
23
+ def initialize(
24
+ code:,
25
+ processed_source:
26
+ )
27
+ @code = code
28
+ @processed_source = processed_source
29
+ end
30
+
31
+ def call
32
+ new_processed_source = ::RuboCop::ProcessedSource.new(
33
+ @code,
34
+ @processed_source.ruby_version,
35
+ @processed_source.path,
36
+ **keyword_arguments
37
+ )
38
+ new_processed_source.config = @processed_source.config
39
+ new_processed_source.registry = @processed_source.registry
40
+ new_processed_source
41
+ end
42
+
43
+ private
44
+
45
+ # @return [Hash]
46
+ def keyword_arguments
47
+ if @processed_source.respond_to?(:parser_engine)
48
+ { parser_engine: @processed_source.parser_engine }
49
+ else
50
+ {}
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -25,16 +25,12 @@ module RuboCop
25
25
  return unless supported_file_path_pattern?
26
26
 
27
27
  ruby_clips.map do |ruby_clip|
28
- processed_source = ::RuboCop::ProcessedSource.new(
29
- ruby_clip.code,
30
- @processed_source.ruby_version,
31
- file_path
32
- )
33
- processed_source.config = @processed_source.config
34
- processed_source.registry = @processed_source.registry
35
28
  {
36
29
  offset: ruby_clip.offset,
37
- processed_source: processed_source
30
+ processed_source: ProcessedSourceBuilder.call(
31
+ code: ruby_clip.code,
32
+ processed_source: @processed_source
33
+ )
38
34
  }
39
35
  end
40
36
  end
@@ -61,7 +57,7 @@ module RuboCop
61
57
  offset: begin_
62
58
  )
63
59
  end.flat_map do |ruby_clip|
64
- WhenDecomposer.call(ruby_clip)
60
+ WhenDecomposer.call(@processed_source, ruby_clip)
65
61
  end.map do |ruby_clip|
66
62
  KeywordRemover.call(ruby_clip)
67
63
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Slim
5
- VERSION = '0.2.5'
5
+ VERSION = '0.2.7'
6
6
  end
7
7
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parser/current'
4
- require 'rubocop/ast/builder'
5
-
6
3
  module RuboCop
7
4
  module Slim
8
5
  class WhenDecomposer
@@ -13,15 +10,27 @@ module RuboCop
13
10
  /x.freeze
14
11
 
15
12
  class << self
13
+ # @param [RuboCop::ProcessedSource] processed_source
16
14
  # @param [RuboCop::Slim::RubyClip] ruby_clip
17
15
  # @return [Array<RuboCop::Slim::RubyClip>]
18
- def call(ruby_clip)
19
- new(ruby_clip).call
16
+ def call(
17
+ processed_source,
18
+ ruby_clip
19
+ )
20
+ new(
21
+ processed_source,
22
+ ruby_clip
23
+ ).call
20
24
  end
21
25
  end
22
26
 
27
+ # @param [RuboCop::ProcessedSource] processed_source
23
28
  # @param [RuboCop::Slim::RubyClip] ruby_clip
24
- def initialize(ruby_clip)
29
+ def initialize(
30
+ processed_source,
31
+ ruby_clip
32
+ )
33
+ @processed_source = processed_source
25
34
  @ruby_clip = ruby_clip
26
35
  end
27
36
 
@@ -53,14 +62,10 @@ module RuboCop
53
62
  # @param [String] source
54
63
  # @return [RuboCop::AST::Node]
55
64
  def parse(source)
56
- ::Parser::CurrentRuby.new(
57
- ::RuboCop::AST::Builder.new
58
- ).parse(
59
- ::Parser::Source::Buffer.new(
60
- '(string)',
61
- source: source
62
- )
63
- )
65
+ ProcessedSourceBuilder.call(
66
+ code: source,
67
+ processed_source: @processed_source
68
+ ).ast
64
69
  end
65
70
  end
66
71
  end
data/lib/rubocop/slim.rb CHANGED
@@ -4,6 +4,7 @@ module RuboCop
4
4
  module Slim
5
5
  autoload :ConfigLoader, 'rubocop/slim/config_loader'
6
6
  autoload :KeywordRemover, 'rubocop/slim/keyword_remover'
7
+ autoload :ProcessedSourceBuilder, 'rubocop/slim/processed_source_builder'
7
8
  autoload :RubyClip, 'rubocop/slim/ruby_clip'
8
9
  autoload :RubyExtractor, 'rubocop/slim/ruby_extractor'
9
10
  autoload :WhenDecomposer, 'rubocop/slim/when_decomposer'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-25 00:00:00.000000000 Z
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -58,6 +58,7 @@ files:
58
58
  - lib/rubocop/slim.rb
59
59
  - lib/rubocop/slim/config_loader.rb
60
60
  - lib/rubocop/slim/keyword_remover.rb
61
+ - lib/rubocop/slim/processed_source_builder.rb
61
62
  - lib/rubocop/slim/rubocop_extension.rb
62
63
  - lib/rubocop/slim/ruby_clip.rb
63
64
  - lib/rubocop/slim/ruby_extractor.rb