rubocop_director 0.2.0 → 0.3.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: 06b576908b0f9b2cf1470350c38e53c7339caca11fb7abca712909feac9508f7
4
- data.tar.gz: 2087b4e9a5002c5a2c2294a573426def90556ec98866c07421b67355d928fc24
3
+ metadata.gz: b39e90da2a16a400346bb55cf128eb323ac3feb04a617d43ed791e4b2eb6cfa7
4
+ data.tar.gz: b358b9f928eea4ce911e837837f19ec7be09d4e6467f1601c37f9e34250367dd
5
5
  SHA512:
6
- metadata.gz: c798e0ac5e7b7b53339bc0ec001d5165f4bcbe794952f0a297b70cba7ca5cba1fdffd3ea88395e177c72e5d43bc19afe4f56e02e7b77994e56f4e698d77b0dc1
7
- data.tar.gz: d46b526303bd4930b5a4b4e9d63054d08ae472ed813bb1fbf366ccd08c18f873a8f1e9b1b8cbb7b357abce89face540b22ca66bf406db56f9130a5878d646479
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(RUBOCOP_TODO))
26
+ Success(YAML.load_file(@todo_config_path))
22
27
  rescue Errno::ENOENT
23
- Failure("#{RUBOCOP_TODO} not found, generate it using `rubocop --regenerate-todo`")
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 #{CONFIG_NAME} was preserved.")
34
+ Failure("previous version of #{@director_config_path} was preserved.")
30
35
  end
31
36
 
32
37
  def config_not_exists?
33
- !File.file?(CONFIG_NAME)
38
+ !File.file?(@director_config_path)
34
39
  end
35
40
 
36
41
  def override_config?
37
- puts("#{CONFIG_NAME} already exists, do you want to override it? (y/n)")
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(CONFIG_NAME, {
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 || "1995-01-01"
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(CONFIG_NAME))
35
+ Success(YAML.load_file(@director_config_path))
34
36
  rescue Errno::ENOENT
35
- Failure("#{CONFIG_NAME} not found, generate it using `rubocop-director --generate-config`")
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("./.rubocop.yml"))
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
- arg_parser.parse(args)
10
- @command ||= Commands::Plan.new(@since)
10
+ @options = {}
11
+ arg_parser.parse(args, into: @options)
12
+ verify_options
11
13
  end
12
14
 
13
15
  def perform
14
- @command.run.either(
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.on("--generate-config", "Generate default config based on .rubocop_todo.yml") do |since|
25
- @command = Commands::GenerateConfig.new
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("--since=SINCE", "Specify date to start checking git history") do |since|
29
- @since = since
30
- end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopDirector
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -4,5 +4,7 @@ require "rubocop_director/version"
4
4
  require "rubocop_director/runner"
5
5
 
6
6
  module RubocopDirector
7
- CONFIG_NAME = ".rubocop-director.yml"
7
+ CONFIG_NAME = ".rubocop_director.yml"
8
+ RUBOCOP_CONFIG_NAME = ".rubocop.yml"
9
+ TODO_CONFIG_NAME = ".rubocop_todo.yml"
8
10
  end
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.2.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-06-03 00:00:00.000000000 Z
11
+ date: 2023-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads