rfix 1.0.7.pre.66 → 1.0.8.pre.109

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require "bundler"
2
+
3
+ module GemHelper
4
+ def source_for(name:, &block)
5
+ bundle_root = Bundler.bundle_path.join('bundler/gems')
6
+ path = Dir.glob(bundle_root.join("#{name}-*").to_s).first
7
+ path or raise "Could not find source for #{name}, run bundle install first"
8
+ block(path)
9
+ rescue StandardError => e
10
+ puts "[Bundler] #{e}"
11
+ end
12
+ end
@@ -9,8 +9,20 @@ module Rfix::GitHelper
9
9
  include Rfix::Log
10
10
  include Rfix::Cmd
11
11
 
12
- def git(*args, &block)
13
- cmd("git", *args, &block)
12
+ def git(*args, root: Dir.pwd, quiet: false, &block)
13
+ args.unshift *["--git-dir", File.join(root, ".git")]
14
+ args.unshift *["--work-tree", root]
15
+ cmd("git", *args, quiet: quiet, &block)
16
+ end
17
+
18
+ def has_branch?(branch)
19
+ cmd_succeeded?("git", "cat-file", "-t", branch)
20
+ end
21
+
22
+ def dirty?(path)
23
+ Dir.chdir(path) do
24
+ !cmd_succeeded?("git diff --quiet")
25
+ end
14
26
  end
15
27
 
16
28
  def params
@@ -28,3 +40,8 @@ module Rfix::GitHelper
28
40
  ]
29
41
  end
30
42
  end
43
+
44
+ # TODO: Rename above to just ::Git
45
+ module Rfix::Git
46
+ extend Rfix::GitHelper
47
+ end
@@ -13,11 +13,13 @@ module Rfix::Log
13
13
  end
14
14
 
15
15
  def say_error_sub(message)
16
- CLI::UI.puts("#{message}")
16
+ CLI::UI.puts(message.to_s)
17
17
  end
18
18
 
19
19
  def say_debug(message)
20
- CLI::UI.puts("{{*}} #{message}")
20
+ unless Rfix.debug?
21
+ CLI::UI.puts("{{*}} [{{info:Debug}}] #{message}")
22
+ end
21
23
  end
22
24
 
23
25
  def say_abort(message)
@@ -0,0 +1,56 @@
1
+ require "tmpdir"
2
+
3
+ module RakeHelper
4
+ include Rfix::Log
5
+ include Rfix::Cmd
6
+ include Rfix::GitHelper
7
+
8
+ def dirty?
9
+ !cmd_succeeded?("git diff --quiet")
10
+ end
11
+
12
+ def clone(github:, ref:)
13
+ Dir.mktmpdir(github.split("/")) do |src|
14
+ say "Clone {{info:#{github}}}, hold on ..."
15
+ git("clone", "https://github.com/#{github}", src)
16
+ Dir.chdir(src) do
17
+ say "Check out {{info:#{ref}}}"
18
+ git("reset", "--hard", ref)
19
+ git("clean", "-f", "-d")
20
+ end
21
+
22
+ dest = File.join("vendor", github)
23
+ say "Copy files to {{info:#{dest}}}"
24
+ FileUtils.mkdir_p(dest)
25
+ FileUtils.copy_entry(src, dest, true, true, true)
26
+ end
27
+ end
28
+
29
+ def gemfiles
30
+ Dir.glob("ci/Gemfile*").unshift("Gemfile").reject do |path|
31
+ [".lock", ".base"].include?(File.extname(path))
32
+ end
33
+ end
34
+
35
+ def gemlocks
36
+ Dir.glob("ci/Gemfile*.lock").unshift("Gemfile.lock")
37
+ end
38
+
39
+ def source_for(name:)
40
+ bundle_root = Bundler.bundle_path.join('bundler/gems')
41
+ path = Dir.glob(bundle_root.join("#{name}-*").to_s).first
42
+ path or raise "Could not find source for #{name}, run bundle install first"
43
+ end
44
+
45
+ def dest_for(name:)
46
+ File.join(__dir__, 'vendor', name)
47
+ end
48
+
49
+ def osx?
50
+ ENV.fetch("TRAVIS_OS_NAME") == "osx"
51
+ end
52
+
53
+ def brew_url(ref:)
54
+ "https://raw.githubusercontent.com/Homebrew/homebrew-core/#{ref}/Formula/git.rb"
55
+ end
56
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Layout/LineLength
4
+
3
5
  require "rubocop"
4
6
  require "optparse"
5
7
  require "rbconfig"
@@ -13,6 +15,82 @@ module Rfix
13
15
  include GitHelper
14
16
  include Log
15
17
 
18
+ def thanks
19
+ tx = []
20
+ tx << "\n{{v}} Thank you for installing {{green:rfix v#{Rfix::VERSION}}}!\n"
21
+ tx << "{{i}} Run {{command:rfix}} for avalible commands or any of the following to get started:"
22
+ tx << ""
23
+ # tx << "Here are a few examples that might be useful:"
24
+ indent = " " * 3
25
+ tx << "#{indent}{{command:rfix local}} {{italic:# Auto-fixes commits not yet pushed to upstream}}"
26
+ tx << "#{indent}{{command:rfix origin}} {{italic:# Auto-fixes commits between HEAD and origin branch}}"
27
+ tx << "#{indent}{{command:rfix lint}} {{italic:# Lints commits and untracked files not yet pushed to upstream}}"
28
+ tx << ""
29
+ tx << "{{*}} {{bold:ProTip:}} Append {{command:--dry}} to run {{command:rfix}} in read-only mode"
30
+ tx << ""
31
+ tx << "{{i}} {{bold:Issues}} {{italic:https://github.com/oleander/rfix-rb/issues}}"
32
+ tx << "{{i}} {{bold:Readme}} {{italic:https://github.com/oleander/rfix-rb/blob/master/README.md}}"
33
+ tx << "{{i}} {{bold:Travis}} {{italic:https://travis-ci.org/github/oleander/rfix-rb}}"
34
+ tx << ""
35
+ tx << "{{italic:~ Linus}}\n\n"
36
+ CLI::UI.fmt(tx.join("\n"), enable_color: true)
37
+ end
38
+
39
+ def help
40
+ cmds = []
41
+ cmds << "\t{{bold:rfix [cmd] [options]}} -- {{italic:--dry --help --list-files --limit-files --config --untracked}}"
42
+ cmds << "\t{{bold:rfix branch <branch>}} -- {{italic:Fix changes made between HEAD and <branch>}}"
43
+ cmds << "\t{{bold:rfix origin}} -- {{italic:Fix changes made between HEAD and origin branch}}"
44
+ cmds << "\t{{bold:rfix local}} -- {{italic:Fix changes not yet pushed to upstream branch}}"
45
+ cmds << "\t{{bold:rfix info}} -- {{italic:Display runtime dependencies and their versions}}"
46
+ cmds << "\t{{bold:rfix all}} -- {{italic:Fix all files in this repository}} {{warning:(not recommended)}}"
47
+ cmds << "\t{{bold:rfix lint}} -- {{italic:Shortcut for 'local --dry --untracked'}}"
48
+ CLI::UI.fmt(cmds.join("\n"), enable_color: true)
49
+ end
50
+
51
+ def current_branch
52
+ git("rev-parse", "--abbrev-ref", "HEAD").first
53
+ end
54
+
55
+ def debug?
56
+ @debug
57
+ end
58
+
59
+ def debug!
60
+ @debug = true
61
+ end
62
+
63
+ def number_of_commits_since
64
+ cmd("git rev-list master..HEAD | wc -l").first
65
+ end
66
+
67
+ def config
68
+ @config
69
+ end
70
+
71
+ def no_auto_correct!
72
+ @config[:auto_correct] = false
73
+ end
74
+
75
+ def auto_correct!
76
+ @config[:auto_correct] = true
77
+ end
78
+
79
+ def load_config
80
+ yield @store
81
+ rescue RuboCop::Error => e
82
+ say_abort "[Config:RuboCop] #{e}"
83
+ rescue TypeError => e
84
+ say_abort "[Config:Type] #{e}"
85
+ rescue Psych::SyntaxError => e
86
+ say_abort "[Config:Syntax] #{e}"
87
+ end
88
+
89
+ def lint_mode!
90
+ no_auto_correct!
91
+ load_untracked!
92
+ end
93
+
16
94
  def git_version
17
95
  cmd("git --version").last.split(/\s+/, 3).last
18
96
  end
@@ -33,9 +111,25 @@ module Rfix
33
111
  @global_enable
34
112
  end
35
113
 
114
+ def store
115
+ @store
116
+ end
117
+
118
+ def clear_cache!
119
+ RuboCop::ResultCache.cleanup(@store, true)
120
+ end
121
+
36
122
  def init!
37
123
  @files ||= {}
38
124
  @global_enable = false
125
+ @config = {
126
+ force_exclusion: true,
127
+ formatters: ["Rfix::Formatter"]
128
+ }
129
+
130
+ @store = RuboCop::ConfigStore.new
131
+ @debug = false
132
+ auto_correct!
39
133
  end
40
134
 
41
135
  def files
@@ -83,7 +177,7 @@ module Rfix
83
177
  end
84
178
 
85
179
  def has_branch?(name)
86
- Open3.capture2e("git", "cat-file", "-t", name).last.success?
180
+ cmd_succeeded?("git", "cat-file", "-t", name)
87
181
  end
88
182
 
89
183
  # Ref since last push
@@ -100,6 +194,12 @@ module Rfix
100
194
 
101
195
  private
102
196
 
197
+ def old?
198
+ # For version 0.80.x .. 0.83.x:
199
+ # Otherwise it will exit with status code = 1
200
+ (0.80..0.83).include?(RuboCop::Version::STRING.to_f)
201
+ end
202
+
103
203
  def get_file(path, &block)
104
204
  if file = @files[path]
105
205
  block.call(file)
@@ -107,9 +207,7 @@ module Rfix
107
207
  end
108
208
 
109
209
  def list_untrack_files
110
- git("status", "-u", "--porcelain", "--no-column").map do |line|
111
- line.split(" ", 2).map(&:strip)
112
- end.select { |el| el.first == "??" }.map(&:last)
210
+ git("ls-files", "--exclude-standard", "--others")
113
211
  end
114
212
 
115
213
  def cached(files)
@@ -119,3 +217,5 @@ module Rfix
119
217
  end
120
218
  end
121
219
  end
220
+
221
+ # rubocop:enable Layout/LineLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rfix
4
- VERSION = "1.0.7"
4
+ VERSION = "1.0.8"
5
5
  end
Binary file
@@ -2,8 +2,11 @@
2
2
 
3
3
  require "pathname"
4
4
  require_relative "lib/rfix/version"
5
+ # require_relative "lib/rfix/gem_helper"
5
6
 
6
7
  Gem::Specification.new do |spec|
8
+ # extend GemHelper
9
+
7
10
  spec.name = "rfix"
8
11
 
9
12
  if ENV["TRAVIS"]
@@ -17,18 +20,16 @@ Gem::Specification.new do |spec|
17
20
  spec.authors = ["Linus Oleander"]
18
21
  spec.email = ["linus@oleander.nu"]
19
22
 
20
- spec.summary = "RuboCop CLI that only complains about your latest changes"
23
+ # rubocop:disable Layout/LineLength
24
+ spec.summary = "RuboCop CLI that only lints and auto-fixes code you committed by utilizing `git-log` and `git-diff`"
25
+ # rubocop:enable Layout/LineLength
26
+
21
27
  spec.description = <<~TEXT
22
- #{spec.summary}
23
- Uses 'git diff' to determine what changes were made then runs RuboCop against them
28
+ RuboCop CLI that only lints and auto-fixes code you committed by utilizing `git-log` and `git-diff`. Rfix CLI makes it possible to lint (`rfix lint`) and auto-fix (`rfix local|origin|branch`) code changes since a certain point in history. You can auto-fix code committed since creating the current branch (`rfix origin`) or since pushing to upstream (`rfix local`).
24
29
 
25
- $ rfix branch <branch> -- Fix changes made between HEAD and <branch>
26
- $ rfix origin -- Fix changes made between HEAD and origin branch
27
- $ rfix local -- Fix changes not yet pushed to upstream branch
28
- $ rfix info -- Display runtime dependencies and their versions
29
- $ rfix all -- Fix all files in this repository (not recommended)
30
+ Includes a RuboCop formatter with syntax highlighting and build in hyperlinks for offense documentation.
30
31
 
31
- Optional args: --dry --help --list-files --limit-files --config --untracked
32
+ Holds the same CLI arguments as RuboCop. Run `rfix --help` for a complete list or `rfix` for supported commands.
32
33
  TEXT
33
34
  spec.homepage = "https://github.com/oleander/rfix-rb"
34
35
  spec.license = "MIT"
@@ -42,15 +43,19 @@ Gem::Specification.new do |spec|
42
43
  `git ls-files -z`.split("\x0").reject(&validate_file)
43
44
  end
44
45
 
45
- spec.files += Dir.glob("vendor/cli-ui/lib/**/*").reject(&validate_file)
46
+ spec.files += Dir.glob("vendor/shopify/cli-ui/lib/**/*").reject(&validate_file)
46
47
 
47
48
  spec.bindir = "exe"
48
49
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
49
- spec.require_paths = ["lib", "vendor/cli-ui/lib"]
50
+ spec.require_paths = ["lib", "vendor/shopify/cli-ui/lib"]
50
51
 
51
52
  spec.requirements << "git, v2.0+"
52
53
 
53
54
  spec.add_runtime_dependency "rainbow", "~> 3.0"
54
55
  spec.add_runtime_dependency "rouge", "~> 3.20"
55
- spec.add_runtime_dependency "rubocop", "~> 0.80"
56
+ spec.add_runtime_dependency "rubocop", ">= 0.80"
57
+
58
+ spec.add_development_dependency "rspec", "~> 3.0"
59
+ spec.add_development_dependency "aruba", "~> 1.0"
60
+ spec.add_development_dependency "rake", "~> 12.3"
56
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7.pre.66
4
+ version: 1.0.8.pre.109
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Oleander
@@ -42,24 +42,64 @@ dependencies:
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.80'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.80'
55
- description: "RuboCop CLI that only complains about your latest changes\nUses 'git
56
- diff' to determine what changes were made then runs RuboCop against them\n\n\t$
57
- rfix branch <branch> -- Fix changes made between HEAD and <branch>\n\t$ rfix origin
58
- \ -- Fix changes made between HEAD and origin branch\n\t$ rfix local --
59
- Fix changes not yet pushed to upstream branch\n\t$ rfix info -- Display
60
- runtime dependencies and their versions\n\t$ rfix all -- Fix all files
61
- in this repository (not recommended)\n\nOptional args: --dry --help --list-files
62
- --limit-files --config --untracked\n"
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '12.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12.3'
97
+ description: |
98
+ RuboCop CLI that only lints and auto-fixes code you committed by utilizing `git-log` and `git-diff`. Rfix CLI makes it possible to lint (`rfix lint`) and auto-fix (`rfix local|origin|branch`) code changes since a certain point in history. You can auto-fix code committed since creating the current branch (`rfix origin`) or since pushing to upstream (`rfix local`).
99
+
100
+ Includes a RuboCop formatter with syntax highlighting and build in hyperlinks for offense documentation.
101
+
102
+ Holds the same CLI arguments as RuboCop. Run `rfix --help` for a complete list or `rfix` for supported commands.
63
103
  email:
64
104
  - linus@oleander.nu
65
105
  executables:
@@ -72,12 +112,19 @@ files:
72
112
  - ".rubocop.yml"
73
113
  - ".travis.yml"
74
114
  - Gemfile
115
+ - Gemfile.base
75
116
  - Gemfile.lock
76
117
  - Guardfile
77
118
  - LICENSE.txt
119
+ - Makefile
78
120
  - README.md
79
121
  - Rakefile
122
+ - bin/bundle
80
123
  - bin/console
124
+ - bin/guard
125
+ - bin/rake
126
+ - bin/rfix
127
+ - bin/rspec
81
128
  - bin/setup
82
129
  - ci/Gemfile.rubocop-0.80
83
130
  - ci/Gemfile.rubocop-0.80.lock
@@ -94,44 +141,48 @@ files:
94
141
  - ci/Gemfile.rubocop-0.85.1.lock
95
142
  - ci/Gemfile.rubocop-0.85.lock
96
143
  - exe/rfix
144
+ - file.rb
97
145
  - lib/rfix.rb
98
146
  - lib/rfix/cmd.rb
99
147
  - lib/rfix/extensions/extensions.rb
100
148
  - lib/rfix/extensions/offense.rb
101
149
  - lib/rfix/formatter.rb
150
+ - lib/rfix/gem_helper.rb
102
151
  - lib/rfix/git_file.rb
103
152
  - lib/rfix/git_helper.rb
104
153
  - lib/rfix/log.rb
154
+ - lib/rfix/rake_helper.rb
105
155
  - lib/rfix/rfix.rb
106
156
  - lib/rfix/tracked_file.rb
107
157
  - lib/rfix/untracked_file.rb
108
158
  - lib/rfix/version.rb
159
+ - resources/ps.png
109
160
  - rfix.gemspec
110
- - vendor/cli-ui/lib/cli/ui.rb
111
- - vendor/cli-ui/lib/cli/ui/ansi.rb
112
- - vendor/cli-ui/lib/cli/ui/color.rb
113
- - vendor/cli-ui/lib/cli/ui/formatter.rb
114
- - vendor/cli-ui/lib/cli/ui/frame.rb
115
- - vendor/cli-ui/lib/cli/ui/frame/frame_stack.rb
116
- - vendor/cli-ui/lib/cli/ui/frame/frame_style.rb
117
- - vendor/cli-ui/lib/cli/ui/frame/frame_style/box.rb
118
- - vendor/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb
119
- - vendor/cli-ui/lib/cli/ui/glyph.rb
120
- - vendor/cli-ui/lib/cli/ui/printer.rb
121
- - vendor/cli-ui/lib/cli/ui/progress.rb
122
- - vendor/cli-ui/lib/cli/ui/prompt.rb
123
- - vendor/cli-ui/lib/cli/ui/prompt/interactive_options.rb
124
- - vendor/cli-ui/lib/cli/ui/prompt/options_handler.rb
125
- - vendor/cli-ui/lib/cli/ui/spinner.rb
126
- - vendor/cli-ui/lib/cli/ui/spinner/async.rb
127
- - vendor/cli-ui/lib/cli/ui/spinner/spin_group.rb
128
- - vendor/cli-ui/lib/cli/ui/stdout_router.rb
129
- - vendor/cli-ui/lib/cli/ui/terminal.rb
130
- - vendor/cli-ui/lib/cli/ui/truncater.rb
131
- - vendor/cli-ui/lib/cli/ui/version.rb
132
- - vendor/cli-ui/lib/cli/ui/widgets.rb
133
- - vendor/cli-ui/lib/cli/ui/widgets/base.rb
134
- - vendor/cli-ui/lib/cli/ui/widgets/status.rb
161
+ - vendor/shopify/cli-ui/lib/cli/ui.rb
162
+ - vendor/shopify/cli-ui/lib/cli/ui/ansi.rb
163
+ - vendor/shopify/cli-ui/lib/cli/ui/color.rb
164
+ - vendor/shopify/cli-ui/lib/cli/ui/formatter.rb
165
+ - vendor/shopify/cli-ui/lib/cli/ui/frame.rb
166
+ - vendor/shopify/cli-ui/lib/cli/ui/frame/frame_stack.rb
167
+ - vendor/shopify/cli-ui/lib/cli/ui/frame/frame_style.rb
168
+ - vendor/shopify/cli-ui/lib/cli/ui/frame/frame_style/box.rb
169
+ - vendor/shopify/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb
170
+ - vendor/shopify/cli-ui/lib/cli/ui/glyph.rb
171
+ - vendor/shopify/cli-ui/lib/cli/ui/printer.rb
172
+ - vendor/shopify/cli-ui/lib/cli/ui/progress.rb
173
+ - vendor/shopify/cli-ui/lib/cli/ui/prompt.rb
174
+ - vendor/shopify/cli-ui/lib/cli/ui/prompt/interactive_options.rb
175
+ - vendor/shopify/cli-ui/lib/cli/ui/prompt/options_handler.rb
176
+ - vendor/shopify/cli-ui/lib/cli/ui/spinner.rb
177
+ - vendor/shopify/cli-ui/lib/cli/ui/spinner/async.rb
178
+ - vendor/shopify/cli-ui/lib/cli/ui/spinner/spin_group.rb
179
+ - vendor/shopify/cli-ui/lib/cli/ui/stdout_router.rb
180
+ - vendor/shopify/cli-ui/lib/cli/ui/terminal.rb
181
+ - vendor/shopify/cli-ui/lib/cli/ui/truncater.rb
182
+ - vendor/shopify/cli-ui/lib/cli/ui/version.rb
183
+ - vendor/shopify/cli-ui/lib/cli/ui/widgets.rb
184
+ - vendor/shopify/cli-ui/lib/cli/ui/widgets/base.rb
185
+ - vendor/shopify/cli-ui/lib/cli/ui/widgets/status.rb
135
186
  homepage: https://github.com/oleander/rfix-rb
136
187
  licenses:
137
188
  - MIT
@@ -141,7 +192,7 @@ post_install_message:
141
192
  rdoc_options: []
142
193
  require_paths:
143
194
  - lib
144
- - vendor/cli-ui/lib
195
+ - vendor/shopify/cli-ui/lib
145
196
  required_ruby_version: !ruby/object:Gem::Requirement
146
197
  requirements:
147
198
  - - ">="
@@ -157,5 +208,6 @@ requirements:
157
208
  rubygems_version: 3.0.3
158
209
  signing_key:
159
210
  specification_version: 4
160
- summary: RuboCop CLI that only complains about your latest changes
211
+ summary: RuboCop CLI that only lints and auto-fixes code you committed by utilizing
212
+ `git-log` and `git-diff`
161
213
  test_files: []