rfix 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,189 @@
1
+ GIT
2
+ remote: https://github.com/Shopify/cli-ui.git
3
+ revision: ef976df676f43a80b47249ac2390d5f12b2293d1
4
+ ref: ef976df676f4
5
+ specs:
6
+ cli-ui (1.3.0)
7
+
8
+ GIT
9
+ remote: https://github.com/oleander/git-fame-rb.git
10
+ revision: a9b9c25bbab197feaee00f9a5c970998e76f636c
11
+ ref: a9b9c25bbab1
12
+ specs:
13
+ git_fame (2.5.3)
14
+ hirb (~> 0.7.3)
15
+ memoist (~> 0.14.0)
16
+ method_profiler (~> 2.0.1)
17
+ progressbar (~> 0.21.0)
18
+ scrub_rb (~> 1.0.1)
19
+ trollop (~> 2.1.2)
20
+
21
+ PATH
22
+ remote: ..
23
+ specs:
24
+ rfix (0.2.0)
25
+ rainbow (~> 3.0)
26
+ rouge (~> 3.20)
27
+ rubocop (~> 0.80)
28
+
29
+ GEM
30
+ remote: https://rubygems.org/
31
+ specs:
32
+ activesupport (6.0.3.1)
33
+ concurrent-ruby (~> 1.0, >= 1.0.2)
34
+ i18n (>= 0.7, < 2)
35
+ minitest (~> 5.1)
36
+ tzinfo (~> 1.1)
37
+ zeitwerk (~> 2.2, >= 2.2.2)
38
+ aruba (1.0.1)
39
+ childprocess (~> 3.0)
40
+ contracts (~> 0.16.0)
41
+ cucumber (>= 2.4, < 5.0)
42
+ ffi (~> 1.9)
43
+ rspec-expectations (~> 3.4)
44
+ thor (~> 1.0)
45
+ ast (2.4.1)
46
+ builder (3.2.4)
47
+ childprocess (3.0.0)
48
+ coderay (1.1.3)
49
+ concurrent-ruby (1.1.6)
50
+ contracts (0.16.0)
51
+ cucumber (4.0.0)
52
+ builder (~> 3.2, >= 3.2.3)
53
+ cucumber-core (~> 7.0, >= 7.0.0)
54
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
55
+ cucumber-gherkin (~> 13.0, >= 13.0.0)
56
+ cucumber-html-formatter (~> 6.0, >= 6.0.1)
57
+ cucumber-messages (~> 12.1, >= 12.1.1)
58
+ cucumber-wire (~> 3.0, >= 3.0.0)
59
+ diff-lcs (~> 1.3, >= 1.3)
60
+ multi_test (~> 0.1, >= 0.1.2)
61
+ sys-uname (~> 1.0, >= 1.0.2)
62
+ cucumber-core (7.0.0)
63
+ cucumber-gherkin (~> 13.0, >= 13.0.0)
64
+ cucumber-messages (~> 12.1, >= 12.1.1)
65
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
66
+ cucumber-cucumber-expressions (10.2.0)
67
+ cucumber-gherkin (13.0.0)
68
+ cucumber-messages (~> 12.0, >= 12.0.0)
69
+ cucumber-html-formatter (6.0.3)
70
+ cucumber-messages (~> 12.1, >= 12.1.1)
71
+ cucumber-messages (12.1.1)
72
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
73
+ cucumber-tag-expressions (2.0.4)
74
+ cucumber-wire (3.0.0)
75
+ cucumber-core (~> 7.0, >= 7.0.0)
76
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
77
+ cucumber-messages (~> 12.1, >= 12.1.1)
78
+ diff-lcs (1.3)
79
+ ffi (1.13.1)
80
+ formatador (0.2.5)
81
+ guard (2.16.2)
82
+ formatador (>= 0.2.4)
83
+ listen (>= 2.7, < 4.0)
84
+ lumberjack (>= 1.0.12, < 2.0)
85
+ nenv (~> 0.1)
86
+ notiffany (~> 0.0)
87
+ pry (>= 0.9.12)
88
+ shellany (~> 0.0)
89
+ thor (>= 0.18.1)
90
+ guard-compat (1.2.1)
91
+ guard-rspec (4.7.3)
92
+ guard (~> 2.1)
93
+ guard-compat (~> 1.1)
94
+ rspec (>= 2.99.0, < 4.0)
95
+ hirb (0.7.3)
96
+ i18n (1.8.3)
97
+ concurrent-ruby (~> 1.0)
98
+ listen (3.2.1)
99
+ rb-fsevent (~> 0.10, >= 0.10.3)
100
+ rb-inotify (~> 0.9, >= 0.9.10)
101
+ lumberjack (1.2.5)
102
+ memoist (0.14.0)
103
+ method_profiler (2.0.1)
104
+ hirb (>= 0.6.0)
105
+ method_source (1.0.0)
106
+ middleware (0.1.0)
107
+ minitest (5.14.1)
108
+ multi_test (0.1.2)
109
+ nenv (0.3.0)
110
+ notiffany (0.1.3)
111
+ nenv (~> 0.1)
112
+ shellany (~> 0.0)
113
+ parallel (1.19.1)
114
+ parser (2.7.1.3)
115
+ ast (~> 2.4.0)
116
+ progressbar (0.21.0)
117
+ protobuf-cucumber (3.10.8)
118
+ activesupport (>= 3.2)
119
+ middleware
120
+ thor
121
+ thread_safe
122
+ pry (0.13.1)
123
+ coderay (~> 1.1)
124
+ method_source (~> 1.0)
125
+ rainbow (3.0.0)
126
+ rake (12.3.3)
127
+ rb-fsevent (0.10.4)
128
+ rb-inotify (0.10.1)
129
+ ffi (~> 1.0)
130
+ regexp_parser (1.7.1)
131
+ rexml (3.2.4)
132
+ rouge (3.20.0)
133
+ rspec (3.9.0)
134
+ rspec-core (~> 3.9.0)
135
+ rspec-expectations (~> 3.9.0)
136
+ rspec-mocks (~> 3.9.0)
137
+ rspec-core (3.9.2)
138
+ rspec-support (~> 3.9.3)
139
+ rspec-expectations (3.9.2)
140
+ diff-lcs (>= 1.2.0, < 2.0)
141
+ rspec-support (~> 3.9.0)
142
+ rspec-mocks (3.9.1)
143
+ diff-lcs (>= 1.2.0, < 2.0)
144
+ rspec-support (~> 3.9.0)
145
+ rspec-support (3.9.3)
146
+ rubocop (0.85.0)
147
+ parallel (~> 1.10)
148
+ parser (>= 2.7.0.1)
149
+ rainbow (>= 2.2.2, < 4.0)
150
+ regexp_parser (>= 1.7)
151
+ rexml
152
+ rubocop-ast (>= 0.0.3)
153
+ ruby-progressbar (~> 1.7)
154
+ unicode-display_width (>= 1.4.0, < 2.0)
155
+ rubocop-ast (0.0.3)
156
+ parser (>= 2.7.0.1)
157
+ ruby-progressbar (1.10.1)
158
+ scrub_rb (1.0.1)
159
+ shellany (0.0.1)
160
+ sys-uname (1.2.1)
161
+ ffi (>= 1.0.0)
162
+ thor (1.0.1)
163
+ thread_safe (0.3.6)
164
+ trollop (2.1.3)
165
+ tzinfo (1.2.7)
166
+ thread_safe (~> 0.1)
167
+ unicode-display_width (1.7.0)
168
+ zeitwerk (2.3.0)
169
+
170
+ PLATFORMS
171
+ ruby
172
+
173
+ DEPENDENCIES
174
+ aruba
175
+ cli-ui!
176
+ git_fame!
177
+ guard
178
+ guard-rspec
179
+ pry
180
+ rake (~> 12.0)
181
+ rfix!
182
+ rspec (~> 3.0)
183
+ rubocop (= 0.85.0)
184
+
185
+ RUBY VERSION
186
+ ruby 2.5.0p0
187
+
188
+ BUNDLED WITH
189
+ 2.1.4
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rfix"
5
+ require "rubocop"
6
+ require "rfix/formatter"
7
+ require "cli/ui"
8
+
9
+ should_list_files = false
10
+ limit_files = false
11
+ options = RuboCop::Options.new
12
+ config = RuboCop::ConfigStore.new
13
+ display_help = ARGV.include?("--help")
14
+ is_dry = ARGV.include?("--dry")
15
+ config_path = false
16
+
17
+ extend Rfix::Log
18
+ Rfix.init!
19
+ CLI::UI::StdoutRouter.enable
20
+
21
+ say "Using RuboCop {{yellow:#{RuboCop::Version.version}}}"
22
+
23
+ base_config = {
24
+ color: true,
25
+ force_exclusion: true,
26
+ auto_correct: true,
27
+ formatters: ["Rfix::Formatter"]
28
+ }
29
+
30
+ # For version 0.80.x .. 0.83.x:
31
+ # Otherwise it will exit with status code = 1
32
+ if (0.80..0.83).include?(RuboCop::Version::STRING.to_f)
33
+ if is_dry
34
+ base_config[:fail_level] = :autocorrect
35
+ else
36
+ base_config[:fail_level] = :warning
37
+ end
38
+ end
39
+
40
+ def load_config
41
+ yield
42
+ rescue RuboCop::Error => e
43
+ say_abort "[Config] #{e}"
44
+ rescue TypeError => e
45
+ say_abort "[Config] #{e}"
46
+ end
47
+
48
+ options.on("--dry", "No auto correct") do
49
+ say "Will run rfix in {{red:read-only}} mode"
50
+ base_config.merge!({ auto_correct: false })
51
+ end
52
+
53
+ options.on("--untracked", "Include untracked files") do
54
+ Rfix.load_untracked!
55
+ end
56
+
57
+ options.on("--list-files", "List files found by git") do
58
+ should_list_files = true
59
+ end
60
+
61
+ options.on("--limit-files NUM", Integer, "Limit number of files") do |limit|
62
+ limit_files = limit
63
+ end
64
+
65
+ options.on("--config PATH", "A configuration file") do |path|
66
+ config_path = path
67
+ end
68
+
69
+ case cmd = ARGV.shift
70
+ when "info"
71
+ say "Using Rfix {{yellow:#{Rfix::VERSION}}}"
72
+ say "Using OS {{yellow:#{Rfix.current_os}}}"
73
+ say "Using Git {{yellow:#{Rfix.git_version}}}"
74
+ say "Using Ruby {{yellow:#{Rfix.ruby_version}}}"
75
+ exit 0
76
+ when "local"
77
+ reference = Rfix.ref_since_push
78
+ when "origin"
79
+ reference = Rfix.ref_since_origin
80
+ when "all"
81
+ reference = false
82
+ Rfix.global_enable!
83
+ when "branch"
84
+ abort_message = "No branch passed as second argument"
85
+ unless reference = ARGV.shift
86
+ say_abort abort_message
87
+ end
88
+
89
+ # Catches:
90
+ # NOT OK: branch --help
91
+ # OK branch master --help
92
+ say_abort abort_message if reference.start_with?("--")
93
+
94
+ # Check if branch exists
95
+ say_abort "Branch {{yellow:#{reference}}} does not exist" unless Rfix.has_branch?(reference)
96
+ else
97
+ unless display_help
98
+ say_error "Valid rfix commands are"
99
+ say_error_sub "\t{{italic:rfix branch <a branch>}}"
100
+ say_error_sub "\t{{italic:rfix origin}}"
101
+ say_error_sub "\tr{{italic:fix local}}"
102
+ say_error_sub "\tr{{italic:fix all}}"
103
+ say_error_sub "\tr{{italic:fix info}}"
104
+ exit 1
105
+ end
106
+
107
+ ARGV.unshift(cmd)
108
+ end
109
+
110
+ begin
111
+ options, paths = options.parse(ARGV)
112
+ rescue OptionParser::MissingArgument => e
113
+ say_abort "[Parser] #{e}"
114
+ end
115
+
116
+ if path = config_path
117
+ load_config do
118
+ config.options_config = path
119
+ end
120
+ else
121
+ load_config do
122
+ config.for(Dir.pwd)
123
+ end
124
+ end
125
+
126
+ if ref = reference
127
+ say "Compare against {{yellow:#{ref}}}"
128
+
129
+ Rfix.load_tracked!(ref)
130
+
131
+ paths = Rfix.paths if paths.empty?
132
+
133
+ say_exit "No files to run against" if paths.empty?
134
+ end
135
+
136
+ if limit = limit_files
137
+ say "Limit number of files to {{yellow:#{limit}}}"
138
+ paths = paths.take(limit)
139
+ end
140
+
141
+ if should_list_files
142
+ say "Loaded {{yellow:#{paths.count}}} paths"
143
+ paths.each do |path|
144
+ say "\t" + Rfix.to_relative(path: path)
145
+ end
146
+ end
147
+
148
+ env = RuboCop::CLI::Environment.new(
149
+ base_config.merge(options),
150
+ config,
151
+ paths
152
+ )
153
+
154
+ begin
155
+ exit RuboCop::CLI::Command::ExecuteRunner.new(env).run
156
+ rescue RuboCop::Error => e
157
+ say_abort e.message
158
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # https://gist.github.com/skanev/9d4bec97d5a6825eaaf6
5
+
6
+ require "rfix/version"
7
+ require "rfix/log"
8
+ require "rfix/extensions"
9
+ require "rfix/rfix"
10
+
11
+ module Rfix
12
+ extend self
13
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "rfix"
5
+ require "rfix/log"
6
+
7
+ module Rfix::Cmd
8
+ include Rfix::Log
9
+
10
+ def cmd(*args)
11
+ out, err, status = Open3.capture3(*args)
12
+
13
+ unless status.success?
14
+ return yield if block_given?
15
+
16
+ say_error "[Cmd] {{italic:#{args.join(" ")}}}"
17
+ say_error "[Pwd] {{italic:#{Dir.pwd}}}"
18
+ say_error "[Err] {{error:#{err.strip}}}"
19
+
20
+ exit status.exitstatus
21
+ end
22
+
23
+ out.lines.map(&:chomp)
24
+ end
25
+
26
+ def params
27
+ [
28
+ "--word-diff-regex=[^[:space:]]",
29
+ "--no-renames",
30
+ "--no-merges",
31
+ "--first-parent",
32
+ "--diff-filter=AM",
33
+ "-U0",
34
+ "--no-color",
35
+ "-p"
36
+ ]
37
+ end
38
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "rainbow"
5
+
6
+ module Rfix::Ext
7
+ module CommentConfig
8
+ # Called by RuboCop on every line to see
9
+ # if its suppose to run against it or not
10
+ def cop_enabled_at_line?(_cop, line)
11
+ Rfix.enabled?(processed_source.file_path, line) && super
12
+ end
13
+ end
14
+
15
+ module Runner
16
+ # Called _after_ @source has been 'auto fixed' by Rubocop
17
+ def check_for_infinite_loop(source, offences)
18
+ Rfix.refresh!(source); super # TODO: Before or after?
19
+ end
20
+ end
21
+
22
+ module Options
23
+ # Appends custom --args to RuboCop CLI
24
+ def define_options
25
+ super.tap do |options|
26
+ @ons.each do |args, block|
27
+ option(options, *args, &block)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Helper method used by rfix to append cli --args to Rubocop
33
+ def on(*args, &block)
34
+ @ons ||= []
35
+ @ons += [[args, block]]
36
+ end
37
+ end
38
+
39
+ module Offense
40
+ def where
41
+ line.to_s + ":" + real_column.to_s
42
+ end
43
+
44
+ def info
45
+ message.split(": ", 2).last.delete("\n")
46
+ end
47
+
48
+ def msg
49
+ CLI::UI.resolve_text("{{italic:#{info}}}", truncate_to: CLI::UI::Terminal.width - 10)
50
+ end
51
+
52
+ def code
53
+ message.split(": ", 2).first
54
+ end
55
+
56
+ def star
57
+ Rainbow("⭑")
58
+ end
59
+
60
+ def cross
61
+ Rainbow("✗")
62
+ end
63
+
64
+ def check
65
+ Rainbow("✓")
66
+ end
67
+
68
+ def level
69
+ colors = {
70
+ refactor: star.lightcyan,
71
+ convention: star.lightblue,
72
+ warning: star.lightyellow,
73
+ error: cross.indianred,
74
+ fatal: cross.lightsalmon
75
+ }
76
+
77
+ colors[severity.name]
78
+ end
79
+
80
+ def icon
81
+ return check.green if corrected?
82
+ return check.lightgreen if correctable?
83
+
84
+ cross.indianred
85
+ end
86
+ end
87
+ end
88
+
89
+ RuboCop::Options.prepend(Rfix::Ext::Options)
90
+ RuboCop::Runner.prepend(Rfix::Ext::Runner)
91
+ RuboCop::CommentConfig.prepend(Rfix::Ext::CommentConfig)
92
+ RuboCop::Cop::Offense.prepend(Rfix::Ext::Offense)