rfix 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/exe/rfix +11 -90
  3. data/lib/rfix.rb +10 -9
  4. data/lib/rfix/branch/reference.rb +2 -2
  5. data/lib/rfix/branch/upstream.rb +2 -4
  6. data/lib/rfix/cli/command.rb +14 -1
  7. data/lib/rfix/cli/command/all.rb +21 -0
  8. data/lib/rfix/cli/command/base.rb +30 -19
  9. data/lib/rfix/cli/command/branch.rb +2 -0
  10. data/lib/rfix/cli/command/help.rb +2 -0
  11. data/lib/rfix/cli/command/info.rb +6 -1
  12. data/lib/rfix/cli/command/local.rb +2 -0
  13. data/lib/rfix/cli/command/origin.rb +2 -0
  14. data/lib/rfix/cli/command/setup.rb +2 -0
  15. data/lib/rfix/cli/command/status.rb +39 -0
  16. data/lib/rfix/collector.rb +69 -0
  17. data/lib/rfix/diff.rb +69 -0
  18. data/lib/rfix/extension/comment_config.rb +15 -0
  19. data/lib/rfix/extension/offense.rb +17 -14
  20. data/lib/rfix/extension/pastel.rb +7 -4
  21. data/lib/rfix/extension/progresbar.rb +15 -0
  22. data/lib/rfix/extension/strings.rb +10 -2
  23. data/lib/rfix/file.rb +5 -3
  24. data/lib/rfix/file/base.rb +21 -14
  25. data/lib/rfix/file/deleted.rb +2 -0
  26. data/lib/rfix/file/ignored.rb +2 -0
  27. data/lib/rfix/file/null.rb +17 -0
  28. data/lib/rfix/file/tracked.rb +39 -23
  29. data/lib/rfix/file/undefined.rb +17 -0
  30. data/lib/rfix/file/untracked.rb +3 -1
  31. data/lib/rfix/formatter.rb +67 -71
  32. data/lib/rfix/highlighter.rb +1 -3
  33. data/lib/rfix/rake/gemfile.rb +26 -23
  34. data/lib/rfix/repository.rb +59 -96
  35. data/lib/rfix/types.rb +24 -14
  36. data/lib/rfix/version.rb +1 -1
  37. data/rfix.gemspec +11 -3
  38. data/vendor/cli-ui/Gemfile +17 -0
  39. data/vendor/cli-ui/Gemfile.lock +60 -0
  40. data/vendor/cli-ui/LICENSE.txt +21 -0
  41. data/vendor/cli-ui/README.md +224 -0
  42. data/vendor/cli-ui/Rakefile +20 -0
  43. data/vendor/cli-ui/bin/console +14 -0
  44. data/vendor/cli-ui/cli-ui.gemspec +25 -0
  45. data/vendor/cli-ui/dev.yml +14 -0
  46. data/vendor/cli-ui/lib/cli/ui.rb +233 -0
  47. data/vendor/cli-ui/lib/cli/ui/ansi.rb +157 -0
  48. data/vendor/cli-ui/lib/cli/ui/color.rb +84 -0
  49. data/vendor/cli-ui/lib/cli/ui/formatter.rb +192 -0
  50. data/vendor/cli-ui/lib/cli/ui/frame.rb +269 -0
  51. data/vendor/cli-ui/lib/cli/ui/frame/frame_stack.rb +98 -0
  52. data/vendor/cli-ui/lib/cli/ui/frame/frame_style.rb +120 -0
  53. data/vendor/cli-ui/lib/cli/ui/frame/frame_style/box.rb +166 -0
  54. data/vendor/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +139 -0
  55. data/vendor/cli-ui/lib/cli/ui/glyph.rb +84 -0
  56. data/vendor/cli-ui/lib/cli/ui/os.rb +67 -0
  57. data/vendor/cli-ui/lib/cli/ui/printer.rb +59 -0
  58. data/vendor/cli-ui/lib/cli/ui/progress.rb +90 -0
  59. data/vendor/cli-ui/lib/cli/ui/prompt.rb +297 -0
  60. data/vendor/cli-ui/lib/cli/ui/prompt/interactive_options.rb +484 -0
  61. data/vendor/cli-ui/lib/cli/ui/prompt/options_handler.rb +29 -0
  62. data/vendor/cli-ui/lib/cli/ui/spinner.rb +66 -0
  63. data/vendor/cli-ui/lib/cli/ui/spinner/async.rb +40 -0
  64. data/vendor/cli-ui/lib/cli/ui/spinner/spin_group.rb +263 -0
  65. data/vendor/cli-ui/lib/cli/ui/stdout_router.rb +232 -0
  66. data/vendor/cli-ui/lib/cli/ui/terminal.rb +46 -0
  67. data/vendor/cli-ui/lib/cli/ui/truncater.rb +102 -0
  68. data/vendor/cli-ui/lib/cli/ui/version.rb +5 -0
  69. data/vendor/cli-ui/lib/cli/ui/widgets.rb +77 -0
  70. data/vendor/cli-ui/lib/cli/ui/widgets/base.rb +27 -0
  71. data/vendor/cli-ui/lib/cli/ui/widgets/status.rb +61 -0
  72. data/vendor/cli-ui/lib/cli/ui/wrap.rb +56 -0
  73. data/vendor/cli-ui/test/cli/ui/ansi_test.rb +32 -0
  74. data/vendor/cli-ui/test/cli/ui/cli_ui_test.rb +23 -0
  75. data/vendor/cli-ui/test/cli/ui/color_test.rb +40 -0
  76. data/vendor/cli-ui/test/cli/ui/formatter_test.rb +79 -0
  77. data/vendor/cli-ui/test/cli/ui/glyph_test.rb +68 -0
  78. data/vendor/cli-ui/test/cli/ui/printer_test.rb +103 -0
  79. data/vendor/cli-ui/test/cli/ui/progress_test.rb +46 -0
  80. data/vendor/cli-ui/test/cli/ui/prompt/options_handler_test.rb +39 -0
  81. data/vendor/cli-ui/test/cli/ui/prompt_test.rb +348 -0
  82. data/vendor/cli-ui/test/cli/ui/spinner/spin_group_test.rb +39 -0
  83. data/vendor/cli-ui/test/cli/ui/spinner_test.rb +141 -0
  84. data/vendor/cli-ui/test/cli/ui/stdout_router_test.rb +32 -0
  85. data/vendor/cli-ui/test/cli/ui/terminal_test.rb +26 -0
  86. data/vendor/cli-ui/test/cli/ui/truncater_test.rb +31 -0
  87. data/vendor/cli-ui/test/cli/ui/widgets/status_test.rb +49 -0
  88. data/vendor/cli-ui/test/cli/ui/widgets_test.rb +15 -0
  89. data/vendor/cli-ui/test/test_helper.rb +53 -0
  90. data/vendor/cli-ui/tmp/cache/bootsnap/compile-cache/d9/c036af0f3dc494 +0 -0
  91. data/vendor/cli-ui/tmp/cache/bootsnap/load-path-cache +0 -0
  92. data/vendor/dry-cli/lib/dry/cli/command.rb +2 -1
  93. data/vendor/dry-cli/tmp/cache/bootsnap/compile-cache/ff/a22a5daafbd74c +0 -0
  94. data/vendor/dry-cli/tmp/cache/bootsnap/load-path-cache +0 -0
  95. data/vendor/strings-ansi/tmp/cache/bootsnap/compile-cache/79/49cf49407b370e +0 -0
  96. data/vendor/strings-ansi/tmp/cache/bootsnap/load-path-cache +0 -0
  97. metadata +170 -9
  98. data/lib/rfix/extension/string.rb +0 -12
  99. data/lib/rfix/indicator.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66e6b7496f3ebaeaf53eeb228174761dffe2b1aa2a6bb9c2cf1a216dcf8f6ec7
4
- data.tar.gz: 7c9d47278a8d71226afb731d673f31701db9e940b215f75c29055759edc46b08
3
+ metadata.gz: 3a7fa6803ed26d756483ddbebd07a92bb34f485112ea984754eda6ff8af4e18e
4
+ data.tar.gz: bf4954a1f5b938c826ed21390e25f22f6bb3095fd803149c9c977339e24ecd97
5
5
  SHA512:
6
- metadata.gz: 6bbd5525b43116a769b127bf2550ad4aa77ccf3c2f1adec696abf6e8feff46c5a1d6b241bd23bec3c699d3d0dc138a71ea571e5145acd007a57385888d50219f
7
- data.tar.gz: 9cc4eb38f99db4f0a478450dbf9f689a920a002ee20b1ad806d4ee725c3f27db465ac9e85d67a6a6fd47f8787c70e5fbd38f2dfcc8508c25671ad09223fdb3fe
6
+ metadata.gz: 05031f0a115d547614fe9bd3b675c3aba36e1713230b363f67faf726b5971707b4165788b83b3aa911a0bda38faf865bc155ac9c9f553ffe5815ad2dea54defc
7
+ data.tar.gz: ae3b638be3c3423fe57abf01c5665870ec83f9e7fddbac7ec46ea2a5a2cb4c00973983e1f51871c4c2da7aa4ecda9e450141a9a4427687fad1252ca7ecdba317
data/exe/rfix CHANGED
@@ -1,95 +1,16 @@
1
- #!/usr/bin/env -S ruby -W0 --disable-all
1
+ #!/usr/bin/env -S ruby -W0 --disable-all --enable=gems
2
2
  # frozen_string_literal: true
3
3
 
4
- require "rubygems"
5
- require "pathname"
6
- require "bundler"
4
+ require_relative "../lib/rfix"
7
5
 
8
- module Path
9
- HOME = Pathname("~").expand_path
10
- DIR = Pathname(__dir__)
11
- LOCK = "Gemfile.lock"
12
- PWD = Pathname.getwd
13
- PROJECT = DIR.join("..").expand_path
14
- end
15
-
16
- def lock_path
17
- Path::PWD.ascend.find do |path|
18
- return if (path <=> Path::HOME) == -1
19
-
20
- path.join(Path::LOCK).file?
21
- end.join(Path::LOCK)
22
- end
23
-
24
- def find(name, env: Bundler.rubygems)
25
- env.loaded_specs(name) || env.find_name(name).max_by(&:version)
26
- end
27
-
28
- def deactivate(spec)
29
- Gem.loaded_specs.delete(spec.name)
30
-
31
- $LOAD_PATH.reject! do |path|
32
- spec.load_paths.include?(path)
33
- end
34
- end
35
-
36
- def specs
37
- return [] unless (path = lock_path)
38
-
39
- Bundler::LockfileParser.new(path.read).specs
40
- end
41
-
42
- def overlapping_specs
43
- specs.select do |spec|
44
- spec.name.start_with?("rubocop")
45
- end
46
- end
47
-
48
- def rfix
49
- find("rfix")
50
- end
51
-
52
- def dev?
53
- # $PROGRAM_NAME.end_with?("exe/rfix")
54
- false
55
- end
56
-
57
- def rfix_path
58
- return Pathname(__dir__).parent if dev?
59
-
60
- Pathname(rfix.full_gem_path)
61
- end
62
-
63
- def commands
64
- rfix_path.glob("lib/rfix/commands/*.rb").map do |command|
65
- Cri::Command.load_file(command.to_path, infer_name: true)
66
- end
67
- end
68
-
69
- def deactivate_all!
70
- Gem.loaded_specs.each do |_name, spec|
71
- deactivate(spec)
72
- end
73
- end
74
-
75
- deactivate_all!
76
-
77
- require "bundler/inline"
78
- gemfile(false, ui: Bundler::UI::Silent.new) do
79
- overlapping_specs.each do |spec|
80
- gem spec.name, spec.version
81
- end
82
-
83
- path rfix_path do
84
- gem "rfix"
85
- end
86
-
87
- path rfix_path.join("vendor") do
88
- gem "dry-cli", require: "dry/cli"
89
- gem "strings-ansi"
90
- end
91
- end
6
+ require "rubocop"
7
+ require "dry/cli"
8
+ require "rainbow"
92
9
 
93
- module Rfix
94
- Dry::CLI.new(CLI::Command).call
10
+ begin
11
+ exit Rfix::CLI::Command.setup
12
+ rescue Errno::ENOENT, RuboCop::Error => e
13
+ abort [Rainbow("\n==>").red, e.message].join(" ")
14
+ rescue Interrupt
15
+ exit 1
95
16
  end
data/lib/rfix.rb CHANGED
@@ -1,22 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push Pathname(__dir__).join("../vendor/strings-ansi/lib")
4
- $LOAD_PATH.push Pathname(__dir__).join("../vendor/dry-cli/lib")
5
-
6
3
  require "active_support/core_ext/module/attribute_accessors"
7
- require "rubocop-ast"
4
+ require "active_support/core_ext/module/concerning"
8
5
  require "zeitwerk"
9
- require "rubocop"
10
6
 
11
7
  loader = Zeitwerk::Loader.for_gem
12
- loader.ignore("#{__dir__}/rfix/rake/paths")
8
+
13
9
  loader.ignore("#{__dir__}/rfix/rake/support")
14
- loader.ignore("#{__dir__}/rfix/loader")
10
+ loader.ignore("#{__dir__}/rfix/rake/paths")
11
+ loader.ignore("#{__dir__}/rfix/extension")
15
12
  loader.ignore("#{__dir__}/rfix/commands")
16
- loader.ignore("#{__dir__}/rfix/extension/strings")
17
- loader.ignore("#{__dir__}/rfix/extension/pastel")
13
+ loader.ignore("#{__dir__}/rfix/rake")
14
+
18
15
  loader.inflector.inflect "cli" => "CLI"
19
16
 
17
+ loader.on_load("Rfix::Formatter") do
18
+ Pathname(__dir__).glob("rfix/extension/*", &method(:require))
19
+ end
20
+
20
21
  loader.setup
21
22
 
22
23
  module Rfix
@@ -7,8 +7,8 @@ module Rfix
7
7
 
8
8
  def resolve
9
9
  repository.lookup(repository.rev_parse(name).oid)
10
- rescue Rugged::Error, Rugged::InvalidError
11
- raise Error, name
10
+ rescue Rugged::Error, Rugged::InvalidError, Rugged::ReferenceError
11
+ raise Error, "Reference #{name.inspect} not found"
12
12
  end
13
13
  end
14
14
  end
@@ -3,10 +3,8 @@
3
3
  module Rfix
4
4
  module Branch
5
5
  class Upstream < Base
6
- def resolve
7
- repository.rev_parse("@{upstream}")
8
- rescue Rugged::ConfigError
9
- raise Error, "No upstream branch defined"
6
+ def name
7
+ "@{upstream}"
10
8
  end
11
9
 
12
10
  def to_s
@@ -13,7 +13,20 @@ module Rfix
13
13
  register "setup", Setup
14
14
  register "lint", Lint
15
15
  register "info", Info
16
- register "help", Help
16
+ register "all", All
17
+ register "status", Status
18
+
19
+ # register "help", Help
20
+
21
+ def setup
22
+ Dry::CLI.new(self).call
23
+ rescue Error => e
24
+ abort e.message
25
+ else
26
+ exit 0
27
+ end
28
+
29
+ module_function :setup
17
30
  end
18
31
  end
19
32
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rfix
4
+ module CLI
5
+ module Command
6
+ class All < Base
7
+ def call(**params)
8
+ walker = Rugged::Walker.new(Rugged::Repository.discover)
9
+ walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
10
+ walker.push("HEAD")
11
+
12
+ unless oid = walker.each_oid(limit: 1).first
13
+ raise Error, "Repository contains no commits"
14
+ end
15
+
16
+ define(Rfix::Branch::Reference.new(name: oid), **params)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -6,9 +6,6 @@ require "rubocop"
6
6
  require "rainbow"
7
7
  require "rugged"
8
8
 
9
- require "rfix/extension/pastel"
10
- require "rfix/extension/strings"
11
-
12
9
  module Rfix
13
10
  module CLI
14
11
  module Command
@@ -16,29 +13,22 @@ module Rfix
16
13
  include Log
17
14
  include Dry::Core::Constants
18
15
 
19
- class RuboCop::CommentConfig
20
- concerning :Verification, prepend: true do
21
- def cop_enabled_at_line?(_, line)
22
- repository.include?(processed_source.file_path, line)
23
- rescue StandardError => e
24
- abort e.full_message(highlight: true)
25
- end
26
- end
27
- end
28
-
29
16
  option :formatters, type: :array, default: ["Rfix::Formatter"]
30
17
  option :format, type: :string, default: "Rfix::Formatter"
31
18
  option :auto_correct_all, type: :boolean, default: true
32
19
  option :auto_correct, type: :boolean, default: true
20
+ option :parallel, type: :boolean, default: false
33
21
  option :cache, type: :boolean, default: true
34
22
  option :debug, type: :boolean, default: false
35
23
  option :only_recognized_file_types, type: :boolean, default: true
24
+ option :no_cache, type: :boolean, default: false
36
25
  option :force_exclusion, type: :boolean, default: true
37
26
 
38
27
  private
39
28
 
40
29
  def define(reference, args: Undefined, **params)
41
30
  handler = Rfix::Repository.new(
31
+ current_path: Pathname.pwd.relative_path_from(reference.repository.workdir),
42
32
  repository: reference.repository,
43
33
  reference: reference
44
34
  )
@@ -49,15 +39,36 @@ module Rfix
49
39
  end
50
40
  end
51
41
 
52
- config = RuboCop::ConfigStore.new.tap do |config|
53
- config.options_config = RuboCop::ConfigLoader.configuration_file_for(handler.workdir)
42
+ paths = handler.paths
43
+
44
+ variadic_args = Undefined.default(args, EMPTY_ARRAY)
45
+ RuboCop::Options.new.parse(variadic_args).then do |user_defined_options, user_defined_paths|
46
+ params.merge!(user_defined_options)
47
+
48
+ unless user_defined_paths.empty?
49
+ paths.replace(user_defined_paths)
50
+ end
51
+ end
52
+
53
+ config = RuboCop::ConfigStore.new.tap do |config_store|
54
+ RuboCop::ConfigLoader.configuration_file_for(handler.workdir).then do |loader|
55
+ config_store.options_config = loader
56
+ rescue RuboCop::Cop::AmbiguousCopName => e
57
+ abort e.message
58
+ end
54
59
  end
55
60
 
56
- Undefined.default(args, handler.paths).then do |paths|
57
- RuboCop::CLI::Environment.new(params, config, paths)
58
- end.then do |env|
59
- RuboCop::CLI::Command::ExecuteRunner.new(env).run
61
+ if params[:no_cache]
62
+ RuboCop::ResultCache.cleanup(config, true)
63
+ XDG::Config.new.home.then do |cache_path|
64
+ cache_path.rmtree if cache_path.exist?
65
+ end
60
66
  end
67
+
68
+ params.merge!(repository: handler)
69
+
70
+ env = RuboCop::CLI::Environment.new(params, config, paths)
71
+ RuboCop::CLI::Command::ExecuteRunner.new(env).run
61
72
  end
62
73
  end
63
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rfix
2
4
  module CLI
3
5
  module Command
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rfix
2
4
  module CLI
3
5
  module Command
@@ -1,9 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
1
5
  module Rfix
2
6
  module CLI
3
7
  module Command
4
8
  class Info < Base
5
9
  def call(**)
6
- raise NotImplementedError
10
+ puts "Rubocop: #{RuboCop::Version.version}"
11
+ puts "Rfix: #{VERSION}"
7
12
  end
8
13
  end
9
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rfix
2
4
  module CLI
3
5
  module Command
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rfix
2
4
  module CLI
3
5
  module Command
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rfix
2
4
  module CLI
3
5
  module Command
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/all"
4
+ require "tty/tree"
5
+ require "pry"
6
+
7
+ module Rfix
8
+ module CLI
9
+ module Command
10
+ class Status < Base
11
+ def call(**_params)
12
+ walker = Rugged::Walker.new(Rugged::Repository.discover)
13
+ walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
14
+ walker.push("HEAD")
15
+
16
+ unless oid = walker.each_oid(limit: 1).first
17
+ raise Error, "Repository contains no commits"
18
+ end
19
+
20
+ ref = Rfix::Branch::Reference.new(name: oid)
21
+ repo = Repository.new(repository: Rugged::Repository.discover, reference: ref)
22
+ files = repo.permitted
23
+
24
+ pp files.map(&:status).uniq
25
+
26
+ result = files.map do |file|
27
+ file.to_s.split("/").reverse.reduce({}) do |acc, part|
28
+ next { "#{part} (#{file.class}:#{file.status.join(', ')})" => {} } if acc.empty?
29
+
30
+ { part.to_s => acc }
31
+ end
32
+ end.reduce(EMPTY_HASH, :deep_merge)
33
+
34
+ puts TTY::Tree.new({ root: result }).render
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/struct"
4
+
5
+ module Rfix
6
+ class Collector < Dry::Struct
7
+ # https://github.com/libgit2/rugged/blob/master/lib/rugged/tree.rb
8
+ OPTIONS = {
9
+ include_untracked_content: true,
10
+ ignore_whitespace_change: false,
11
+ recurse_untracked_dirs: true,
12
+ ignore_whitespace_eol: false,
13
+ disable_pathspec_match: true,
14
+ include_unmodified: true,
15
+ include_untracked: true,
16
+ ignore_submodules: true,
17
+ include_ignored: false,
18
+ deltas_are_icase: true,
19
+ ignore_filemode: true,
20
+ force_text: true,
21
+ context_lines: 0
22
+ }.freeze
23
+
24
+ attribute :repository, Repository
25
+ attribute :reference, Types::String
26
+
27
+ delegate_missing_to :repository
28
+
29
+ include Enumerable
30
+
31
+ def each(&block)
32
+ construct = lambda do |path, statuses|
33
+ File.call(basename: path, status: statuses, repository: repository)
34
+ end
35
+
36
+ statuses = Hash.new(EMPTY_ARRAY).tap do |statuses|
37
+ repository.status do |path, status|
38
+ statuses[path] = status
39
+ end
40
+ end
41
+
42
+ if repository.head_unborn?
43
+ statuses.each do |path, status|
44
+ (block << construct).call(path, status)
45
+ end
46
+ else
47
+ origin.diff_workdir(**OPTIONS.dup).tap do |diff|
48
+ diff.find_similar!(
49
+ renames_from_rewrites: true,
50
+ renames: true,
51
+ copies: true
52
+ )
53
+ end.each_delta do |delta|
54
+ delta.new_file.fetch(:path).then do |file_path|
55
+ (block << construct).call(file_path, statuses[file_path] + [delta.status])
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def origin
64
+ repository.lookup(repository.rev_parse(reference).oid)
65
+ rescue Rugged::Error, Rugged::InvalidError, Rugged::ReferenceError
66
+ raise Error, "Reference #{reference.inspect} not found"
67
+ end
68
+ end
69
+ end