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.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.rspec +0 -1
- data/.rubocop.yml +46 -31
- data/.travis.yml +5 -12
- data/Gemfile.base +10 -3
- data/Gemfile.base.lock +172 -0
- data/Gemfile.lock +28 -7
- data/Guardfile +1 -1
- data/Makefile +4 -13
- data/Rakefile +16 -95
- data/ci/Gemfile.rubocop-0.80.lock +16 -1
- data/ci/Gemfile.rubocop-0.81.lock +16 -1
- data/ci/Gemfile.rubocop-0.82.lock +16 -1
- data/ci/Gemfile.rubocop-0.83.lock +19 -4
- data/ci/Gemfile.rubocop-0.84.lock +19 -4
- data/ci/Gemfile.rubocop-0.85.1.lock +19 -4
- data/ci/Gemfile.rubocop-0.85.lock +16 -1
- data/exe/rfix +18 -144
- data/lib/rfix.rb +10 -3
- data/lib/rfix/box.rb +112 -0
- data/lib/rfix/branch.rb +30 -0
- data/lib/rfix/branches/base.rb +29 -0
- data/lib/rfix/branches/head.rb +11 -0
- data/lib/rfix/branches/main.rb +33 -0
- data/lib/rfix/branches/name.rb +21 -0
- data/lib/rfix/branches/reference.rb +19 -0
- data/lib/rfix/branches/upstream.rb +11 -0
- data/lib/rfix/cmd.rb +9 -14
- data/lib/rfix/commands/all.rb +26 -0
- data/lib/rfix/commands/branch.rb +15 -0
- data/lib/rfix/commands/extensions/options.rb +8 -0
- data/lib/rfix/commands/help.rb +7 -0
- data/lib/rfix/commands/helper/args.rb +137 -0
- data/lib/rfix/commands/helper/help.rb +6 -0
- data/lib/rfix/commands/helper/loader.rb +6 -0
- data/lib/rfix/commands/helper/option.rb +0 -0
- data/lib/rfix/commands/helper/params.rb +0 -0
- data/lib/rfix/commands/helper/rubocop.rb +17 -0
- data/lib/rfix/commands/info.rb +30 -0
- data/lib/rfix/commands/lint.rb +23 -0
- data/lib/rfix/commands/local.rb +12 -0
- data/lib/rfix/commands/origin.rb +19 -0
- data/lib/rfix/commands/setup.rb +29 -0
- data/lib/rfix/commands/welcome.rb +24 -0
- data/lib/rfix/deleted.rb +13 -0
- data/lib/rfix/error.rb +2 -0
- data/lib/rfix/extensions/extensions.rb +4 -26
- data/lib/rfix/extensions/offense.rb +2 -1
- data/lib/rfix/extensions/string.rb +8 -0
- data/lib/rfix/file.rb +46 -0
- data/lib/rfix/file_cache.rb +59 -0
- data/lib/rfix/formatter.rb +37 -10
- data/lib/rfix/git_helper.rb +13 -1
- data/lib/rfix/log.rb +104 -7
- data/lib/rfix/no_file.rb +13 -0
- data/lib/rfix/rake/paths.rb +50 -0
- data/lib/rfix/rake/support.rb +75 -0
- data/lib/rfix/repository.rb +201 -0
- data/lib/rfix/rfix.rb +7 -198
- data/lib/rfix/tracked.rb +76 -0
- data/lib/rfix/tracked_file.rb +1 -1
- data/lib/rfix/untracked.rb +13 -0
- data/lib/rfix/version.rb +1 -1
- data/path.rb +7 -0
- data/rfix.gemspec +6 -2
- data/rugged.rb +206 -0
- data/tasks/bump.rake +11 -0
- data/tasks/bundle.rake +17 -0
- data/tasks/complex.rake +54 -0
- data/tasks/simple.rake +58 -0
- data/tasks/travis.rake +74 -0
- data/tasks/vendor.rake +34 -0
- metadata +136 -13
- data/file.rb +0 -1
- data/lib/rfix/gem_helper.rb +0 -12
- data/lib/rfix/git_file.rb +0 -36
- data/lib/rfix/rake_helper.rb +0 -56
- data/lib/rfix/untracked_file.rb +0 -13
data/lib/rfix/branch.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rfix/repository"
|
2
|
+
require "rfix/error"
|
3
|
+
|
4
|
+
module Rfix
|
5
|
+
module Branch
|
6
|
+
class UnknownBranchError < Rfix::Error
|
7
|
+
end
|
8
|
+
|
9
|
+
class NotYetImplementedError < Rfix::Error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Pathname(__dir__).glob("branches/*.rb").each(&method(:require))
|
15
|
+
|
16
|
+
module Rfix
|
17
|
+
module Branch
|
18
|
+
UPSTREAM = Branch::Upstream.new
|
19
|
+
MAIN = Branch::Main.new
|
20
|
+
HEAD = Branch::Head.new
|
21
|
+
|
22
|
+
def self.local(at: Dir.pwd)
|
23
|
+
repo(at: at).branches.each_name(:local).sort
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.repo(at:)
|
27
|
+
Rugged::Repository.new(at)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Rfix::Branch::Base
|
2
|
+
def resolve(with:)
|
3
|
+
raise Rfix::NotYetImplementedError.new("#resolved")
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_s
|
7
|
+
raise Rfix::NotYetImplementedError.new("#to_s")
|
8
|
+
end
|
9
|
+
|
10
|
+
def branch(using:)
|
11
|
+
names(using: using).last or raise Rfix::Error.new("No named branch found for {{error:#{self}}}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def names(using:)
|
15
|
+
oid = resolve(with: using).oid
|
16
|
+
locals = using.branches.each_name(:local).to_a
|
17
|
+
|
18
|
+
using.branches.select do |branch|
|
19
|
+
next false unless locals.include?(branch.name)
|
20
|
+
branch.target_id == oid
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def revparse(using:, ref:)
|
25
|
+
using.rev_parse(ref)
|
26
|
+
rescue Rugged::InvalidError
|
27
|
+
raise Rfix::Branch::UnknownBranchError.new("Could not find reference {{error:#{ref}}}")
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "rugged"
|
2
|
+
|
3
|
+
module Rfix
|
4
|
+
class Branch::Main < Branch::Base
|
5
|
+
KEY = "rfix.main.branch"
|
6
|
+
|
7
|
+
def resolve(with:)
|
8
|
+
unless name = with.config[KEY]
|
9
|
+
raise Error.new("Please run {{command:rfix setup}} first")
|
10
|
+
end
|
11
|
+
|
12
|
+
String.new(name).resolve(with: with)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.set(branch, at: Dir.pwd)
|
16
|
+
unless branch.is_a?(String)
|
17
|
+
raise Rfix::Error.new("Branch must be a string, got {{error:#{branch.class}}}")
|
18
|
+
end
|
19
|
+
|
20
|
+
check = Branch::Name.new(branch)
|
21
|
+
repo = Branch.repo(at: at)
|
22
|
+
Branch.repo(at: at).config[KEY] = check.branch(using: repo).name
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get(at: Dir.pwd)
|
26
|
+
Branch.repo(at: at).config[KEY]
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
"configured main branch"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rfix
|
2
|
+
class Branch::Name < Branch::Base
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def resolve(with:)
|
10
|
+
unless branch = with.branches[name]
|
11
|
+
raise Branch::UnknownBranchError.new("Could not find branch {{error:#{name}}}")
|
12
|
+
end
|
13
|
+
|
14
|
+
with.lookup(with.merge_base(branch.target_id, with.head.target_id))
|
15
|
+
rescue Rugged::ReferenceError
|
16
|
+
raise Branch::UnknownBranchError.new("Could not find branch {{error:#{name}}}")
|
17
|
+
end
|
18
|
+
|
19
|
+
alias to_s name
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rfix
|
2
|
+
class Branch::Reference < Branch::Base
|
3
|
+
attr_reader :reference
|
4
|
+
|
5
|
+
def initialize(reference)
|
6
|
+
@reference = reference
|
7
|
+
end
|
8
|
+
|
9
|
+
def resolve(with:)
|
10
|
+
Branch::Name.new(reference).resolve(with: with)
|
11
|
+
rescue Branch::UnknownBranchError
|
12
|
+
revparse(using: with, ref: reference)
|
13
|
+
rescue Rugged::InvalidError
|
14
|
+
raise Branch::UnknownBranchError.new("Branch with reference {{error:#{reference}}} not found")
|
15
|
+
end
|
16
|
+
|
17
|
+
alias to_s reference
|
18
|
+
end
|
19
|
+
end
|
data/lib/rfix/cmd.rb
CHANGED
@@ -9,20 +9,15 @@ module Rfix::Cmd
|
|
9
9
|
|
10
10
|
def cmd(*args, quiet: false)
|
11
11
|
out, err, status = Open3.capture3(*args)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
exit status.exitstatus
|
23
|
-
end
|
24
|
-
|
25
|
-
out.lines.map(&:chomp)
|
12
|
+
box = Rfix::Box.new(out, err, status, args, quiet)
|
13
|
+
return box.stdout if box.success?
|
14
|
+
return yield if block_given?
|
15
|
+
return if quiet
|
16
|
+
|
17
|
+
box.render(color: :red)
|
18
|
+
exit box.exit_status
|
19
|
+
ensure
|
20
|
+
# box.render(debug: false)
|
26
21
|
end
|
27
22
|
|
28
23
|
def cmd_succeeded?(*cmd)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# helper("help", binding)
|
2
|
+
# helper("rubocop", binding)
|
3
|
+
# helper("args", binding)
|
4
|
+
#
|
5
|
+
# summary "All"
|
6
|
+
#
|
7
|
+
# run do |opts, args, cmd|
|
8
|
+
# setup(opts, args) do |repo, files|
|
9
|
+
# q1 = "Are you sure you want to {{warning:auto-fix}} the {{warning:the entire folder}}"
|
10
|
+
# q2 = "Are you sure you want to {{warning:auto-fix}} everything in {{warning:#{files.join(", ")}?}}"
|
11
|
+
#
|
12
|
+
# begin
|
13
|
+
# if files.empty?
|
14
|
+
# unless CLI::UI.confirm(q1)
|
15
|
+
# exit 1
|
16
|
+
# end
|
17
|
+
# elsif CLI::UI.confirm(q2)
|
18
|
+
# exit 1
|
19
|
+
# end
|
20
|
+
# rescue Interrupt
|
21
|
+
# exit 1
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# Rfix.global_enable!
|
25
|
+
# end
|
26
|
+
# end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
r_args = []
|
2
|
+
|
3
|
+
helper("help", binding)
|
4
|
+
helper("rubocop", binding)
|
5
|
+
helper("args", binding)
|
6
|
+
|
7
|
+
param :branch
|
8
|
+
usage "rfix branch BRANCH [opts] [-p path ..]"
|
9
|
+
option :p, :path, "Path to be passed to RuboCop", argument: :required, multiple: true
|
10
|
+
summary "Fix changes made between HEAD and <branch>"
|
11
|
+
|
12
|
+
run do |opts, args, _cmd|
|
13
|
+
branch = Rfix::Branch::Reference.new(args[:branch])
|
14
|
+
setup(r_args, opts, args, files: opts[:path] || [], reference: branch)
|
15
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
option :r, :root, "{{*}} Project root path", default: Dir.pwd, argument: :required
|
2
|
+
option :b, :"main-branch", "{{*}} Branch to use", default: "master", argument: :required
|
3
|
+
option :l, :limit, "{{*}} Limit number of files", argument: :required, transform: method(:Integer)
|
4
|
+
|
5
|
+
flag nil, :dry, "{{*}} Run in dry mode"
|
6
|
+
flag nil, :untracked, "{{*}} Load untracked files"
|
7
|
+
flag nil, :"clear-cache", "{{*}} Clear Rubocop`s cache"
|
8
|
+
flag nil, :test, "{{*}} Used in tests"
|
9
|
+
|
10
|
+
def validate!(files:)
|
11
|
+
return [] unless files.is_a?(Array)
|
12
|
+
|
13
|
+
files.each do |file|
|
14
|
+
unless File.exist?(file)
|
15
|
+
say_abort "Passed file {{error:#{file}}} does not exist"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
files
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup(r_args = [], opts, _args, files: [], reference:)
|
23
|
+
# files = validate!(files: files)
|
24
|
+
options = RuboCop::Options.new
|
25
|
+
store = RuboCop::ConfigStore.new
|
26
|
+
|
27
|
+
params = {
|
28
|
+
force_exclusion: true,
|
29
|
+
formatters: ["Rfix::Formatter"],
|
30
|
+
auto_correct: true
|
31
|
+
}
|
32
|
+
|
33
|
+
if opts.key?(:format)
|
34
|
+
params.delete(:formatters)
|
35
|
+
end
|
36
|
+
|
37
|
+
if opts.key?(:dry)
|
38
|
+
params[:auto_correct] = false
|
39
|
+
end
|
40
|
+
|
41
|
+
if opts.key?(:test)
|
42
|
+
params.delete(:formatters)
|
43
|
+
params[:format] = "json"
|
44
|
+
params[:cache] = "false"
|
45
|
+
Rfix.test = true
|
46
|
+
|
47
|
+
unless opts.key?(:root)
|
48
|
+
raise "No --root passed with --test"
|
49
|
+
end
|
50
|
+
|
51
|
+
unless opts.key?(:config)
|
52
|
+
raise "No --config passed with --test"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if opts[:cache] == "false"
|
57
|
+
params[:cache] = "false"
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
Rfix.repo = repo = Rfix::Repository.new(
|
62
|
+
root_path: opts[:root],
|
63
|
+
load_untracked: opts[:untracked],
|
64
|
+
reference: reference,
|
65
|
+
paths: files || []
|
66
|
+
)
|
67
|
+
rescue Rugged::RepositoryError => e
|
68
|
+
say_abort e.to_s
|
69
|
+
rescue Rfix::Error => e
|
70
|
+
say_abort e.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
# RuboCop::ResultCache.cleanup(store, true)
|
74
|
+
|
75
|
+
if opts[:"clear-cache"]
|
76
|
+
RuboCop::ResultCache.cleanup(store, true)
|
77
|
+
params[:cache] = "false"
|
78
|
+
say_debug "Cleared Rubocop`s cache"
|
79
|
+
end
|
80
|
+
|
81
|
+
if block_given?
|
82
|
+
yield(repo, [])
|
83
|
+
end
|
84
|
+
|
85
|
+
begin
|
86
|
+
params2, paths = options.parse(r_args)
|
87
|
+
rescue OptionParser::MissingArgument => e
|
88
|
+
say_abort e.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
params2.merge!(params)
|
92
|
+
|
93
|
+
begin
|
94
|
+
if config = opts[:config]
|
95
|
+
store.options_config = config
|
96
|
+
elsif root_path = opts[:root]
|
97
|
+
store.for(root_path)
|
98
|
+
end
|
99
|
+
rescue RuboCop::Error => e
|
100
|
+
say_abort e.to_s
|
101
|
+
rescue TypeError => e
|
102
|
+
say_abort e.to_s
|
103
|
+
rescue Psych::SyntaxError => e
|
104
|
+
say_abort e.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
# unless files.empty?
|
108
|
+
# say "Loading files from {{italic:#{files.join(', ')}}}"
|
109
|
+
# end
|
110
|
+
|
111
|
+
if !files.empty?
|
112
|
+
paths = files
|
113
|
+
elsif paths.empty? && repo.paths.empty?
|
114
|
+
if opts[:format] == "json"
|
115
|
+
prt JSON.pretty_generate({"files": []})
|
116
|
+
exit 0
|
117
|
+
else
|
118
|
+
say_exit "Everything looks good, nothing to lint"
|
119
|
+
end
|
120
|
+
elsif paths.empty?
|
121
|
+
paths = repo.paths
|
122
|
+
end
|
123
|
+
|
124
|
+
if limit = opts[:limit]
|
125
|
+
paths = paths.take(limit)
|
126
|
+
end
|
127
|
+
|
128
|
+
env = RuboCop::CLI::Environment.new(params2, store, paths)
|
129
|
+
|
130
|
+
begin
|
131
|
+
exit RuboCop::CLI::Command::ExecuteRunner.new(env).run
|
132
|
+
rescue RuboCop::Runner::InfiniteCorrectionLoop => e
|
133
|
+
say_abort e.to_s
|
134
|
+
rescue RuboCop::Error => e
|
135
|
+
say_abort e.to_s
|
136
|
+
end
|
137
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RuboCop::Options.new.opts.instance_eval("@stack", __FILE__, __LINE__).map(&:list).flatten.each do |opt|
|
2
|
+
short = opt.short.map { |arg| arg.delete_prefix("-") }
|
3
|
+
long = opt.long.map { |arg| arg.delete_prefix("--") }
|
4
|
+
|
5
|
+
short.unshift(nil) if opt.short.empty?
|
6
|
+
long.unshift(nil) if opt.long.empty?
|
7
|
+
|
8
|
+
if opt.arg
|
9
|
+
option(*short, *long, opt.desc.join(" "), argument: :optional) do |value|
|
10
|
+
r_args.append(*opt.long, value)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
flag(*short, *long, opt.desc.join(" ")) do
|
14
|
+
r_args.append(*opt.long)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rbconfig"
|
2
|
+
require "rugged"
|
3
|
+
|
4
|
+
extend Rfix::Log
|
5
|
+
extend Rfix::Cmd
|
6
|
+
|
7
|
+
def git_version
|
8
|
+
cmd("git --version").last.split(/\s+/, 3).last
|
9
|
+
end
|
10
|
+
|
11
|
+
def ruby_version
|
12
|
+
RbConfig::CONFIG["ruby_version"] || "<unknown>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def current_os
|
16
|
+
RbConfig::CONFIG["host_os"] || "<unknown>"
|
17
|
+
end
|
18
|
+
|
19
|
+
helper("help", binding)
|
20
|
+
|
21
|
+
summary "Display runtime dependencies and their version"
|
22
|
+
|
23
|
+
run do |_opts, _args|
|
24
|
+
say "Using RuboCop {{info:#{RuboCop::Version.version}}}"
|
25
|
+
say "Using Rugged {{info:#{Rugged::VERSION}}}"
|
26
|
+
say "Using Rfix {{info:#{Rfix::VERSION}}}"
|
27
|
+
say "Using OS {{info:#{current_os}}}"
|
28
|
+
say "Using Git {{info:#{git_version}}}"
|
29
|
+
say "Using Ruby {{info:#{ruby_version}}}"
|
30
|
+
end
|