rubocop-erb 0.5.3 → 0.5.5

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: 1650bd31cfedf2d62fc05f8979e290bf33b04b8b42a6988fbab36ddef75a113f
4
- data.tar.gz: 44de0adbdc72ac2abb1cb49778989bb6266f6c91a5cfeffd428c2c83df9ec764
3
+ metadata.gz: 49341b04ccc3098029bdd8f9b98b961825328a46623797e1a544e3264f16768b
4
+ data.tar.gz: eac652e2b1a040701290af19e4cded60a4cd53aa2849bc2aa5d1c9ddfefe7fee
5
5
  SHA512:
6
- metadata.gz: '059b029c8a15edf705991b6e0acf4e7b31dbae52afd4c109afc04902cb4e3db353b0dc3cc2c6fdc0118a361be190b755b73dfa54472a0d85097e70192e0f4203'
7
- data.tar.gz: 1d69a7428f7caee5cbcfad7d987ac49f0f38b28b16cb11888fe1aa66a6a827bf8528b178f86e3b395b195f24dd588d67dbea48121448d2d23952a443e3f398f3
6
+ metadata.gz: d3dd34349dc3eeea3925ad0b0d789e89efabc1ce0120f80ef64298e1b2b8b548936be1f7e4d10b7b2569a36685cc10170af706eeb3d982c08ac1d5638979e90c
7
+ data.tar.gz: 7705cb8f5537d18855c89e431fe40489f002a2c9a104b5662fa7bf20e967c23ae549507c42649819360180d1ee792b9980432b810ea1e17f4feb73d3b477f747
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-erb (0.5.3)
4
+ rubocop-erb (0.5.5)
5
5
  better_html
6
6
  rubocop (~> 1.45)
7
7
 
@@ -45,12 +45,12 @@ GEM
45
45
  concurrent-ruby (~> 1.0)
46
46
  json (2.7.2)
47
47
  language_server-protocol (3.17.0.3)
48
- loofah (2.22.0)
48
+ loofah (2.23.1)
49
49
  crass (~> 1.0.2)
50
50
  nokogiri (>= 1.12.0)
51
51
  minitest (5.24.1)
52
52
  mutex_m (0.2.0)
53
- nokogiri (1.16.7-x86_64-linux)
53
+ nokogiri (1.16.8-x86_64-linux)
54
54
  racc (~> 1.4)
55
55
  parallel (1.25.1)
56
56
  parser (3.3.4.0)
@@ -62,9 +62,9 @@ GEM
62
62
  activesupport (>= 5.0.0)
63
63
  minitest
64
64
  nokogiri (>= 1.6)
65
- rails-html-sanitizer (1.6.0)
65
+ rails-html-sanitizer (1.6.1)
66
66
  loofah (~> 2.21)
67
- nokogiri (~> 1.14)
67
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
68
68
  rainbow (3.1.1)
69
69
  rake (13.2.1)
70
70
  regexp_parser (2.9.2)
data/config/default.yml CHANGED
@@ -143,7 +143,7 @@ Lint/OutOfRangeRegexpRef:
143
143
  Exclude:
144
144
  - '**/*.erb'
145
145
 
146
- Lint/SyntaxError:
146
+ Lint/Syntax:
147
147
  Exclude:
148
148
  - '**/*.erb'
149
149
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- rubocop-erb (0.5.3)
4
+ rubocop-erb (0.5.5)
5
5
  better_html
6
6
  rubocop (~> 1.45)
7
7
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Erb
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
@@ -28,10 +28,9 @@ module RuboCop
28
28
  ruby_clips.map do |ruby_clip|
29
29
  {
30
30
  offset: ruby_clip.offset,
31
- processed_source: ProcessedSourceHelper.code_to_processed_source(
32
- @processed_source,
33
- file_path,
34
- ruby_clip.code
31
+ processed_source: ProcessedSourceBuilder.call(
32
+ code: ruby_clip.code,
33
+ processed_source: @processed_source
35
34
  )
36
35
  }
37
36
  end
@@ -63,7 +62,7 @@ module RuboCop
63
62
  def root
64
63
  ::BetterHtml::Parser.new(
65
64
  ::Parser::Source::Buffer.new(
66
- @file_path,
65
+ file_path,
67
66
  source: template_source
68
67
  ),
69
68
  template_language: :html
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Erb
5
- VERSION = '0.5.3'
5
+ VERSION = '0.5.5'
6
6
  end
7
7
  end
@@ -37,13 +37,15 @@ module RuboCop
37
37
  if match_data
38
38
  offset = match_data[0].length
39
39
  condition = @ruby_clip.code[offset..].sub(/[ \t]then(?:[ \t].*)?/, '')
40
- parse(
40
+ nodes = parse(
41
41
  <<~RUBY
42
42
  [
43
43
  #{condition}
44
44
  ]
45
45
  RUBY
46
- ).children.map do |child|
46
+ )&.children || []
47
+
48
+ nodes.map do |child|
47
49
  RubyClip.new(
48
50
  code: child.location.expression.source,
49
51
  offset: @ruby_clip.offset + offset + child.location.expression.begin_pos - 4
@@ -59,10 +61,9 @@ module RuboCop
59
61
  # @param [String] source
60
62
  # @return [RuboCop::AST::Node]
61
63
  def parse(source)
62
- ProcessedSourceHelper.code_to_processed_source(
63
- @processed_source,
64
- '(string)',
65
- source
64
+ ProcessedSourceBuilder.call(
65
+ code: source,
66
+ processed_source: @processed_source
66
67
  ).ast
67
68
  end
68
69
  end
data/lib/rubocop/erb.rb CHANGED
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Erb
5
5
  autoload :ConfigLoader, 'rubocop/erb/config_loader'
6
6
  autoload :KeywordRemover, 'rubocop/erb/keyword_remover'
7
- autoload :ProcessedSourceHelper, 'rubocop/erb/processed_source_helper'
7
+ autoload :ProcessedSourceBuilder, 'rubocop/erb/processed_source_builder'
8
8
  autoload :RubyClip, 'rubocop/erb/ruby_clip'
9
9
  autoload :RubyExtractor, 'rubocop/erb/ruby_extractor'
10
10
  autoload :WhenDecomposer, 'rubocop/erb/when_decomposer'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
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-08-11 00:00:00.000000000 Z
11
+ date: 2024-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_html
@@ -59,7 +59,7 @@ files:
59
59
  - lib/rubocop/erb.rb
60
60
  - lib/rubocop/erb/config_loader.rb
61
61
  - lib/rubocop/erb/keyword_remover.rb
62
- - lib/rubocop/erb/processed_source_helper.rb
62
+ - lib/rubocop/erb/processed_source_builder.rb
63
63
  - lib/rubocop/erb/rubocop_extension.rb
64
64
  - lib/rubocop/erb/ruby_clip.rb
65
65
  - lib/rubocop/erb/ruby_extractor.rb
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Erb
5
- module ProcessedSourceHelper
6
- # Creates a new ProcessedSource, inheriting state from a donor
7
- #
8
- # @param [RuboCop::ProcessedSource] input_processed_source
9
- # @param [String] code
10
- # @return [RuboCop::ProcessedSource]
11
- def self.code_to_processed_source(input_processed_source, path, code)
12
- supports_prism = input_processed_source.respond_to?(:parser_engine)
13
- processed_source = if supports_prism
14
- ::RuboCop::ProcessedSource.new(
15
- code,
16
- input_processed_source.ruby_version,
17
- path,
18
- parser_engine: input_processed_source.parser_engine
19
- )
20
- else
21
- ::RuboCop::ProcessedSource.new(
22
- code,
23
- input_processed_source.ruby_version,
24
- path
25
- )
26
- end
27
- processed_source.config = input_processed_source.config
28
- processed_source.registry = input_processed_source.registry
29
- processed_source
30
- end
31
- end
32
- end
33
- end