slimcop 0.1.0 → 0.5.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: 7d598a52269b8958e493b5b29b175e58d96d122381679e21b5c90c86b2c50d8a
4
- data.tar.gz: 8f45fae7e940bdc8ece0c4ae5575554ba715f6d79e986a9c18fd9893e7c9ff61
3
+ metadata.gz: 294e38d0a479f35dc2d3c6c2c042af57645927ec17cc2b91b6e6c68107defd40
4
+ data.tar.gz: 5f65145f2f89a7fbae3341228bc5d3b2ac8c53c065748ed2dc2e86a1f49d8d95
5
5
  SHA512:
6
- metadata.gz: bbcc157e1514269668fe126bce9f29315cf848ef49208c784877a36fdd00b5d71de538af0474ca76dfdee44c4aa3920167b065bc0f41b65a5948facf04f133b8
7
- data.tar.gz: '009cdacfe8068fcda5c90a172ca49ef0b77db8e965d4700723f6010bbe0fd0b35b5dcbe8f8d7472b79121785961e0997d1a41146b1aeb0eb4c21add9240bb126'
6
+ metadata.gz: cd736f85dafc680f45a77ab81f791620909eda2c23523cf0d7ce4e999587c464946c14a77a2e1853cd4f14da26e9cd2fd17b444ef0d53e031ae38220adef9998
7
+ data.tar.gz: 840ee9ef8e7db1c8fb6590b36c157114784c51c20de7adad8a947fc4df305bb54b838fd63faadcbfafb52f715533effaaa95d5fd408a5be81fea546456dfaf95
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ require:
2
+ - rubocop-rspec
3
+
1
4
  AllCops:
2
5
  NewCops: enable
3
6
  SuggestExtensions: false
@@ -9,5 +12,20 @@ Layout/LineLength:
9
12
  Metrics:
10
13
  Enabled: false
11
14
 
15
+ RSpec/AnyInstance:
16
+ Enabled: false
17
+
18
+ RSpec/ExampleLength:
19
+ Enabled: false
20
+
21
+ RSpec/ImplicitSubject:
22
+ Enabled: false
23
+
24
+ RSpec/MultipleExpectations:
25
+ Enabled: false
26
+
27
+ RSpec/NamedSubject:
28
+ Enabled: false
29
+
12
30
  Style/Documentation:
13
31
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,49 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.5.0 - 2021-12-27
6
+
7
+ ### Changed
8
+
9
+ - Ignore Lint/EmptyFile by default.
10
+ - Ignore Style/RescueModifier by default.
11
+
12
+ ### Fixed
13
+
14
+ - Fix NoMethodError on some RuboCop offenses.
15
+ - Fix bug when uncorrectable RuboCop offense exists.
16
+
17
+ ## 0.4.0 - 2021-12-26
18
+
19
+ ### Added
20
+
21
+ - Support glob pattern on arguments of executable.
22
+
23
+ ### Fixed
24
+
25
+ - Fix bug on parsing invalid syntax Ruby code.
26
+
27
+ ## 0.3.0 - 2021-12-25
28
+
29
+ ### Added
30
+
31
+ - Show Slim file path on Slim syntax error.
32
+
33
+ ### Changed
34
+
35
+ - Require slimi >= 0.4 for :file option handling.
36
+
37
+ ## 0.2.0 - 2021-12-21
38
+
39
+ ### Added
40
+
41
+ - Add --color and --no-color option.
42
+
43
+ ### Changed
44
+
45
+ - Improve offenses CLI output format.
46
+ - Return exit status 1 if any offense found.
47
+
5
48
  ## 0.1.0 - 2021-12-21
6
49
 
7
50
  - Initial release.
data/Gemfile CHANGED
@@ -2,11 +2,9 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in slimcop.gemspec
6
5
  gemspec
7
6
 
8
7
  gem 'rake', '~> 13.0'
9
-
10
- gem 'rspec', '~> 3.0'
11
-
12
- gem 'rubocop', '~> 1.21'
8
+ gem 'rspec'
9
+ gem 'rubocop'
10
+ gem 'rubocop-rspec'
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slimcop (0.1.0)
4
+ slimcop (0.5.0)
5
+ rainbow
5
6
  rubocop (>= 0.87)
6
- slimi (>= 0.1.1)
7
+ slimi (>= 0.4)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -41,8 +42,10 @@ GEM
41
42
  unicode-display_width (>= 1.4.0, < 3.0)
42
43
  rubocop-ast (1.15.0)
43
44
  parser (>= 3.0.1.1)
45
+ rubocop-rspec (2.6.0)
46
+ rubocop (~> 1.19)
44
47
  ruby-progressbar (1.11.0)
45
- slimi (0.1.1)
48
+ slimi (0.4.1)
46
49
  temple
47
50
  temple (0.8.2)
48
51
  unicode-display_width (2.1.0)
@@ -52,8 +55,9 @@ PLATFORMS
52
55
 
53
56
  DEPENDENCIES
54
57
  rake (~> 13.0)
55
- rspec (~> 3.0)
56
- rubocop (~> 1.21)
58
+ rspec
59
+ rubocop
60
+ rubocop-rspec
57
61
  slimcop!
58
62
 
59
63
  BUNDLED WITH
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Slimcop
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/slimcop.svg)](https://rubygems.org/gems/slimcop)
3
4
  [![test](https://github.com/r7kamura/slimcop/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/slimcop/actions/workflows/test.yml)
4
5
 
5
6
  [RuboCop](https://github.com/rubocop/rubocop) runner for [Slim template](https://github.com/slim-template/slim).
@@ -32,4 +33,16 @@ Use `slimcop` executable to check offenses and auto-correct them.
32
33
  $ slimcop --help
33
34
  Usage: slimcop [options] [file1, file2, ...]
34
35
  -a, --auto-correct Auto-correct offenses.
36
+ --[no-]color Force color output on or off.
37
+ ```
38
+
39
+ ### Example
40
+
41
+ ```console
42
+ $ slimcop spec/**/*.slim
43
+
44
+ Offenses:
45
+
46
+ spec/fixtures/dummy.slim:1:3 C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
47
+ spec/fixtures/dummy.slim:3:5 C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
35
48
  ```
data/default.yml CHANGED
@@ -10,6 +10,9 @@ Layout/BlockAlignment:
10
10
  Layout/ClosingParenthesisIndentation:
11
11
  Enabled: false
12
12
 
13
+ Lint/EmptyFile:
14
+ Enabled: false
15
+
13
16
  Layout/EmptyLineAfterGuardClause:
14
17
  Enabled: false
15
18
 
@@ -100,6 +103,9 @@ Style/IfUnlessModifier:
100
103
  Style/Next:
101
104
  Enabled: false
102
105
 
106
+ Style/RescueModifier:
107
+ Enabled: false
108
+
103
109
  Style/WhileUntilDo:
104
110
  Enabled: false
105
111
 
data/lib/slimcop/cli.rb CHANGED
@@ -1,36 +1,71 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'optparse'
4
- require 'rubocop'
3
+ require 'rainbow'
5
4
 
6
5
  module Slimcop
7
6
  class Cli
8
7
  def initialize(argv)
9
8
  @argv = argv.dup
9
+ @configuration = Configuration.new
10
+ @formatter = Formatter.new
10
11
  end
11
12
 
12
13
  def call
13
14
  options = parse!
14
- @argv.each do |slim_file_path|
15
- runner = Runner.new(
16
- file_path: slim_file_path
17
- )
18
- if options[:auto_correct]
19
- ::File.write(
20
- slim_file_path,
21
- runner.auto_correct
22
- )
23
- else
24
- messages = runner.offenses.map do |offense|
25
- offense[:rubocop_offense].message
26
- end
27
- puts messages
28
- end
29
- end
15
+ slim_file_paths = PathFinder.new(patterns: @argv).call
16
+
17
+ Rainbow.enabled = options[:color] if options.key?(:color)
18
+
19
+ offenses_set = investigate(auto_correct: options[:auto_correct], slim_file_paths: slim_file_paths)
20
+ correct(offenses_set) if options[:auto_correct]
21
+ offenses = offenses_set.flat_map { |(_, _, array)| array }
22
+ report(offenses)
23
+ exit(offenses.empty? ? 0 : 1)
30
24
  end
31
25
 
32
26
  private
33
27
 
28
+ # @param [Array] offenses_set
29
+ def correct(offenses_set)
30
+ offenses_set.each do |(file_path, source, offenses)|
31
+ rewritten_source = SlimCorrector.new(
32
+ file_path: file_path,
33
+ offenses: offenses,
34
+ source: source
35
+ ).call
36
+ ::File.write(file_path, rewritten_source)
37
+ end
38
+ end
39
+
40
+ # @param [Boolean] auto_correct
41
+ # @param [Array] slim_file_paths
42
+ # @return [Array]
43
+ def investigate(auto_correct:, slim_file_paths:)
44
+ slim_file_paths.map do |file_path|
45
+ source = ::File.read(file_path)
46
+ offenses = SlimOffenseCollector.new(
47
+ auto_correct: auto_correct,
48
+ file_path: file_path,
49
+ rubocop_config: @configuration.rubocop_config,
50
+ source: source
51
+ ).call
52
+ [file_path, source, offenses]
53
+ end
54
+ end
55
+
56
+ # @param [Array<Slimcop::Offense>] offenses
57
+ def report(offenses)
58
+ result = +''
59
+ unless offenses.empty?
60
+ result << "\nOffenses:\n\n"
61
+ lines = offenses.map do |offense|
62
+ @formatter.format_offense(offense)
63
+ end
64
+ result << lines.join("\n")
65
+ end
66
+ puts(result)
67
+ end
68
+
34
69
  # @return [Hash]
35
70
  def parse!
36
71
  options = {}
@@ -39,6 +74,9 @@ module Slimcop
39
74
  parser.on('-a', '--auto-correct', 'Auto-correct offenses.') do
40
75
  options[:auto_correct] = true
41
76
  end
77
+ parser.on('--[no-]color', 'Force color output on or off.') do |value|
78
+ options[:color] = value
79
+ end
42
80
  parser.parse!(@argv)
43
81
  options
44
82
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module Slimcop
6
+ class Configuration
7
+ # @return [RuboCop::Config]
8
+ def rubocop_config
9
+ @rubocop_config ||= begin
10
+ config_path = ::File.expand_path('../../default.yml', __dir__)
11
+ config = ::RuboCop::ConfigLoader.load_file(config_path)
12
+ ::RuboCop::ConfigLoader.merge_with_default(config, config_path)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+ require 'rainbow'
5
+
6
+ module Slimcop
7
+ # Format String for CLI output.
8
+ class Formatter
9
+ COLOR_FOR_SEVERITY_CODE = {
10
+ convention: :yellow,
11
+ error: :red,
12
+ fatal: :red,
13
+ info: :gray,
14
+ refactor: :yellow,
15
+ warning: :magenta
16
+ }.freeze
17
+
18
+ # @param [Slimcop::Offense] offense
19
+ # @return [String]
20
+ def format_offense(offense)
21
+ format(
22
+ '%<path>s:%<line>d:%<column>d %<severity>s: %<message>s',
23
+ column: offense.real_column,
24
+ line: offense.line,
25
+ message: message(offense),
26
+ path: file_path(offense),
27
+ severity: severity(offense)
28
+ )
29
+ end
30
+
31
+ private
32
+
33
+ # @param [String] path e.g. "./spec/fixtures/dummy.slim"
34
+ # @return [String]
35
+ # @example "spec/fixtures/dummy.slim"
36
+ def canonicalize_path(path)
37
+ ::File.expand_path(path).delete_prefix("#{::Dir.pwd}/")
38
+ end
39
+
40
+ # @param [Slimcop::Offense] offense
41
+ # @return [String]
42
+ def file_path(offense)
43
+ Rainbow(canonicalize_path(offense.file_path)).cyan
44
+ end
45
+
46
+ # @param [Slimcop::Offense] offense
47
+ # @return [String]
48
+ def message(offense)
49
+ "#{status(offense)}#{offense.message}"
50
+ end
51
+
52
+ # @param [Slimcop::Offense] offense
53
+ # @return [String]
54
+ def severity(offense)
55
+ Rainbow(offense.severity.code).color(COLOR_FOR_SEVERITY_CODE[offense.severity.name])
56
+ end
57
+
58
+ # @param [Slimcop::Offense] offense
59
+ # @return [String]
60
+ def status(offense)
61
+ if offense.rubocop_offense.corrected_with_todo?
62
+ Rainbow('[Todo] ').green
63
+ elsif offense.rubocop_offense.corrected?
64
+ Rainbow('[Corrected] ').green
65
+ elsif offense.rubocop_offense.correctable?
66
+ Rainbow('[Correctable] ').yellow
67
+ else
68
+ ''
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'parser'
4
+
5
+ module Slimcop
6
+ class Offense
7
+ # @return [String]
8
+ attr_reader :file_path
9
+
10
+ # @return [Integer]
11
+ attr_reader :offset
12
+
13
+ # @return [RuboCop::Cop::Offense]
14
+ attr_reader :rubocop_offense
15
+
16
+ # @param [Integer] offset
17
+ # @param [RuboCop::Cop::Offense] rubocop_offense
18
+ # @param [String] source Slim code.
19
+ def initialize(file_path:, offset:, rubocop_offense:, source:)
20
+ @file_path = file_path
21
+ @offset = offset
22
+ @rubocop_offense = rubocop_offense
23
+ @source = source
24
+ end
25
+
26
+ # @return [RuboCop::Cop::Corrector]
27
+ def corrector
28
+ @rubocop_offense.corrector
29
+ end
30
+
31
+ # @return [Integer]
32
+ def line
33
+ range.line
34
+ end
35
+
36
+ # @return [String]
37
+ def message
38
+ @rubocop_offense.message
39
+ end
40
+
41
+ # @return [Integer]
42
+ def real_column
43
+ range.column + 1
44
+ end
45
+
46
+ # @return [RuboCop::Cop::Severity]
47
+ def severity
48
+ @rubocop_offense.severity
49
+ end
50
+
51
+ private
52
+
53
+ # @return [Parser::Source::Buffer]
54
+ def buffer
55
+ ::Parser::Source::Buffer.new(
56
+ file_path,
57
+ source: @source
58
+ )
59
+ end
60
+
61
+ # @return [Parser::Source::Range]
62
+ def range
63
+ @range ||= ::Parser::Source::Range.new(
64
+ buffer,
65
+ @rubocop_offense.location.begin_pos + @offset,
66
+ @rubocop_offense.location.end_pos + @offset
67
+ )
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,20 @@
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
+ # @param [Array<String>] patterns Patterns normally given as CLI arguments (e.g. `["app/views/**/*.html.slim"]`).
9
+ def initialize(patterns:)
10
+ @patterns = patterns
11
+ end
12
+
13
+ # @return [Array<String>]
14
+ def call
15
+ @patterns.flat_map do |pattern|
16
+ ::Pathname.glob(pattern).select(&:file?).map(&:to_s)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,8 +5,10 @@ require 'slimi'
5
5
  module Slimcop
6
6
  # Extract codes from Slim source.
7
7
  class RubyExtractor
8
+ # @param [String, nil] file_path
8
9
  # @param [String] source
9
- def initialize(source:)
10
+ def initialize(file_path:, source:)
11
+ @file_path = file_path
10
12
  @source = source
11
13
  end
12
14
 
@@ -26,7 +28,7 @@ module Slimcop
26
28
  # @return [Array] Slim AST, represented in S-expression.
27
29
  def ast
28
30
  ::Slimi::Filters::Interpolation.new.call(
29
- ::Slimi::Parser.new.call(@source)
31
+ ::Slimi::Parser.new(file: @file_path).call(@source)
30
32
  )
31
33
  end
32
34
 
@@ -5,18 +5,21 @@ require 'rubocop'
5
5
  module Slimcop
6
6
  # Collect RuboCop offenses from Ruby code.
7
7
  class RubyOffenseCollector
8
+ # @param [Boolean] auto_correct
8
9
  # @param [String] file_path
9
10
  # @param [RuboCop::Config] rubocop_config
10
11
  # @param [String] source
11
- def initialize(file_path:, rubocop_config:, source:)
12
+ def initialize(auto_correct:, file_path:, rubocop_config:, source:)
13
+ @auto_correct = auto_correct
12
14
  @file_path = file_path
13
15
  @rubocop_config = rubocop_config
14
16
  @source = source
15
17
  end
16
18
 
17
- # @return [Array<RuboCop::Cop::Offense>, nil]
19
+ # @return [Array<RuboCop::Cop::Offense>]
18
20
  def call
19
- return unless rubocop_processed_source.valid_syntax?
21
+ # Skip if invalid syntax Ruby code is given. (e.g. "- if a?")
22
+ return [] unless rubocop_processed_source.valid_syntax?
20
23
 
21
24
  rubocop_team.investigate(rubocop_processed_source).offenses
22
25
  end
@@ -37,7 +40,7 @@ module Slimcop
37
40
  ::RuboCop::Cop::Team.new(
38
41
  ::RuboCop::Cop::Registry.new(::RuboCop::Cop::Cop.all),
39
42
  @rubocop_config,
40
- auto_correct: true,
43
+ auto_correct: @auto_correct,
41
44
  display_cop_names: true,
42
45
  extra_details: true,
43
46
  stdin: ''
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'parser'
3
4
  require 'rubocop/cop/legacy/corrector'
4
5
 
5
6
  module Slimcop
6
7
  # Apply auto-corrections to Slim file.
7
8
  class SlimCorrector
8
9
  # @param [String] file_path
9
- # @param [Array<Hash>] offenses
10
+ # @param [Array<Slimcop::Offense>] offenses
10
11
  # @param [String] source
11
12
  def initialize(file_path:, offenses:, source:)
12
13
  @file_path = file_path
@@ -23,9 +24,9 @@ module Slimcop
23
24
 
24
25
  # @return [Array<Proc>]
25
26
  def corrections
26
- @offenses.map do |offense|
27
+ @offenses.select(&:corrector).map do |offense|
27
28
  lambda do |corrector|
28
- corrector.import!(offense[:rubocop_offense].corrector, offset: offense[:offset])
29
+ corrector.import!(offense.corrector, offset: offense.offset)
29
30
  end
30
31
  end
31
32
  end
@@ -3,27 +3,32 @@
3
3
  module Slimcop
4
4
  # Collect RuboCop offenses from Slim code.
5
5
  class SlimOffenseCollector
6
+ # @param [Boolean] auto_correct
6
7
  # @param [String] file_path Slim file path
7
8
  # @param [RuboCop::Config] rubocop_config
8
9
  # @param [String] source Slim code
9
- def initialize(file_path:, rubocop_config:, source:)
10
+ def initialize(auto_correct:, file_path:, rubocop_config:, source:)
11
+ @auto_correct = auto_correct
10
12
  @file_path = file_path
11
13
  @rubocop_config = rubocop_config
12
14
  @source = source
13
15
  end
14
16
 
15
- # @return [Array<Hash>]
17
+ # @return [Array<Slimcop::Offense>]
16
18
  def call
17
19
  snippets.flat_map do |snippet|
18
20
  RubyOffenseCollector.new(
21
+ auto_correct: @auto_correct,
19
22
  file_path: @file_path,
20
23
  rubocop_config: @rubocop_config,
21
24
  source: snippet[:code]
22
25
  ).call.map do |rubocop_offense|
23
- {
26
+ Offense.new(
27
+ file_path: @file_path,
24
28
  offset: snippet[:begin_],
25
- rubocop_offense: rubocop_offense
26
- }
29
+ rubocop_offense: rubocop_offense,
30
+ source: @source
31
+ )
27
32
  end
28
33
  end
29
34
  end
@@ -32,7 +37,10 @@ module Slimcop
32
37
 
33
38
  # @return [Array<Hash>]
34
39
  def snippets
35
- RubyExtractor.new(source: @source).call
40
+ RubyExtractor.new(
41
+ file_path: @file_path,
42
+ source: @source
43
+ ).call
36
44
  end
37
45
  end
38
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slimcop
4
- VERSION = '0.1.0'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/slimcop.rb CHANGED
@@ -4,9 +4,12 @@ require_relative 'slimcop/version'
4
4
 
5
5
  module Slimcop
6
6
  autoload :Cli, 'slimcop/cli'
7
+ autoload :Configuration, 'slimcop/configuration'
8
+ autoload :Formatter, 'slimcop/formatter'
9
+ autoload :Offense, 'slimcop/offense'
10
+ autoload :PathFinder, 'slimcop/path_finder'
7
11
  autoload :RubyExtractor, 'slimcop/ruby_extractor'
8
12
  autoload :RubyOffenseCollector, 'slimcop/ruby_offense_collector'
9
- autoload :Runner, 'slimcop/runner'
10
13
  autoload :SlimCorrector, 'slimcop/slim_corrector'
11
14
  autoload :SlimOffenseCollector, 'slimcop/slim_offense_collector'
12
15
  end
data/slimcop.gemspec CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  'rubygems_mfa_required' => 'true'
32
32
  }
33
33
 
34
+ spec.add_dependency 'rainbow'
34
35
  spec.add_dependency 'rubocop', '>= 0.87'
35
- spec.add_dependency 'slimi', '>= 0.1.1'
36
+ spec.add_dependency 'slimi', '>= 0.4'
36
37
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.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: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2021-12-26 00:00:00.000000000 Z
12
12
  dependencies:
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rubocop
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,14 +44,14 @@ dependencies:
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 0.1.1
47
+ version: '0.4'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 0.1.1
54
+ version: '0.4'
41
55
  description:
42
56
  email:
43
57
  - r7kamura@gmail.com
@@ -61,9 +75,12 @@ files:
61
75
  - exe/slimcop
62
76
  - lib/slimcop.rb
63
77
  - lib/slimcop/cli.rb
78
+ - lib/slimcop/configuration.rb
79
+ - lib/slimcop/formatter.rb
80
+ - lib/slimcop/offense.rb
81
+ - lib/slimcop/path_finder.rb
64
82
  - lib/slimcop/ruby_extractor.rb
65
83
  - lib/slimcop/ruby_offense_collector.rb
66
- - lib/slimcop/runner.rb
67
84
  - lib/slimcop/slim_corrector.rb
68
85
  - lib/slimcop/slim_offense_collector.rb
69
86
  - lib/slimcop/version.rb
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop'
4
-
5
- module Slimcop
6
- # Report offenses in Slim file, and apply auto-corrections if required.
7
- class Runner
8
- # @param [String] file_path
9
- def initialize(file_path:)
10
- @file_path = file_path
11
- end
12
-
13
- # @return [Array<Hash>]
14
- def offenses
15
- @offenses ||= SlimOffenseCollector.new(
16
- file_path: @file_path,
17
- rubocop_config: rubocop_config,
18
- source: source
19
- ).call
20
- end
21
-
22
- def auto_correct
23
- SlimCorrector.new(
24
- file_path: @file_path,
25
- offenses: offenses,
26
- source: source
27
- ).call
28
- end
29
-
30
- private
31
-
32
- # @return [RuboCop::Config]
33
- def rubocop_config
34
- config_path = ::File.expand_path('../../default.yml', __dir__)
35
- config = ::RuboCop::ConfigLoader.load_file(config_path)
36
- ::RuboCop::ConfigLoader.merge_with_default(config, config_path)
37
- end
38
-
39
- # @return [Array<Hash>]
40
- def snippets
41
- RubyExtractor.new(source: source).call
42
- end
43
-
44
- # @return [String]
45
- def source
46
- ::File.read(@file_path)
47
- end
48
- end
49
- end