slimcop 0.11.0 → 0.14.0

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: 4b967da47ab7a5721d082f4d1a4e9bb84006431c5acb5992a27f8246bdcfd904
4
- data.tar.gz: 6e260866461bc31ddef835279d647905f17f87890b63af229bd98557699e0d8f
3
+ metadata.gz: 9fa07b1fe38abcfaa4931343e0f3a44ad24cb17d6d85ed6dbe6090dd16f429b7
4
+ data.tar.gz: 6612b476195e0f2f34991edaa869fa5336d4e1d553e5c124b983856da9881b28
5
5
  SHA512:
6
- metadata.gz: 62cbf9db3a9f0fc741714afdd4f886b61efb4bed1e3f4ca54e6e7caa03b3cf2e8f3141aec2456b3b13f7fe0999e5a7ab9a7578a6700225a220db08200f9b2f96
7
- data.tar.gz: c6742245998d9fbd23dca47dbf55be3e8717722daa7515df5afab77baca05d1c2ddc26d80a62bbbc97a7cfa06332a5c6fb3bc078a7d3853479598f7cb86c36ea
6
+ metadata.gz: 5a9fa1438ea7d1c7401f1fa77990977e3d65b36c7435eae44f14c0369169ef453ed8736ee7b50eb544381a6db8fa225c4b0d4b870b86b62e13d6e60c36e28749
7
+ data.tar.gz: c1fe2201f69025cf886305532bdad15144097c301ae407c22ee6b22ff5a264c3a9fec0b206ff9fcb274f806ce900ebd300500f24d1c4d47d519f4374760f20f8
data/CHANGELOG.md CHANGED
@@ -2,11 +2,34 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.14.0 - 2022-01-22
6
+
7
+ ### Changed
8
+
9
+ - Disable Style/MultilineTernaryOperator by default.
10
+
11
+ ## 0.13.1 - 2022-01-18
12
+
13
+ ### Fixed
14
+
15
+ - Fix missing some metadata in gemspec.
16
+
17
+ ## 0.13.0 - 2022-01-15
18
+
19
+ ### Changed
20
+
21
+ - Use templatecop.
22
+
23
+ ## 0.12.0 - 2022-01-12
24
+
25
+ ### Changed
26
+
27
+ - Keep trying auto-correction up to 7 times until no offense detected.
28
+
5
29
  ## 0.11.0 - 2022-01-10
6
30
 
7
31
  ### Changed
8
32
 
9
- - Use :offset instead of :begin_ at RubyExtractor.
10
33
  - Detect offenses from code that containing `if`, `unless`, `do`, etc.
11
34
 
12
35
  ## 0.10.0 - 2022-01-06
data/Gemfile.lock CHANGED
@@ -1,10 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slimcop (0.11.0)
5
- rainbow
6
- rubocop (>= 0.87)
4
+ slimcop (0.14.0)
7
5
  slimi (>= 0.5.1)
6
+ templatecop
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
@@ -45,10 +44,14 @@ GEM
45
44
  rubocop-rspec (2.6.0)
46
45
  rubocop (~> 1.19)
47
46
  ruby-progressbar (1.11.0)
48
- slimi (0.7.0)
47
+ slimi (0.7.1)
49
48
  temple
50
49
  thor
51
50
  tilt
51
+ templatecop (0.2.0)
52
+ parallel
53
+ parser
54
+ rubocop (>= 0.87)
52
55
  temple (0.8.2)
53
56
  thor (1.2.1)
54
57
  tilt (2.0.10)
data/default.yml CHANGED
@@ -103,6 +103,9 @@ Style/IdenticalConditionalBranches:
103
103
  Style/IfUnlessModifier:
104
104
  Enabled: false
105
105
 
106
+ Style/MultilineTernaryOperator:
107
+ Enabled: false
108
+
106
109
  Style/Next:
107
110
  Enabled: false
108
111
 
data/exe/slimcop CHANGED
@@ -3,5 +3,12 @@
3
3
 
4
4
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
5
  require 'slimcop'
6
+ require 'templatecop'
6
7
 
7
- Slimcop::Cli.new(ARGV).call
8
+ Templatecop::Cli.call(
9
+ default_configuration_path: File.expand_path('../default.yml', __dir__),
10
+ default_path_patterns: %w[**/*.slim],
11
+ executable_name: 'slimcop',
12
+ implicit_configuration_paths: %w[.slimcop.yml .rubocop.yml],
13
+ ruby_extractor: Slimcop::RubyExtractor
14
+ )
@@ -1,10 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'slimi'
4
+ require 'templatecop'
4
5
 
5
6
  module Slimcop
6
7
  # Extract Ruby codes from Slim source.
7
8
  class RubyExtractor
9
+ class << self
10
+ # @param [String, nil] file_path
11
+ # @param [String] source
12
+ def call(
13
+ file_path:,
14
+ source:
15
+ )
16
+ new(
17
+ file_path: file_path,
18
+ source: source
19
+ ).call
20
+ end
21
+ end
22
+
8
23
  # @param [String, nil] file_path
9
24
  # @param [String] source
10
25
  def initialize(file_path:, source:)
@@ -15,7 +30,7 @@ module Slimcop
15
30
  # @return [Array<Hash>]
16
31
  def call
17
32
  ranges.map do |(begin_, end_)|
18
- clipped = RubyClipper.new(@source[begin_...end_]).call
33
+ clipped = ::Templatecop::RubyClipper.new(@source[begin_...end_]).call
19
34
  {
20
35
  code: clipped[:code],
21
36
  offset: begin_ + clipped[:offset]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slimcop
4
- VERSION = '0.11.0'
4
+ VERSION = '0.14.0'
5
5
  end
data/lib/slimcop.rb CHANGED
@@ -3,13 +3,5 @@
3
3
  require_relative 'slimcop/version'
4
4
 
5
5
  module Slimcop
6
- autoload :Cli, 'slimcop/cli'
7
- autoload :Offense, 'slimcop/offense'
8
- autoload :PathFinder, 'slimcop/path_finder'
9
- autoload :RuboCopConfigGenerator, 'slimcop/rubo_cop_config_generator'
10
- autoload :RubyClipper, 'slimcop/ruby_clipper'
11
6
  autoload :RubyExtractor, 'slimcop/ruby_extractor'
12
- autoload :RubyOffenseCollector, 'slimcop/ruby_offense_collector'
13
- autoload :SlimCorrector, 'slimcop/slim_corrector'
14
- autoload :SlimOffenseCollector, 'slimcop/slim_offense_collector'
15
7
  end
data/slimcop.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = spec.homepage
18
18
  spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
19
+ spec.metadata['rubygems_mfa_required'] = 'true'
19
20
 
20
21
  # Specify which files should be added to the gem when it is released.
21
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -27,11 +28,7 @@ Gem::Specification.new do |spec|
27
28
  spec.bindir = 'exe'
28
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
30
  spec.require_paths = ['lib']
30
- spec.metadata = {
31
- 'rubygems_mfa_required' => 'true'
32
- }
33
31
 
34
- spec.add_dependency 'rainbow'
35
- spec.add_dependency 'rubocop', '>= 0.87'
36
32
  spec.add_dependency 'slimi', '>= 0.5.1'
33
+ spec.add_dependency 'templatecop'
37
34
  end
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-10 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rainbow
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rubocop
14
+ name: slimi
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '0.87'
19
+ version: 0.5.1
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '0.87'
26
+ version: 0.5.1
41
27
  - !ruby/object:Gem::Dependency
42
- name: slimi
28
+ name: templatecop
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: 0.5.1
33
+ version: '0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: 0.5.1
40
+ version: '0'
55
41
  description:
56
42
  email:
57
43
  - r7kamura@gmail.com
@@ -74,21 +60,16 @@ files:
74
60
  - default.yml
75
61
  - exe/slimcop
76
62
  - lib/slimcop.rb
77
- - lib/slimcop/cli.rb
78
- - lib/slimcop/offense.rb
79
- - lib/slimcop/path_finder.rb
80
- - lib/slimcop/rubo_cop_config_generator.rb
81
- - lib/slimcop/ruby_clipper.rb
82
63
  - lib/slimcop/ruby_extractor.rb
83
- - lib/slimcop/ruby_offense_collector.rb
84
- - lib/slimcop/slim_corrector.rb
85
- - lib/slimcop/slim_offense_collector.rb
86
64
  - lib/slimcop/version.rb
87
65
  - slimcop.gemspec
88
66
  homepage: https://github.com/r7kamura/slimcop
89
67
  licenses:
90
68
  - MIT
91
69
  metadata:
70
+ homepage_uri: https://github.com/r7kamura/slimcop
71
+ source_code_uri: https://github.com/r7kamura/slimcop
72
+ changelog_uri: https://github.com/r7kamura/slimcop/blob/main/CHANGELOG.md
92
73
  rubygems_mfa_required: 'true'
93
74
  post_install_message:
94
75
  rdoc_options: []
data/lib/slimcop/cli.rb DELETED
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rainbow'
4
- require 'rubocop'
5
-
6
- module Slimcop
7
- class Cli
8
- def initialize(argv)
9
- @argv = argv.dup
10
- end
11
-
12
- def call
13
- options = parse!
14
- formatter = ::RuboCop::Formatter::ProgressFormatter.new($stdout, color: options[:color])
15
- rubocop_config = RuboCopConfigGenerator.new(additional_config_file_path: options[:additional_config_file_path]).call
16
- file_paths = PathFinder.new(patterns: @argv).call
17
-
18
- formatter.started(file_paths)
19
- offenses = file_paths.flat_map do |file_path|
20
- formatter.file_started(file_path, {})
21
- source = ::File.read(file_path)
22
- offenses_ = investigate(
23
- auto_correct: options[:auto_correct],
24
- file_path: file_path,
25
- rubocop_config: rubocop_config,
26
- source: source
27
- )
28
- if options[:auto_correct]
29
- correct(
30
- file_path: file_path,
31
- offenses: offenses_,
32
- source: source
33
- )
34
- end
35
- formatter.file_finished(file_path, offenses_)
36
- offenses_
37
- end
38
- formatter.finished(file_paths)
39
- exit(offenses.empty? ? 0 : 1)
40
- end
41
-
42
- private
43
-
44
- # @param [String] file_path
45
- # @param [Array<Slimcop::Offense>] offenses
46
- # @param [String] source
47
- def correct(file_path:, offenses:, source:)
48
- rewritten_source = SlimCorrector.new(
49
- file_path: file_path,
50
- offenses: offenses,
51
- source: source
52
- ).call
53
- ::File.write(file_path, rewritten_source)
54
- end
55
-
56
- # @param [Boolean] auto_correct
57
- # @param [String] file_path
58
- # @param [String] rubocop_config
59
- # @param [String] source
60
- # @return [Array<Slimcop::Offense>]
61
- def investigate(auto_correct:, file_path:, rubocop_config:, source:)
62
- SlimOffenseCollector.new(
63
- auto_correct: auto_correct,
64
- file_path: file_path,
65
- rubocop_config: rubocop_config,
66
- source: source
67
- ).call
68
- end
69
-
70
- # @return [Hash]
71
- def parse!
72
- options = {}
73
- parser = ::OptionParser.new
74
- parser.banner = 'Usage: slimcop [options] [file1, file2, ...]'
75
- parser.version = VERSION
76
- parser.on('-a', '--auto-correct', 'Auto-correct offenses.') do
77
- options[:auto_correct] = true
78
- end
79
- parser.on('-c', '--config=', 'Specify configuration file. (default: .slimcop.yml or .rubocop.yml)') do |file_path|
80
- options[:additional_config_file_path] = file_path
81
- end
82
- parser.on('--[no-]color', 'Force color output on or off.') do |value|
83
- options[:color] = value
84
- end
85
- parser.parse!(@argv)
86
- options
87
- end
88
- end
89
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- require 'parser'
6
- require 'rubocop'
7
-
8
- module Slimcop
9
- class Offense
10
- extend ::Forwardable
11
-
12
- # @return [String]
13
- attr_reader :file_path
14
-
15
- # @return [Integer]
16
- attr_reader :offset
17
-
18
- delegate(
19
- %i[
20
- column
21
- column_length
22
- correctable?
23
- corrected_with_todo?
24
- corrected?
25
- corrector
26
- highlighted_area
27
- line
28
- message
29
- real_column
30
- severity
31
- ] => :rubocop_offense_with_real_location
32
- )
33
-
34
- # @param [Integer] offset
35
- # @param [RuboCop::Cop::Offense] rubocop_offense
36
- # @param [String] source Slim code.
37
- def initialize(file_path:, offset:, rubocop_offense:, source:)
38
- @file_path = file_path
39
- @offset = offset
40
- @rubocop_offense = rubocop_offense
41
- @source = source
42
- end
43
-
44
- # @return [Parser::Source::Range]
45
- def location
46
- @location ||= ::Parser::Source::Range.new(
47
- buffer,
48
- @rubocop_offense.location.begin_pos + @offset,
49
- @rubocop_offense.location.end_pos + @offset
50
- )
51
- end
52
-
53
- private
54
-
55
- # @return [Parser::Source::Buffer]
56
- def buffer
57
- ::Parser::Source::Buffer.new(
58
- file_path,
59
- source: @source
60
- )
61
- end
62
-
63
- # @return [RuboCop::Cop::Offense]
64
- def rubocop_offense_with_real_location
65
- ::RuboCop::Cop::Offense.new(
66
- @rubocop_offense.severity.name,
67
- location,
68
- @rubocop_offense.message,
69
- @rubocop_offense.cop_name,
70
- @rubocop_offense.status,
71
- @rubocop_offense.corrector
72
- )
73
- end
74
- end
75
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pathname'
4
-
5
- module Slimcop
6
- # Collect file paths from given path patterns.
7
- class PathFinder
8
- DEFAULT_PATH_PATTERNS = %w[
9
- **/*.slim
10
- ].freeze
11
-
12
- # @param [Array<String>] patterns Patterns normally given as CLI arguments (e.g. `["app/views/**/*.html.slim"]`).
13
- def initialize(patterns:)
14
- @patterns = patterns
15
- end
16
-
17
- # @return [Array<String>]
18
- def call
19
- patterns.flat_map do |pattern|
20
- ::Pathname.glob(pattern).select(&:file?).map(&:to_s)
21
- end.uniq.sort
22
- end
23
-
24
- private
25
-
26
- # @return [Array<String>]
27
- def patterns
28
- if @patterns.empty?
29
- DEFAULT_PATH_PATTERNS
30
- else
31
- @patterns
32
- end
33
- end
34
- end
35
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop'
4
-
5
- module Slimcop
6
- class RuboCopConfigGenerator
7
- DEFAULT_ADDITIONAL_CONFIG_PATH1 = '.slimcop.yml'
8
- DEFAULT_ADDITIONAL_CONFIG_PATH2 = '.rubocop.yml'
9
-
10
- # @param [String] additional_config_file_path
11
- def initialize(additional_config_file_path: nil)
12
- @additional_config_file_path = additional_config_file_path
13
- end
14
-
15
- # @return [RuboCop::Config]
16
- def call
17
- ::RuboCop::ConfigLoader.merge_with_default(merged_config, loaded_path)
18
- end
19
-
20
- private
21
-
22
- # @return [String]
23
- def loaded_path
24
- @additional_config_file_path || slimcop_default_config_file_path
25
- end
26
-
27
- # @return [RuboCop::Config]
28
- def merged_config
29
- ::RuboCop::Config.create(merged_config_hash, loaded_path)
30
- end
31
-
32
- # @return [Hash]
33
- def merged_config_hash
34
- result = slimcop_default_config
35
- result = ::RuboCop::ConfigLoader.merge(result, additional_config) if additional_config
36
- result
37
- end
38
-
39
- # @return [RuboCop::Config, nil]
40
- def additional_config
41
- if instance_variable_defined?(:@additional_config)
42
- @additional_config
43
- else
44
- @additional_config = \
45
- if @additional_config_file_path
46
- ::RuboCop::ConfigLoader.load_file(@additional_config_file_path)
47
- elsif ::File.exist?(DEFAULT_ADDITIONAL_CONFIG_PATH1)
48
- ::RuboCop::ConfigLoader.load_file(DEFAULT_ADDITIONAL_CONFIG_PATH1)
49
- elsif ::File.exist?(DEFAULT_ADDITIONAL_CONFIG_PATH2)
50
- ::RuboCop::ConfigLoader.load_file(DEFAULT_ADDITIONAL_CONFIG_PATH2)
51
- end
52
- end
53
- end
54
-
55
- # @return [RuboCop::Config]
56
- def slimcop_default_config
57
- ::RuboCop::ConfigLoader.load_file(slimcop_default_config_file_path)
58
- end
59
-
60
- # @return [String]
61
- def slimcop_default_config_file_path
62
- @slimcop_default_config_file_path ||= ::File.expand_path('../../default.yml', __dir__)
63
- end
64
- end
65
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Slimcop
4
- # Remove unnecessary part (e.g. `if`, `unless`, `do`, ...) from Ruby code.
5
- class RubyClipper
6
- # @param [String] code
7
- def initialize(code)
8
- @code = code
9
- end
10
-
11
- # @return [Hash]
12
- def call
13
- [
14
- PrecedingKeywordRemover,
15
- TrailingDoRemover
16
- ].each_with_object(
17
- code: @code,
18
- offset: 0
19
- ) do |klass, object|
20
- result = klass.new(object[:code]).call
21
- object[:code] = result[:code]
22
- object[:offset] += result[:offset]
23
- end
24
- end
25
-
26
- class PrecedingKeywordRemover
27
- REGEXP = /
28
- \A
29
- (?:
30
- begin
31
- | case
32
- | else
33
- | elsif
34
- | ensure
35
- | if
36
- | rescue
37
- | unless
38
- | until
39
- | when
40
- | while
41
- | for[ \t]+\w+[ \t]+in
42
- )
43
- [ \t]
44
- /x.freeze
45
-
46
- # @param [String] code
47
- def initialize(code)
48
- @code = code
49
- end
50
-
51
- # @return [Hash]
52
- def call
53
- data = @code.match(REGEXP)
54
- if data
55
- offset = data[0].length
56
- {
57
- code: @code[offset..],
58
- offset: offset
59
- }
60
- else
61
- {
62
- code: @code,
63
- offset: 0
64
- }
65
- end
66
- end
67
- end
68
-
69
- class TrailingDoRemover
70
- REGEXP = /
71
- [ \t]
72
- do
73
- [ \t]*
74
- (\|[^|]*\|)?
75
- [ \t]*
76
- \Z
77
- /x.freeze
78
-
79
- # @param [String] code
80
- def initialize(code)
81
- @code = code
82
- end
83
-
84
- # @return [Hash]
85
- def call
86
- {
87
- code: @code.sub(REGEXP, ''),
88
- offset: 0
89
- }
90
- end
91
- end
92
- end
93
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop'
4
-
5
- module Slimcop
6
- # Collect RuboCop offenses from Ruby code.
7
- class RubyOffenseCollector
8
- # @param [Boolean] auto_correct
9
- # @param [String] file_path
10
- # @param [RuboCop::Config] rubocop_config
11
- # @param [String] source
12
- def initialize(auto_correct:, file_path:, rubocop_config:, source:)
13
- @auto_correct = auto_correct
14
- @file_path = file_path
15
- @rubocop_config = rubocop_config
16
- @source = source
17
- end
18
-
19
- # @return [Array<RuboCop::Cop::Offense>]
20
- def call
21
- # Skip if invalid syntax Ruby code is given. (e.g. "- if a?")
22
- return [] unless rubocop_processed_source.valid_syntax?
23
-
24
- rubocop_team.investigate(rubocop_processed_source).offenses.reject(&:disabled?)
25
- end
26
-
27
- private
28
-
29
- # @return [RuboCop::ProcessedSource]
30
- def rubocop_processed_source
31
- @rubocop_processed_source ||= ::RuboCop::ProcessedSource.new(
32
- @source,
33
- @rubocop_config.target_ruby_version,
34
- @file_path
35
- )
36
- end
37
-
38
- # @return [RuboCop::Cop::Team]
39
- def rubocop_team
40
- ::RuboCop::Cop::Team.new(
41
- ::RuboCop::Cop::Registry.new(::RuboCop::Cop::Cop.all),
42
- @rubocop_config,
43
- auto_correct: @auto_correct,
44
- display_cop_names: true,
45
- extra_details: true,
46
- stdin: ''
47
- )
48
- end
49
- end
50
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'parser'
4
- require 'rubocop/cop/legacy/corrector'
5
-
6
- module Slimcop
7
- # Apply auto-corrections to Slim file.
8
- class SlimCorrector
9
- # @param [String] file_path
10
- # @param [Array<Slimcop::Offense>] offenses
11
- # @param [String] source
12
- def initialize(file_path:, offenses:, source:)
13
- @file_path = file_path
14
- @offenses = offenses
15
- @source = source
16
- end
17
-
18
- # @return [String] Rewritten Slim code.
19
- def call
20
- ::RuboCop::Cop::Legacy::Corrector.new(source_buffer, corrections).rewrite
21
- end
22
-
23
- private
24
-
25
- # @return [Array<Proc>]
26
- def corrections
27
- @offenses.select(&:corrector).map do |offense|
28
- lambda do |corrector|
29
- corrector.import!(offense.corrector, offset: offense.offset)
30
- end
31
- end
32
- end
33
-
34
- # @return [Parser::Source::Buffer]
35
- def source_buffer
36
- ::Parser::Source::Buffer.new(
37
- @file_path,
38
- source: @source
39
- )
40
- end
41
- end
42
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Slimcop
4
- # Collect RuboCop offenses from Slim code.
5
- class SlimOffenseCollector
6
- # @param [Boolean] auto_correct
7
- # @param [String] file_path Slim file path
8
- # @param [RuboCop::Config] rubocop_config
9
- # @param [String] source Slim code
10
- def initialize(auto_correct:, file_path:, rubocop_config:, source:)
11
- @auto_correct = auto_correct
12
- @file_path = file_path
13
- @rubocop_config = rubocop_config
14
- @source = source
15
- end
16
-
17
- # @return [Array<Slimcop::Offense>]
18
- def call
19
- snippets.flat_map do |snippet|
20
- RubyOffenseCollector.new(
21
- auto_correct: @auto_correct,
22
- file_path: @file_path,
23
- rubocop_config: @rubocop_config,
24
- source: snippet[:code]
25
- ).call.map do |rubocop_offense|
26
- Offense.new(
27
- file_path: @file_path,
28
- offset: snippet[:offset],
29
- rubocop_offense: rubocop_offense,
30
- source: @source
31
- )
32
- end
33
- end
34
- end
35
-
36
- private
37
-
38
- # @return [Array<Hash>]
39
- def snippets
40
- RubyExtractor.new(
41
- file_path: @file_path,
42
- source: @source
43
- ).call
44
- end
45
- end
46
- end