rubocop_director 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/rubocop_director/commands/generate_config.rb +12 -7
- data/lib/rubocop_director/commands/plan.rb +7 -5
- data/lib/rubocop_director/rubocop_stats.rb +5 -1
- data/lib/rubocop_director/runner.rb +38 -8
- data/lib/rubocop_director/version.rb +1 -1
- data/lib/rubocop_director.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b39e90da2a16a400346bb55cf128eb323ac3feb04a617d43ed791e4b2eb6cfa7
|
4
|
+
data.tar.gz: b358b9f928eea4ce911e837837f19ec7be09d4e6467f1601c37f9e34250367dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2222f3a7fe1c71f335356877a6d8b9714e7ab54f787575d7cebdbd5009658aeeeac7778f6617044abe1d3f4796627c08e0fb91106bf27b2204e2c3541821b4d2
|
7
|
+
data.tar.gz: 4d090d5d404844a7b6c8b3dca91e34589bcf5f2f5585b8bf580bcbf759796af4ec6c53a7c6ae382e255a892ef0f3f3116aeadba471a32c974dedc58e1d0266aa
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.3.0 (2023-06-03)
|
6
|
+
|
7
|
+
- [PR #12](https://github.com/DmitryTsepelev/rubocop_director/pull/12) Added option to pass configs as args for all config files ([@samarthkathal][])
|
8
|
+
|
5
9
|
## 0.2.0 (2023-06-03)
|
6
10
|
|
7
11
|
- [PR #13](https://github.com/DmitryTsepelev/rubocop_director/pull/13) Prettify output formatter and change stats calculation algorithm ([@DmitryTsepelev][])
|
@@ -8,6 +8,11 @@ module RubocopDirector
|
|
8
8
|
|
9
9
|
RUBOCOP_TODO = ".rubocop_todo.yml"
|
10
10
|
|
11
|
+
def initialize(director_config:)
|
12
|
+
@director_config_path = director_config
|
13
|
+
@todo_config_path = TODO_CONFIG_NAME
|
14
|
+
end
|
15
|
+
|
11
16
|
def run
|
12
17
|
rubocop_todo = yield load_config
|
13
18
|
yield check_config_already_exists
|
@@ -18,30 +23,30 @@ module RubocopDirector
|
|
18
23
|
private
|
19
24
|
|
20
25
|
def load_config
|
21
|
-
Success(YAML.load_file(
|
26
|
+
Success(YAML.load_file(@todo_config_path))
|
22
27
|
rescue Errno::ENOENT
|
23
|
-
Failure("#{
|
28
|
+
Failure("#{@todo_config_path} not found, generate it using `rubocop --regenerate-todo`")
|
24
29
|
end
|
25
30
|
|
26
31
|
def check_config_already_exists
|
27
32
|
return Success() if config_not_exists? || override_config?
|
28
33
|
|
29
|
-
Failure("previous version of #{
|
34
|
+
Failure("previous version of #{@director_config_path} was preserved.")
|
30
35
|
end
|
31
36
|
|
32
37
|
def config_not_exists?
|
33
|
-
!File.file?(
|
38
|
+
!File.file?(@director_config_path)
|
34
39
|
end
|
35
40
|
|
36
41
|
def override_config?
|
37
|
-
puts("#{
|
38
|
-
gets.chomp == "y"
|
42
|
+
puts("#{@director_config_path} already exists, do you want to override it? (y/n)")
|
43
|
+
$stdin.gets.chomp == "y"
|
39
44
|
end
|
40
45
|
|
41
46
|
def create_config(rubocop_todo)
|
42
47
|
weights = rubocop_todo.keys.to_h { |key| [key, 1] }
|
43
48
|
|
44
|
-
File.write(
|
49
|
+
File.write(@director_config_path, {
|
45
50
|
"update_weight" => 1,
|
46
51
|
"default_cop_weight" => 1,
|
47
52
|
"weights" => weights
|
@@ -14,8 +14,10 @@ module RubocopDirector
|
|
14
14
|
include Dry::Monads[:result]
|
15
15
|
include Dry::Monads::Do.for(:run)
|
16
16
|
|
17
|
-
def initialize(since)
|
18
|
-
@since = since
|
17
|
+
def initialize(director_config:, rubocop_config:, since: "1995-01-01")
|
18
|
+
@since = since.to_s
|
19
|
+
@director_config_path = director_config
|
20
|
+
@rubocop_config_path = rubocop_config
|
19
21
|
end
|
20
22
|
|
21
23
|
def run
|
@@ -30,14 +32,14 @@ module RubocopDirector
|
|
30
32
|
private
|
31
33
|
|
32
34
|
def load_config
|
33
|
-
Success(YAML.load_file(
|
35
|
+
Success(YAML.load_file(@director_config_path))
|
34
36
|
rescue Errno::ENOENT
|
35
|
-
Failure("#{
|
37
|
+
Failure("#{@director_config_path} not found, generate it using `rubocop-director --generate-config`")
|
36
38
|
end
|
37
39
|
|
38
40
|
def load_rubocop_json
|
39
41
|
puts "💡 Running rubocop to get the list of offences to fix..."
|
40
|
-
RubocopStats.new.fetch
|
42
|
+
RubocopStats.new(@rubocop_config_path).fetch
|
41
43
|
end
|
42
44
|
|
43
45
|
def load_git_stats
|
@@ -11,6 +11,10 @@ module RubocopDirector
|
|
11
11
|
|
12
12
|
TEMP_CONFIG_PATH = "./.temp_rubocop.yml"
|
13
13
|
|
14
|
+
def initialize(rubocop_path)
|
15
|
+
@rubocop_path = rubocop_path
|
16
|
+
end
|
17
|
+
|
14
18
|
def fetch
|
15
19
|
config = yield load_config
|
16
20
|
yield generate_temp_rubocop_config_without_todo(initial_config: config)
|
@@ -24,7 +28,7 @@ module RubocopDirector
|
|
24
28
|
private
|
25
29
|
|
26
30
|
def load_config
|
27
|
-
Success(YAML.load_file(
|
31
|
+
Success(YAML.load_file(@rubocop_path))
|
28
32
|
rescue Errno::ENOENT
|
29
33
|
Failure("unable to load rubocop config. Please ensure .rubocop.yml file is present at your project's root directory")
|
30
34
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "optparse"
|
2
|
+
require "optparse/date"
|
2
3
|
|
3
4
|
require_relative "commands/generate_config"
|
4
5
|
require_relative "commands/plan"
|
@@ -6,12 +7,13 @@ require_relative "commands/plan"
|
|
6
7
|
module RubocopDirector
|
7
8
|
class Runner
|
8
9
|
def initialize(args)
|
9
|
-
|
10
|
-
|
10
|
+
@options = {}
|
11
|
+
arg_parser.parse(args, into: @options)
|
12
|
+
verify_options
|
11
13
|
end
|
12
14
|
|
13
15
|
def perform
|
14
|
-
|
16
|
+
command.run.either(
|
15
17
|
->(success_message) { puts success_message },
|
16
18
|
->(failure_message) { puts "\nFailure: #{failure_message}" }
|
17
19
|
)
|
@@ -19,15 +21,43 @@ module RubocopDirector
|
|
19
21
|
|
20
22
|
private
|
21
23
|
|
24
|
+
def verify_options
|
25
|
+
@options[:rubocop_config] = verified_path(config_name: RUBOCOP_CONFIG_NAME, path: @options[:rubocop_config])
|
26
|
+
@options[:director_config] = verified_path(config_name: CONFIG_NAME, path: @options[:director_config])
|
27
|
+
end
|
28
|
+
|
29
|
+
def verified_path(config_name:, path:)
|
30
|
+
path = project_root if path.nil?
|
31
|
+
path.directory? ? path + config_name : path
|
32
|
+
end
|
33
|
+
|
34
|
+
def project_root
|
35
|
+
return Rails.root if defined?(Rails)
|
36
|
+
return Bundler.root if defined?(Bundler)
|
37
|
+
|
38
|
+
Pathname.new(Dir.pwd)
|
39
|
+
end
|
40
|
+
|
41
|
+
def command
|
42
|
+
@command ||= if @options[:generate_config]
|
43
|
+
Commands::GenerateConfig.new(**@options.slice(:director_config))
|
44
|
+
else
|
45
|
+
Commands::Plan.new(**@options.slice(:since, :director_config, :rubocop_config))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
22
49
|
def arg_parser
|
23
50
|
OptionParser.new do |p|
|
24
|
-
p.
|
25
|
-
|
51
|
+
p.accept(Pathname) do |s|
|
52
|
+
Pathname.new(s)
|
53
|
+
rescue ArgumentError, TypeError
|
54
|
+
raise OptionParser::InvalidArgument, s
|
26
55
|
end
|
27
56
|
|
28
|
-
p.on("--
|
29
|
-
|
30
|
-
|
57
|
+
p.on("--generate_config", "Generate default config based on .rubocop_todo.yml")
|
58
|
+
p.on("--since=SINCE", Date, "Specify date to start checking git history")
|
59
|
+
p.on("--director_config=PATH", Pathname, "Specify path where .rubocop_director.yml config must be read from OR written to, default path: {PROJECTROOT}/.rubocop_director.yml")
|
60
|
+
p.on("--rubocop_config=PATH", Pathname, "Specify path where .rubocop.yml config must be read from, default path: {PROJECTROOT}/.rubocop.yml")
|
31
61
|
|
32
62
|
p.on("--help", "Prints this help") do
|
33
63
|
puts p
|
data/lib/rubocop_director.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop_director
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|