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 +4 -4
- data/CHANGELOG.md +14 -2
- data/Gemfile.lock +2 -2
- data/default.yml +3 -0
- data/lib/slimcop/cli.rb +43 -29
- data/lib/slimcop/path_finder.rb +1 -1
- data/lib/slimcop/rubo_cop_config_generator.rb +51 -0
- data/lib/slimcop/version.rb +1 -1
- data/lib/slimcop.rb +1 -1
- metadata +3 -3
- data/lib/slimcop/configuration.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f5970bfa12ccffdb04b26f3b827b8102e035cb95ddd7f6d2ad70f1ff53d240f
|
4
|
+
data.tar.gz: d293f0d5c72e0e96c21f515ed16c6f0dbe9bf0aae745e42cec20186e654922a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
-
|
10
|
-
-
|
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.
|
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.
|
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
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
|
-
|
20
|
-
|
21
|
-
|
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 [
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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 [
|
42
|
-
# @
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
data/lib/slimcop/path_finder.rb
CHANGED
@@ -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
|
data/lib/slimcop/version.rb
CHANGED
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.
|
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-
|
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
|