rfix 1.0.15 → 1.1.0.pre.147

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rspec +0 -1
  4. data/.rubocop.yml +46 -31
  5. data/.travis.yml +5 -12
  6. data/Gemfile.base +10 -3
  7. data/Gemfile.base.lock +172 -0
  8. data/Gemfile.lock +28 -7
  9. data/Guardfile +1 -1
  10. data/Makefile +4 -13
  11. data/Rakefile +16 -95
  12. data/ci/Gemfile.rubocop-0.80.lock +16 -1
  13. data/ci/Gemfile.rubocop-0.81.lock +16 -1
  14. data/ci/Gemfile.rubocop-0.82.lock +16 -1
  15. data/ci/Gemfile.rubocop-0.83.lock +19 -4
  16. data/ci/Gemfile.rubocop-0.84.lock +19 -4
  17. data/ci/Gemfile.rubocop-0.85.1.lock +19 -4
  18. data/ci/Gemfile.rubocop-0.85.lock +16 -1
  19. data/exe/rfix +18 -144
  20. data/lib/rfix.rb +10 -3
  21. data/lib/rfix/box.rb +112 -0
  22. data/lib/rfix/branch.rb +30 -0
  23. data/lib/rfix/branches/base.rb +29 -0
  24. data/lib/rfix/branches/head.rb +11 -0
  25. data/lib/rfix/branches/main.rb +33 -0
  26. data/lib/rfix/branches/name.rb +21 -0
  27. data/lib/rfix/branches/reference.rb +19 -0
  28. data/lib/rfix/branches/upstream.rb +11 -0
  29. data/lib/rfix/cmd.rb +9 -14
  30. data/lib/rfix/commands/all.rb +26 -0
  31. data/lib/rfix/commands/branch.rb +15 -0
  32. data/lib/rfix/commands/extensions/options.rb +8 -0
  33. data/lib/rfix/commands/help.rb +7 -0
  34. data/lib/rfix/commands/helper/args.rb +137 -0
  35. data/lib/rfix/commands/helper/help.rb +6 -0
  36. data/lib/rfix/commands/helper/loader.rb +6 -0
  37. data/lib/rfix/commands/helper/option.rb +0 -0
  38. data/lib/rfix/commands/helper/params.rb +0 -0
  39. data/lib/rfix/commands/helper/rubocop.rb +17 -0
  40. data/lib/rfix/commands/info.rb +30 -0
  41. data/lib/rfix/commands/lint.rb +23 -0
  42. data/lib/rfix/commands/local.rb +12 -0
  43. data/lib/rfix/commands/origin.rb +19 -0
  44. data/lib/rfix/commands/setup.rb +29 -0
  45. data/lib/rfix/commands/welcome.rb +24 -0
  46. data/lib/rfix/deleted.rb +13 -0
  47. data/lib/rfix/error.rb +2 -0
  48. data/lib/rfix/extensions/extensions.rb +4 -26
  49. data/lib/rfix/extensions/offense.rb +2 -1
  50. data/lib/rfix/extensions/string.rb +8 -0
  51. data/lib/rfix/file.rb +46 -0
  52. data/lib/rfix/file_cache.rb +59 -0
  53. data/lib/rfix/formatter.rb +37 -10
  54. data/lib/rfix/git_helper.rb +13 -1
  55. data/lib/rfix/log.rb +104 -7
  56. data/lib/rfix/no_file.rb +13 -0
  57. data/lib/rfix/rake/paths.rb +50 -0
  58. data/lib/rfix/rake/support.rb +75 -0
  59. data/lib/rfix/repository.rb +201 -0
  60. data/lib/rfix/rfix.rb +7 -198
  61. data/lib/rfix/tracked.rb +76 -0
  62. data/lib/rfix/tracked_file.rb +1 -1
  63. data/lib/rfix/untracked.rb +13 -0
  64. data/lib/rfix/version.rb +1 -1
  65. data/path.rb +7 -0
  66. data/rfix.gemspec +6 -2
  67. data/rugged.rb +206 -0
  68. data/tasks/bump.rake +11 -0
  69. data/tasks/bundle.rake +17 -0
  70. data/tasks/complex.rake +54 -0
  71. data/tasks/simple.rake +58 -0
  72. data/tasks/travis.rake +74 -0
  73. data/tasks/vendor.rake +34 -0
  74. metadata +136 -13
  75. data/file.rb +0 -1
  76. data/lib/rfix/gem_helper.rb +0 -12
  77. data/lib/rfix/git_file.rb +0 -36
  78. data/lib/rfix/rake_helper.rb +0 -56
  79. data/lib/rfix/untracked_file.rb +0 -13
@@ -1,10 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rfix (1.0.8)
4
+ rfix (1.0.20)
5
+ cri (~> 2.15.10)
6
+ listen (~> 3.0)
5
7
  rainbow (~> 3.0)
6
8
  rouge (~> 3.20)
7
9
  rubocop (>= 0.80)
10
+ rugged (~> 1.0.0)
8
11
 
9
12
  GEM
10
13
  remote: https://rubygems.org/
@@ -26,9 +29,11 @@ GEM
26
29
  builder (3.2.4)
27
30
  childprocess (4.0.0)
28
31
  coderay (1.1.3)
32
+ colorize (0.8.1)
29
33
  concurrent-ruby (1.1.6)
30
34
  contracts (0.16.0)
31
- cucumber (4.0.0)
35
+ cri (2.15.10)
36
+ cucumber (4.0.1)
32
37
  builder (~> 3.2, >= 3.2.3)
33
38
  cucumber-core (~> 7.0, >= 7.0.0)
34
39
  cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
@@ -36,14 +41,14 @@ GEM
36
41
  cucumber-html-formatter (~> 6.0, >= 6.0.1)
37
42
  cucumber-messages (~> 12.1, >= 12.1.1)
38
43
  cucumber-wire (~> 3.0, >= 3.0.0)
39
- diff-lcs (~> 1.3, >= 1.3)
44
+ diff-lcs (~> 1.3, >= 1.3, < 1.4)
40
45
  multi_test (~> 0.1, >= 0.1.2)
41
46
  sys-uname (~> 1.0, >= 1.0.2)
42
47
  cucumber-core (7.0.0)
43
48
  cucumber-gherkin (~> 13.0, >= 13.0.0)
44
49
  cucumber-messages (~> 12.1, >= 12.1.1)
45
50
  cucumber-tag-expressions (~> 2.0, >= 2.0.4)
46
- cucumber-cucumber-expressions (10.2.0)
51
+ cucumber-cucumber-expressions (10.2.1)
47
52
  cucumber-gherkin (13.0.0)
48
53
  cucumber-messages (~> 12.0, >= 12.0.0)
49
54
  cucumber-html-formatter (6.0.3)
@@ -56,9 +61,13 @@ GEM
56
61
  cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
57
62
  cucumber-messages (~> 12.1, >= 12.1.1)
58
63
  diff-lcs (1.3)
64
+ faker (2.13.0)
65
+ i18n (>= 1.6, < 2)
59
66
  ffi (1.13.1)
60
67
  formatador (0.2.5)
61
68
  gem-release (2.1.1)
69
+ git (1.7.0)
70
+ rchardet (~> 1.8)
62
71
  guard (2.16.2)
63
72
  formatador (>= 0.2.4)
64
73
  listen (>= 2.7, < 4.0)
@@ -103,6 +112,7 @@ GEM
103
112
  rb-fsevent (0.10.4)
104
113
  rb-inotify (0.10.1)
105
114
  ffi (~> 1.0)
115
+ rchardet (1.8.0)
106
116
  regexp_parser (1.7.1)
107
117
  rexml (3.2.4)
108
118
  rouge (3.20.0)
@@ -131,6 +141,7 @@ GEM
131
141
  rubocop-ast (0.0.3)
132
142
  parser (>= 2.7.0.1)
133
143
  ruby-progressbar (1.10.1)
144
+ rugged (1.0.1)
134
145
  shellany (0.0.1)
135
146
  sys-uname (1.2.1)
136
147
  ffi (>= 1.0.0)
@@ -146,9 +157,13 @@ PLATFORMS
146
157
 
147
158
  DEPENDENCIES
148
159
  aruba (~> 1.0)
160
+ colorize
161
+ faker
149
162
  gem-release
163
+ git (~> 1.7.0)
150
164
  guard
151
165
  guard-rspec
166
+ pry
152
167
  rake (~> 12.3)
153
168
  rfix!
154
169
  rspec (~> 3.0)
@@ -1,10 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rfix (1.0.8)
4
+ rfix (1.0.20)
5
+ cri (~> 2.15.10)
6
+ listen (~> 3.0)
5
7
  rainbow (~> 3.0)
6
8
  rouge (~> 3.20)
7
9
  rubocop (>= 0.80)
10
+ rugged (~> 1.0.0)
8
11
 
9
12
  GEM
10
13
  remote: https://rubygems.org/
@@ -26,8 +29,10 @@ GEM
26
29
  builder (3.2.4)
27
30
  childprocess (4.0.0)
28
31
  coderay (1.1.3)
32
+ colorize (0.8.1)
29
33
  concurrent-ruby (1.1.6)
30
34
  contracts (0.16.0)
35
+ cri (2.15.10)
31
36
  cucumber (4.0.0)
32
37
  builder (~> 3.2, >= 3.2.3)
33
38
  cucumber-core (~> 7.0, >= 7.0.0)
@@ -56,9 +61,13 @@ GEM
56
61
  cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
57
62
  cucumber-messages (~> 12.1, >= 12.1.1)
58
63
  diff-lcs (1.3)
64
+ faker (2.13.0)
65
+ i18n (>= 1.6, < 2)
59
66
  ffi (1.13.1)
60
67
  formatador (0.2.5)
61
68
  gem-release (2.1.1)
69
+ git (1.7.0)
70
+ rchardet (~> 1.8)
62
71
  guard (2.16.2)
63
72
  formatador (>= 0.2.4)
64
73
  listen (>= 2.7, < 4.0)
@@ -103,6 +112,7 @@ GEM
103
112
  rb-fsevent (0.10.4)
104
113
  rb-inotify (0.10.1)
105
114
  ffi (~> 1.0)
115
+ rchardet (1.8.0)
106
116
  regexp_parser (1.7.1)
107
117
  rexml (3.2.4)
108
118
  rouge (3.20.0)
@@ -131,6 +141,7 @@ GEM
131
141
  rubocop-ast (0.0.3)
132
142
  parser (>= 2.7.0.1)
133
143
  ruby-progressbar (1.10.1)
144
+ rugged (1.0.1)
134
145
  shellany (0.0.1)
135
146
  sys-uname (1.2.1)
136
147
  ffi (>= 1.0.0)
@@ -146,9 +157,13 @@ PLATFORMS
146
157
 
147
158
  DEPENDENCIES
148
159
  aruba (~> 1.0)
160
+ colorize
161
+ faker
149
162
  gem-release
163
+ git (~> 1.7.0)
150
164
  guard
151
165
  guard-rspec
166
+ pry
152
167
  rake (~> 12.3)
153
168
  rfix!
154
169
  rspec (~> 3.0)
data/exe/rfix CHANGED
@@ -1,156 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # frozen_string_literal: true
4
-
3
+ require "cri"
5
4
  require "rfix"
5
+ require "rfix/log"
6
6
  require "rubocop"
7
- require "rfix/formatter"
8
- require "cli/ui"
9
-
10
- should_list_files = false
11
- limit_files = false
12
- options = RuboCop::Options.new
13
-
14
- display_help = ARGV.include?("--help")
15
- is_dry = ARGV.include?("--dry")
16
- config_path = false
17
- clear_cache = false
18
-
19
- extend Rfix::Log
20
- Rfix.init!
21
- CLI::UI::StdoutRouter.enable
22
-
23
- if ARGV.include?("--debug")
24
- Rfix.debug!
25
- end
26
-
27
- options.on("--untracked", "Include untracked files") do
28
- Rfix.load_untracked!
29
- end
30
-
31
- options.on("--dry", "No auto correct") do
32
- say "Will run rfix in {{red:read-only}} mode"
33
- Rfix.no_auto_correct!
34
- end
35
-
36
- options.on("--list-files", "List files found by git") do
37
- should_list_files = true
38
- end
39
-
40
- options.on("--clear-cache", "Clear RuboCop cache") do
41
- clear_cache = true
42
- end
7
+ require "rfix/extensions/string"
8
+ require "rfix/commands/extensions/options"
9
+ require "rfix/commands/helper/loader"
10
+ require "rfix/branch"
43
11
 
44
- options.on("--limit-files NUM", Integer, "Limit number of files") do |limit|
45
- limit_files = limit
46
- end
47
-
48
- options.on("--config PATH", "A configuration file") do |path|
49
- config_path = path
50
- end
12
+ include Rfix::Loader
13
+ include Rfix::Log
51
14
 
52
- case cmd = ARGV.shift
53
- when "info"
54
- say "Using RuboCop {{yellow:#{RuboCop::Version.version}}}"
55
- say_debug "Current directory {{italic:#{Dir.pwd}}}"
56
- say_debug "[Ruby] {{italic:#{RbConfig.ruby}}}"
57
- say "Using Rfix {{yellow:#{Rfix::VERSION}}}"
58
- say "Using OS {{yellow:#{Rfix.current_os}}}"
59
- say "Using Git {{yellow:#{Rfix.git_version}}}"
60
- say "Using Ruby {{yellow:#{Rfix.ruby_version}}}"
61
- say_debug "Current Git branch {{yellow:#{Rfix.current_branch}}}"
62
- say_debug "Number of commits {{yellow:#{Rfix.number_of_commits_since}}}"
63
- exit 0
64
- when "lint"
65
- Rfix.lint_mode!
66
- reference = Rfix.ref_since_push
67
- when "local"
68
- reference = Rfix.ref_since_push
69
- when "origin"
70
- reference = Rfix.ref_since_origin
71
- when "welcome"
72
- abort Rfix.thanks
73
- when "all"
74
- reference = false
75
- Rfix.global_enable!
76
- when "branch"
77
- abort_message = "No branch passed as second argument"
78
- unless reference = ARGV.shift
79
- say_abort abort_message
80
- end
81
-
82
- # Catches:
83
- # NOT OK: branch --help
84
- # OK branch master --help
85
- say_abort abort_message if reference.start_with?("--")
86
-
87
- # Check if branch exists
88
- say_abort "Branch {{yellow:#{reference}}} does not exist" unless Rfix.has_branch?(reference)
89
- else
90
- unless display_help
91
- say_error "Valid rfix commands are:"
92
- say_error_sub Rfix.help
93
- exit 1
94
- end
15
+ root = Cri::Command.new
95
16
 
96
- ARGV.unshift(cmd)
17
+ Dir.glob(File.join(__dir__, "../lib/rfix/commands/*.rb")).each do |command|
18
+ root.add_command(Cri::Command.load_file(command, infer_name: true))
97
19
  end
98
20
 
99
21
  begin
100
- options, paths = options.parse(ARGV)
101
- rescue OptionParser::MissingArgument => e
102
- say_abort "[Parser] #{e}"
103
- end
104
-
105
- if path = config_path
106
- Rfix.load_config do |config|
107
- say_debug "[Config:Option] Load from #{path}"
108
- config.options_config = path
109
- end
110
- else
111
- Rfix.load_config do |config|
112
- say_debug "[Config:PWD] Load from #{Dir.pwd}"
113
- config.for(Dir.pwd)
114
- end
115
- end
116
-
117
- if clear_cache
118
- say "Clearing cache"
119
- Rfix.clear_cache!
120
- end
121
-
122
- if ref = reference
123
- say "Compare against {{yellow:#{ref}}}"
124
-
125
- Rfix.load_tracked!(ref)
126
-
127
- paths = Rfix.paths if paths.empty?
128
-
129
- say_exit "No files to run against" if paths.empty?
130
- end
131
-
132
- if limit = limit_files
133
- say "Limit number of files to {{yellow:#{limit}}}"
134
- paths = paths.take(limit)
135
- end
136
-
137
- if should_list_files
138
- say "Loaded {{yellow:#{paths.count}}} paths"
139
- paths.each do |path|
140
- say "\t" + Rfix.to_relative(path: path)
22
+ if root.run(ARGV, {}, hard_exit: false)
23
+ exit 0
24
+ else
25
+ prt root.help
26
+ exit 1
141
27
  end
142
- end
143
-
144
- say_debug "[Config:Dump] #{Rfix.store}"
145
-
146
- env = RuboCop::CLI::Environment.new(
147
- Rfix.config.merge(options),
148
- Rfix.store,
149
- paths
150
- )
151
-
152
- begin
153
- exit RuboCop::CLI::Command::ExecuteRunner.new(env).run
154
- rescue RuboCop::Error => e
155
- say_abort e.message
28
+ rescue RuntimeError => e
29
+ say_abort e.to_s
156
30
  end
@@ -3,22 +3,29 @@
3
3
 
4
4
  # https://gist.github.com/skanev/9d4bec97d5a6825eaaf6
5
5
 
6
- require "rfix/version"
7
6
  require "cli/ui"
7
+ require "rfix/version"
8
+ require "rfix/log"
9
+ require "rfix/cmd"
10
+ require "rfix/repository"
11
+ require "rfix/formatter"
8
12
  require "rfix/extensions/extensions"
9
13
  require "rfix/extensions/offense"
14
+ require "rfix/branch"
10
15
  require "rfix/rfix"
16
+ require "rfix/box"
17
+ require "rfix/error"
11
18
 
12
19
  module Rfix
13
20
  module Ext; end
14
21
  extend self
15
22
  end
16
23
 
17
- RuboCop::Options.prepend(Rfix::Ext::Options)
18
- RuboCop::Runner.prepend(Rfix::Ext::Runner)
19
24
  RuboCop::CommentConfig.prepend(Rfix::Ext::CommentConfig)
20
25
  RuboCop::Cop::Offense.prepend(Rfix::Ext::Offense)
21
26
 
27
+ CLI::UI::StdoutRouter.enable
28
+
22
29
  # TODO: Handle cases where color can't be resolved by CLI::UI
23
30
  RuboCop::Formatter::SimpleTextFormatter::COLOR_FOR_SEVERITY.each do |severity, color|
24
31
  id = RuboCop::Cop::Severity::CODE_TABLE.invert.fetch(severity)
@@ -0,0 +1,112 @@
1
+ class Rfix::Box < Struct.new(:out, :err, :status, :args, :quiet)
2
+ include Rfix::Log
3
+
4
+ def render(color: :reset, debug: false)
5
+ return if Rfix.debug? && !debug
6
+
7
+ @render ||= box(title, color: color) do
8
+ margin do
9
+ prt cmd_lines
10
+ end
11
+
12
+ div("{{info:STDOUT}}") do
13
+ prt lines_or_none(stdout)
14
+ end
15
+
16
+ div("{{error:STDERR}}") do
17
+ prt lines_or_none(stderr)
18
+ end
19
+ end
20
+ end
21
+
22
+ def lines_or_none(lines)
23
+ if lines.join.chomp.empty?
24
+ return "{{italic:<none>}}"
25
+ end
26
+
27
+ lines.map(&method(:strip)).join("\n")
28
+ end
29
+
30
+ def title
31
+ "#{quiet_icon}#{icon} #{bin} (#{exit_status}) @ {{italic:#{pwd}}}"
32
+ end
33
+
34
+ def quiet_icon
35
+ return "" unless quiet
36
+
37
+ "{{warning:[silent]}} "
38
+ end
39
+
40
+ def stdout
41
+ @stdout ||= dumpable(out.lines.map(&:chomp))
42
+ end
43
+
44
+ def stderr
45
+ @stderr ||= dumpable(err.lines.map(&:chomp))
46
+ end
47
+
48
+ def dumpable(lines)
49
+ box = self
50
+ lines.tap do
51
+ lines.define_singleton_method(:dump!) do
52
+ tap do
53
+ box.render
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def icon
60
+ success? ? "{{v}}" : "{{x}}"
61
+ end
62
+
63
+ def success?
64
+ status.success?
65
+ end
66
+
67
+ def bin
68
+ clean_args.first
69
+ end
70
+
71
+ def tail
72
+ clean_args[1..-1]
73
+ end
74
+
75
+ def exit_status
76
+ status.exitstatus
77
+ end
78
+
79
+ def pwd
80
+ if Dir.getwd == Dir.pwd
81
+ return "{{italic:#{Dir.getwd}}}"
82
+ end
83
+
84
+ Dir.getwd.sub(Dir.pwd, "")
85
+ end
86
+
87
+ private
88
+
89
+ def longest_arg
90
+ @longest_arg ||= clean_args.reduce(0) do |acc, arg|
91
+ acc < arg.length ? arg.length : acc
92
+ end
93
+ end
94
+
95
+ def clean_args
96
+ @clean_args ||= args.map(&method(:strip))
97
+ end
98
+
99
+ def rest
100
+ tail.each_slice(2).map do |args|
101
+ args.map do |arg|
102
+ arg.ljust(longest_arg + 5)
103
+ end.join(" ")
104
+ end.map do |tail|
105
+ " {{italic:#{tail}}}"
106
+ end.join("\n")
107
+ end
108
+
109
+ def cmd_lines
110
+ "{{command:$ #{bin} \n#{rest}}}"
111
+ end
112
+ end