slimcop 0.5.0 → 0.6.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: 294e38d0a479f35dc2d3c6c2c042af57645927ec17cc2b91b6e6c68107defd40
4
- data.tar.gz: 5f65145f2f89a7fbae3341228bc5d3b2ac8c53c065748ed2dc2e86a1f49d8d95
3
+ metadata.gz: 8f5970bfa12ccffdb04b26f3b827b8102e035cb95ddd7f6d2ad70f1ff53d240f
4
+ data.tar.gz: d293f0d5c72e0e96c21f515ed16c6f0dbe9bf0aae745e42cec20186e654922a0
5
5
  SHA512:
6
- metadata.gz: cd736f85dafc680f45a77ab81f791620909eda2c23523cf0d7ce4e999587c464946c14a77a2e1853cd4f14da26e9cd2fd17b444ef0d53e031ae38220adef9998
7
- data.tar.gz: 840ee9ef8e7db1c8fb6590b36c157114784c51c20de7adad8a947fc4df305bb54b838fd63faadcbfafb52f715533effaaa95d5fd408a5be81fea546456dfaf95
6
+ metadata.gz: b2423cffaf849c867d335df2d3fec06645f5578aecc9597a9d218d5cc99989a86be664609b364c6092695ad391825ce9ff244387d3dd6d77710d5c820d02d5f1
7
+ data.tar.gz: 294f4adb1bc4e8198a2d0b6fb79b810561a57a90fb01ebcfdfe0d3d057278e67ca3c8f77c5063b1bbadb55c36e84b7363db4b39d3004de2d7884f1afcb5f6cca
data/CHANGELOG.md CHANGED
@@ -2,12 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.6.0 - 2021-12-28
6
+
7
+ ### Added
8
+
9
+ - Add -c, --config CLI option to customize RuboCop config.
10
+
11
+ ### Changed
12
+
13
+ - Not investigate all files then auto-correct them, but do it for each file.
14
+ - Sort processed files in alphabetical order.
15
+ - Disable Lint/UselessAssignment by default.
16
+
5
17
  ## 0.5.0 - 2021-12-27
6
18
 
7
19
  ### Changed
8
20
 
9
- - Ignore Lint/EmptyFile by default.
10
- - Ignore Style/RescueModifier by default.
21
+ - Disable Lint/EmptyFile by default.
22
+ - Disable Style/RescueModifier by default.
11
23
 
12
24
  ### Fixed
13
25
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slimcop (0.5.0)
4
+ slimcop (0.6.0)
5
5
  rainbow
6
6
  rubocop (>= 0.87)
7
7
  slimi (>= 0.4)
@@ -45,7 +45,7 @@ GEM
45
45
  rubocop-rspec (2.6.0)
46
46
  rubocop (~> 1.19)
47
47
  ruby-progressbar (1.11.0)
48
- slimi (0.4.1)
48
+ slimi (0.4.2)
49
49
  temple
50
50
  temple (0.8.2)
51
51
  unicode-display_width (2.1.0)
data/default.yml CHANGED
@@ -79,6 +79,9 @@ Layout/TrailingEmptyLines:
79
79
  Layout/TrailingWhitespace:
80
80
  Enabled: false
81
81
 
82
+ Lint/UselessAssignment:
83
+ Enabled: false
84
+
82
85
  Lint/Void:
83
86
  Enabled: false
84
87
 
data/lib/slimcop/cli.rb CHANGED
@@ -6,51 +6,62 @@ module Slimcop
6
6
  class Cli
7
7
  def initialize(argv)
8
8
  @argv = argv.dup
9
- @configuration = Configuration.new
10
9
  @formatter = Formatter.new
11
10
  end
12
11
 
13
12
  def call
14
13
  options = parse!
15
- slim_file_paths = PathFinder.new(patterns: @argv).call
16
-
17
14
  Rainbow.enabled = options[:color] if options.key?(:color)
15
+ rubocop_config = RuboCopConfigGenerator.new(additional_config_file_path: options[:additional_config_file_path]).call
16
+ file_paths = PathFinder.new(patterns: @argv).call
18
17
 
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 }
18
+ offenses = file_paths.flat_map do |file_path|
19
+ source = ::File.read(file_path)
20
+ offenses_ = investigate(
21
+ auto_correct: options[:auto_correct],
22
+ file_path: file_path,
23
+ rubocop_config: rubocop_config,
24
+ source: source
25
+ )
26
+ if options[:auto_correct]
27
+ correct(
28
+ file_path: file_path,
29
+ offenses: offenses_,
30
+ source: source
31
+ )
32
+ end
33
+ offenses_
34
+ end
22
35
  report(offenses)
23
36
  exit(offenses.empty? ? 0 : 1)
24
37
  end
25
38
 
26
39
  private
27
40
 
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
41
+ # @param [String] file_path
42
+ # @param [Array<Slimcop::Offense>] offenses
43
+ # @param [String] source
44
+ def correct(file_path:, offenses:, source:)
45
+ rewritten_source = SlimCorrector.new(
46
+ file_path: file_path,
47
+ offenses: offenses,
48
+ source: source
49
+ ).call
50
+ ::File.write(file_path, rewritten_source)
38
51
  end
39
52
 
40
53
  # @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
+ # @param [String] file_path
55
+ # @param [String] rubocop_config
56
+ # @param [String] source
57
+ # @return [Array<Slimcop::Offense>]
58
+ def investigate(auto_correct:, file_path:, rubocop_config:, source:)
59
+ SlimOffenseCollector.new(
60
+ auto_correct: auto_correct,
61
+ file_path: file_path,
62
+ rubocop_config: rubocop_config,
63
+ source: source
64
+ ).call
54
65
  end
55
66
 
56
67
  # @param [Array<Slimcop::Offense>] offenses
@@ -74,6 +85,9 @@ module Slimcop
74
85
  parser.on('-a', '--auto-correct', 'Auto-correct offenses.') do
75
86
  options[:auto_correct] = true
76
87
  end
88
+ parser.on('-c', '--config=', 'Specify configuration file.') do |file_path|
89
+ options[:additional_config_file_path] = file_path
90
+ end
77
91
  parser.on('--[no-]color', 'Force color output on or off.') do |value|
78
92
  options[:color] = value
79
93
  end
@@ -14,7 +14,7 @@ module Slimcop
14
14
  def call
15
15
  @patterns.flat_map do |pattern|
16
16
  ::Pathname.glob(pattern).select(&:file?).map(&:to_s)
17
- end
17
+ end.sort
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module Slimcop
6
+ class RuboCopConfigGenerator
7
+ # @param [String] additional_config_file_path
8
+ def initialize(additional_config_file_path: nil)
9
+ @additional_config_file_path = additional_config_file_path
10
+ end
11
+
12
+ # @return [RuboCop::Config]
13
+ def call
14
+ ::RuboCop::ConfigLoader.merge_with_default(merged_config, loaded_path)
15
+ end
16
+
17
+ private
18
+
19
+ # @return [String]
20
+ def loaded_path
21
+ @additional_config_file_path || slimcop_default_config_file_path
22
+ end
23
+
24
+ # @return [RuboCop::Config]
25
+ def merged_config
26
+ ::RuboCop::Config.create(merged_config_hash, loaded_path)
27
+ end
28
+
29
+ # @return [Hash]
30
+ def merged_config_hash
31
+ result = slimcop_default_config
32
+ result = ::RuboCop::ConfigLoader.merge(result, additional_config) if @additional_config_file_path
33
+ result
34
+ end
35
+
36
+ # @return [RuboCop::Config, nil]
37
+ def additional_config
38
+ ::RuboCop::ConfigLoader.load_file(@additional_config_file_path) if @additional_config_file_path
39
+ end
40
+
41
+ # @return [RuboCop::Config]
42
+ def slimcop_default_config
43
+ ::RuboCop::ConfigLoader.load_file(slimcop_default_config_file_path)
44
+ end
45
+
46
+ # @return [String]
47
+ def slimcop_default_config_file_path
48
+ @slimcop_default_config_file_path ||= ::File.expand_path('../../default.yml', __dir__)
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slimcop
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/slimcop.rb CHANGED
@@ -4,10 +4,10 @@ require_relative 'slimcop/version'
4
4
 
5
5
  module Slimcop
6
6
  autoload :Cli, 'slimcop/cli'
7
- autoload :Configuration, 'slimcop/configuration'
8
7
  autoload :Formatter, 'slimcop/formatter'
9
8
  autoload :Offense, 'slimcop/offense'
10
9
  autoload :PathFinder, 'slimcop/path_finder'
10
+ autoload :RuboCopConfigGenerator, 'slimcop/rubo_cop_config_generator'
11
11
  autoload :RubyExtractor, 'slimcop/ruby_extractor'
12
12
  autoload :RubyOffenseCollector, 'slimcop/ruby_offense_collector'
13
13
  autoload :SlimCorrector, 'slimcop/slim_corrector'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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-26 00:00:00.000000000 Z
11
+ date: 2021-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -75,10 +75,10 @@ files:
75
75
  - exe/slimcop
76
76
  - lib/slimcop.rb
77
77
  - lib/slimcop/cli.rb
78
- - lib/slimcop/configuration.rb
79
78
  - lib/slimcop/formatter.rb
80
79
  - lib/slimcop/offense.rb
81
80
  - lib/slimcop/path_finder.rb
81
+ - lib/slimcop/rubo_cop_config_generator.rb
82
82
  - lib/slimcop/ruby_extractor.rb
83
83
  - lib/slimcop/ruby_offense_collector.rb
84
84
  - lib/slimcop/slim_corrector.rb
@@ -1,16 +0,0 @@
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