rubocop-gradual 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +17 -10
- data/exe/rubocop-gradual +1 -1
- data/lib/rubocop/gradual/cli.rb +9 -18
- data/lib/rubocop/gradual/commands/autocorrect.rb +51 -0
- data/lib/rubocop/gradual/commands/base.rb +50 -0
- data/lib/rubocop/gradual/configuration.rb +44 -0
- data/lib/rubocop/gradual/formatters/autocorrect.rb +35 -0
- data/lib/rubocop/gradual/formatters/base.rb +36 -0
- data/lib/rubocop/gradual/options.rb +47 -35
- data/lib/rubocop/gradual/process/diff.rb +1 -1
- data/lib/rubocop/gradual/process/printer.rb +5 -5
- data/lib/rubocop/gradual/process.rb +11 -14
- data/lib/rubocop/gradual/version.rb +1 -1
- data/lib/rubocop/gradual.rb +0 -13
- metadata +7 -3
- data/lib/rubocop/gradual/formatter.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a09b07cf179aca2230eacccaa07666e3c12b10d7d7f3972130c300649f60c0f
|
4
|
+
data.tar.gz: 758580d293c1ce1cbaa48ab811074b0b08b09898d88152ece3b4c41f8c340148
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf64a0823d530ea44ca6736914f14decc7dcbe006d0559392efa8576b28d176a7832a8b13d895ceb1d234fd0861a95f70f91b6313e5bb15c1da5cc8f83f9a57
|
7
|
+
data.tar.gz: 04a831f72f97429a2812de310884bcc7d31726858f5b0732bb4477a6be9a1776ad0adeafbd8efb7d5d6b5b38cb8e243e28cab2ec801aaad20e395bf4c35fb042
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.2.0] - 2022-07-26
|
11
|
+
|
12
|
+
- Add autocorrection options. ([@skryukov])
|
13
|
+
Run `rubocop-gradual -a` and `rubocop-gradual -A` to autocorrect new and changed files and then update the lock file.
|
14
|
+
|
15
|
+
- Rename `--ci` to `--check` option. ([@skryukov])
|
16
|
+
|
17
|
+
- Rename `-u, --update` to `-U, --force-update` option. ([@skryukov])
|
18
|
+
|
10
19
|
## [0.1.1] - 2022-07-05
|
11
20
|
|
12
21
|
### Changed
|
@@ -25,7 +34,8 @@ and this project adheres to [Semantic Versioning].
|
|
25
34
|
|
26
35
|
[@skryukov]: https://github.com/skryukov
|
27
36
|
|
28
|
-
[Unreleased]: https://github.com/skryukov/rubocop-gradual/compare/v0.
|
37
|
+
[Unreleased]: https://github.com/skryukov/rubocop-gradual/compare/v0.2.0...HEAD
|
38
|
+
[0.2.0]: https://github.com/skryukov/rubocop-gradual/compare/v0.1.1...v0.2.0
|
29
39
|
[0.1.1]: https://github.com/skryukov/rubocop-gradual/compare/v0.1.0...v0.1.1
|
30
40
|
[0.1.0]: https://github.com/skryukov/rubocop-gradual/commits/v0.1.0
|
31
41
|
|
data/README.md
CHANGED
@@ -5,6 +5,14 @@
|
|
5
5
|
|
6
6
|
RuboCop Gradual is a tool that helps track down and fix RuboCop offenses in your code gradually. It's a more flexible alternative to RuboCop's `--auto-gen-config` option.
|
7
7
|
|
8
|
+
RuboCop Gradual:
|
9
|
+
|
10
|
+
- generates the lock file with all RuboCop offenses and uses hashes to track each offense **line by line**
|
11
|
+
- **automatically** updates the lock file on every successful run, but returns errors on new offenses
|
12
|
+
- does not prevent your editor from **showing ignored offenses**
|
13
|
+
|
14
|
+
Gain full control of gradual improvements: just add `rubocop-gradual` and use it as proxy for `rubocop`.
|
15
|
+
|
8
16
|
<a href="https://evilmartians.com/?utm_source=rubocop-gradual&utm_campaign=project_page">
|
9
17
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
|
10
18
|
</a>
|
@@ -27,24 +35,23 @@ Run `rubocop-gradual` before commiting changes to update the lock file. RuboCop
|
|
27
35
|
|
28
36
|
Proposed workflow:
|
29
37
|
|
38
|
+
- Remove `rubocop_todo.yml` if it exists.
|
30
39
|
- Run `rubocop-gradual` to generate a lock file and commit it to the project repository.
|
31
|
-
|
32
|
-
-
|
33
|
-
|
40
|
+
- Add `rubocop-gradual --check` to your CI pipeline instead of `rubocop`/`standard`. It will throw an error if the lock file is out of date.
|
41
|
+
- Run `rubocop-gradual` to update the lock file, or `rubocop-gradual -a` to run autocorrection for all new and changed files and then update the lock file.
|
34
42
|
- Optionally, add `rubocop-gradual` as a pre-commit hook to your repository (using [lefthook], for example).
|
35
|
-
|
36
|
-
- RuboCop Gradual will throw an error on any new offense, but if you really want to force update the lock file, run `rubocop-gradual --update`.
|
43
|
+
- RuboCop Gradual will throw an error on any new offense, but if you really want to force update the lock file, run `rubocop-gradual --force-update`.
|
37
44
|
|
38
45
|
## Available options
|
39
46
|
|
40
47
|
```
|
41
|
-
|
42
|
-
|
48
|
+
-U, --force-update Force update Gradual lock file.
|
49
|
+
--check Check Gradual lock file is up-to-date.
|
50
|
+
-a, --autocorrect Autocorrect offenses (only when it's safe).
|
51
|
+
-A, --autocorrect-all Autocorrect offenses (safe and unsafe).
|
43
52
|
--gradual-file FILE Specify Gradual lock file.
|
44
|
-
--no-gradual Disable Gradual.
|
45
53
|
-v, --version Display version.
|
46
|
-
-
|
47
|
-
-h, --help Display help message.
|
54
|
+
-h, --help Prints this help.
|
48
55
|
```
|
49
56
|
|
50
57
|
## Alternatives
|
data/exe/rubocop-gradual
CHANGED
@@ -11,6 +11,6 @@ cli = RuboCop::Gradual::CLI.new
|
|
11
11
|
|
12
12
|
time = Benchmark.realtime { exit_status = cli.run }
|
13
13
|
|
14
|
-
puts "Finished in #{time} seconds" if
|
14
|
+
puts "Finished in #{time} seconds" if RuboCop::Gradual::Configuration.display_time?
|
15
15
|
|
16
16
|
exit exit_status
|
data/lib/rubocop/gradual/cli.rb
CHANGED
@@ -1,32 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "configuration"
|
3
4
|
require_relative "options"
|
4
|
-
require_relative "formatter"
|
5
5
|
|
6
6
|
module RuboCop
|
7
7
|
module Gradual
|
8
8
|
# CLI is a wrapper around RuboCop::CLI.
|
9
|
-
class CLI
|
10
|
-
def run(
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
class CLI
|
10
|
+
def run(argv = ARGV)
|
11
|
+
Configuration.apply(*Options.new.parse(argv))
|
12
|
+
puts "Gradual mode: #{Configuration.mode}" if Configuration.debug?
|
13
|
+
load_command(Configuration.command).call.to_i
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@options[:formatters] = [[Formatter, nil]]
|
23
|
-
end
|
24
|
-
|
25
|
-
def execute_runners
|
26
|
-
raise OptionArgumentError, "--auto-gen-config cannot be used in gradual mode." if @options[:auto_gen_config]
|
27
|
-
|
28
|
-
result = super
|
29
|
-
Gradual.mode == :disabled ? result : Gradual.exit_code
|
18
|
+
def load_command(command)
|
19
|
+
require_relative "commands/#{command}"
|
20
|
+
::RuboCop::Gradual::Commands.const_get(command.to_s.capitalize).new
|
30
21
|
end
|
31
22
|
end
|
32
23
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
require_relative "../formatters/autocorrect"
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module Gradual
|
8
|
+
module Commands
|
9
|
+
# Autocorrect command runs RuboCop autocorrect before running the base command.
|
10
|
+
class Autocorrect
|
11
|
+
def call
|
12
|
+
runner = RuboCop::CLI::Command::ExecuteRunner.new(
|
13
|
+
RuboCop::CLI::Environment.new(
|
14
|
+
Configuration.rubocop_options.merge(formatters: [[Formatters::Autocorrect, nil]]),
|
15
|
+
Configuration.rubocop_config_store,
|
16
|
+
changed_or_untracked_files.map(&:path)
|
17
|
+
)
|
18
|
+
)
|
19
|
+
runner.run
|
20
|
+
Base.new.call
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def changed_or_untracked_files
|
26
|
+
tracked_files = LockFile.new(Configuration.path).read_results&.files || []
|
27
|
+
|
28
|
+
target_files.reject do |file|
|
29
|
+
tracked_files.any? { |r| r.path == file.path && r.file_hash == file.file_hash }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def target_files
|
34
|
+
Parallel.map(rubocop_target_file_paths) do |path|
|
35
|
+
Results::File.new(path: RuboCop::PathUtil.smart_path(path), issues: [])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def rubocop_target_file_paths
|
40
|
+
target_finder = RuboCop::TargetFinder.new(Configuration.rubocop_config_store, Configuration.rubocop_options)
|
41
|
+
mode = if Configuration.rubocop_options[:only_recognized_file_types]
|
42
|
+
:only_recognized_file_types
|
43
|
+
else
|
44
|
+
:all_file_types
|
45
|
+
end
|
46
|
+
target_finder.find([], mode)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "benchmark"
|
4
|
+
|
5
|
+
require_relative "../formatters/base"
|
6
|
+
require_relative "../process"
|
7
|
+
|
8
|
+
module RuboCop
|
9
|
+
module Gradual
|
10
|
+
module Commands
|
11
|
+
# Base command runs RuboCop, and processes the results with Gradual.
|
12
|
+
class Base
|
13
|
+
def call
|
14
|
+
exit_code = 0
|
15
|
+
run_rubocop
|
16
|
+
write_stats_message
|
17
|
+
time = Benchmark.realtime { exit_code = Process.new(Configuration.rubocop_results).call }
|
18
|
+
puts "Finished Gradual processing in #{time} seconds" if Configuration.display_time?
|
19
|
+
|
20
|
+
exit_code
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def run_rubocop
|
26
|
+
rubocop_runner = RuboCop::CLI::Command::ExecuteRunner.new(
|
27
|
+
RuboCop::CLI::Environment.new(
|
28
|
+
rubocop_options,
|
29
|
+
Configuration.rubocop_config_store,
|
30
|
+
[]
|
31
|
+
)
|
32
|
+
)
|
33
|
+
rubocop_runner.run
|
34
|
+
end
|
35
|
+
|
36
|
+
def rubocop_options
|
37
|
+
Configuration.rubocop_options
|
38
|
+
.slice(:config, :debug, :display_time)
|
39
|
+
.merge(formatters: [[Formatters::Base, nil]])
|
40
|
+
end
|
41
|
+
|
42
|
+
def write_stats_message
|
43
|
+
issues_count = Configuration.rubocop_results.sum { |f| f[:issues].size }
|
44
|
+
puts "\nFound #{Configuration.rubocop_results.size} files with #{issues_count} issue(s)."
|
45
|
+
puts "Processing results..."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Gradual
|
5
|
+
# Configuration class stores Gradual and Rubocop options.
|
6
|
+
module Configuration
|
7
|
+
class << self
|
8
|
+
attr_reader :options, :rubocop_options, :rubocop_results
|
9
|
+
|
10
|
+
def apply(options = {}, rubocop_options = {})
|
11
|
+
@options = options
|
12
|
+
@rubocop_options = rubocop_options
|
13
|
+
@rubocop_results = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def command
|
17
|
+
options.fetch(:command, :base)
|
18
|
+
end
|
19
|
+
|
20
|
+
def mode
|
21
|
+
options.fetch(:mode, :update)
|
22
|
+
end
|
23
|
+
|
24
|
+
def path
|
25
|
+
options.fetch(:path, ".rubocop_gradual.lock")
|
26
|
+
end
|
27
|
+
|
28
|
+
def debug?
|
29
|
+
rubocop_options[:debug]
|
30
|
+
end
|
31
|
+
|
32
|
+
def display_time?
|
33
|
+
rubocop_options[:debug] || rubocop_options[:display_time]
|
34
|
+
end
|
35
|
+
|
36
|
+
def rubocop_config_store
|
37
|
+
RuboCop::ConfigStore.new.tap do |config_store|
|
38
|
+
config_store.options_config = rubocop_options[:config] if rubocop_options[:config]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Gradual
|
7
|
+
module Formatters
|
8
|
+
# Formatter is a RuboCop formatter class that collects RuboCop results and
|
9
|
+
# calls the Gradual::Process class at the end to process them.
|
10
|
+
class Autocorrect < RuboCop::Formatter::BaseFormatter
|
11
|
+
include PathUtil
|
12
|
+
|
13
|
+
def initialize(_output, options = {})
|
14
|
+
super
|
15
|
+
@corrected_files = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def started(target_files)
|
19
|
+
puts "Inspecting #{target_files.size} file(s) for autocorrection..."
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_finished(_file, offenses)
|
23
|
+
print "."
|
24
|
+
return if offenses.empty?
|
25
|
+
|
26
|
+
@corrected_files += 1 if offenses.any?(&:corrected?)
|
27
|
+
end
|
28
|
+
|
29
|
+
def finished(_inspected_files)
|
30
|
+
puts "\nFixed #{@corrected_files} file(s).\n"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Gradual
|
7
|
+
module Formatters
|
8
|
+
# Base is a RuboCop formatter class that collects RuboCop results and
|
9
|
+
# writes them to Configuration.rubocop_results.
|
10
|
+
class Base < RuboCop::Formatter::BaseFormatter
|
11
|
+
include PathUtil
|
12
|
+
|
13
|
+
def file_finished(file, offenses)
|
14
|
+
print "."
|
15
|
+
return if offenses.empty?
|
16
|
+
|
17
|
+
Configuration.rubocop_results << {
|
18
|
+
path: smart_path(file),
|
19
|
+
issues: offenses.reject(&:corrected?).map { |o| issue_offense(o) }
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def issue_offense(offense)
|
26
|
+
{
|
27
|
+
line: offense.line,
|
28
|
+
column: offense.real_column,
|
29
|
+
length: offense.location.length,
|
30
|
+
message: offense.message
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,61 +1,79 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rainbow"
|
4
3
|
require "shellwords"
|
5
4
|
|
6
5
|
module RuboCop
|
7
6
|
module Gradual
|
8
7
|
# Options class defines RuboCop Gradual cli options.
|
9
|
-
# It also extracts command line RuboCop Gradual arguments
|
10
|
-
# before passing leftover arguments to RuboCop::CLI.
|
11
8
|
class Options
|
9
|
+
AUTOCORRECT_KEY =
|
10
|
+
if Gem::Version.new(RuboCop::Version::STRING) >= Gem::Version.new("1.30")
|
11
|
+
:autocorrect
|
12
|
+
else
|
13
|
+
:auto_correct
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@options = {}
|
18
|
+
end
|
19
|
+
|
12
20
|
def parse(args)
|
13
21
|
parser = define_options
|
14
|
-
|
15
|
-
|
16
|
-
|
22
|
+
gradual_args, rubocop_args = filter_args(parser, args_from_file + args)
|
23
|
+
@rubocop_options, _rubocop_paths = RuboCop::Options.new.parse(rubocop_args)
|
24
|
+
parser.parse(gradual_args)
|
25
|
+
|
26
|
+
[@options, @rubocop_options]
|
17
27
|
end
|
18
28
|
|
19
29
|
private
|
20
30
|
|
21
31
|
def define_options
|
22
32
|
OptionParser.new do |opts|
|
23
|
-
opts
|
24
|
-
|
33
|
+
define_mode_options(opts)
|
25
34
|
define_gradual_options(opts)
|
26
35
|
|
27
|
-
|
36
|
+
define_info_options(opts)
|
28
37
|
end
|
29
38
|
end
|
30
39
|
|
31
|
-
def
|
32
|
-
opts.on("-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
def define_mode_options(opts)
|
41
|
+
opts.on("-U", "--force-update", "Force update Gradual lock file.") { @options[:mode] = :force_update }
|
42
|
+
opts.on("-u", "--update", "Same as --force-update (deprecated).") do
|
43
|
+
warn "-u, --update is deprecated. Use -U, --force-update instead."
|
44
|
+
@options[:mode] = :force_update
|
45
|
+
end
|
37
46
|
|
38
|
-
opts.on("--
|
47
|
+
opts.on("--check", "Check Gradual lock file is up-to-date.") { @options[:mode] = :check }
|
48
|
+
opts.on("--ci", "Same as --check (deprecated).") do
|
49
|
+
warn "--ci is deprecated. Use --check instead."
|
50
|
+
@options[:mode] = :check
|
51
|
+
end
|
39
52
|
end
|
40
53
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
54
|
+
def define_gradual_options(opts)
|
55
|
+
opts.on("-a", "--autocorrect", "Autocorrect offenses (only when it's safe).") do
|
56
|
+
@rubocop_options[AUTOCORRECT_KEY] = true
|
57
|
+
@rubocop_options[:"safe_#{AUTOCORRECT_KEY}"] = true
|
58
|
+
@options[:command] = :autocorrect
|
44
59
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
60
|
+
opts.on("-A", "--autocorrect-all", "Autocorrect offenses (safe and unsafe).") do
|
61
|
+
@rubocop_options[AUTOCORRECT_KEY] = true
|
62
|
+
@options[:command] = :autocorrect
|
48
63
|
end
|
49
64
|
|
50
|
-
|
51
|
-
at_exit { puts opts }
|
52
|
-
end
|
65
|
+
opts.on("--gradual-file FILE", "Specify Gradual lock file.") { |path| @options[:path] = path }
|
53
66
|
end
|
54
67
|
|
55
|
-
def
|
56
|
-
opts.on(
|
57
|
-
|
58
|
-
|
68
|
+
def define_info_options(opts)
|
69
|
+
opts.on("-v", "--version", "Display version.") do
|
70
|
+
puts "rubocop-gradual: #{VERSION}, rubocop: #{RuboCop::Version.version}"
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on("-h", "--help", "Prints this help.") do
|
75
|
+
puts opts
|
76
|
+
exit
|
59
77
|
end
|
60
78
|
end
|
61
79
|
|
@@ -86,12 +104,6 @@ module RuboCop
|
|
86
104
|
[]
|
87
105
|
end
|
88
106
|
end
|
89
|
-
|
90
|
-
def rainbow
|
91
|
-
@rainbow ||= Rainbow.new.tap do |r|
|
92
|
-
r.enabled = false if ARGV.include?("--no-color")
|
93
|
-
end
|
94
|
-
end
|
95
107
|
end
|
96
108
|
end
|
97
109
|
end
|
@@ -10,7 +10,7 @@ module RuboCop
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def print_results
|
13
|
-
puts diff.statistics if
|
13
|
+
puts diff.statistics if Configuration.debug?
|
14
14
|
|
15
15
|
send "print_#{diff.state}"
|
16
16
|
end
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
- Run `rubocop-gradual` locally and commit the results, or
|
24
24
|
- EVEN BETTER: before doing the above, try to fix the remaining issues in those files!
|
25
25
|
|
26
|
-
#{bold("`#{
|
26
|
+
#{bold("`#{Configuration.path}` diff:")}
|
27
27
|
|
28
28
|
#{diff.to_s(ARGV.include?("--no-color") ? :text : :color)}
|
29
29
|
MSG
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
|
36
36
|
def print_complete
|
37
37
|
puts bold("RuboCop Gradual is complete!")
|
38
|
-
puts "Removing `#{
|
38
|
+
puts "Removing `#{Configuration.path}` lock file..." if diff.statistics[:fixed].positive?
|
39
39
|
end
|
40
40
|
|
41
41
|
def print_updated
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
def print_new
|
50
50
|
issues_left = diff.statistics[:left]
|
51
51
|
puts bold("RuboCop Gradual got results for the first time. #{issues_left} issue(s) found.")
|
52
|
-
puts "Don't forget to commit `#{
|
52
|
+
puts "Don't forget to commit `#{Configuration.path}` log file."
|
53
53
|
end
|
54
54
|
|
55
55
|
def print_better
|
@@ -61,7 +61,7 @@ module RuboCop
|
|
61
61
|
def print_worse
|
62
62
|
puts bold("Uh oh, RuboCop Gradual got worse:")
|
63
63
|
print_new_issues
|
64
|
-
puts bold("Force updating lock file...") if
|
64
|
+
puts bold("Force updating lock file...") if Configuration.mode == :force_update
|
65
65
|
end
|
66
66
|
|
67
67
|
def print_new_issues
|
@@ -12,40 +12,37 @@ module RuboCop
|
|
12
12
|
attr_reader :new_results, :lock_file
|
13
13
|
|
14
14
|
def initialize(rubocop_result)
|
15
|
-
@lock_file = LockFile.new(
|
16
|
-
@new_results = Results.new(
|
15
|
+
@lock_file = LockFile.new(Configuration.path)
|
16
|
+
@new_results = Results.new(files: rubocop_result)
|
17
17
|
end
|
18
18
|
|
19
19
|
def call
|
20
20
|
diff = CalculateDiff.call(new_results, lock_file.read_results)
|
21
21
|
printer = Printer.new(diff)
|
22
|
-
if print_ci_warning?(diff)
|
23
|
-
printer.print_ci_warning(lock_file.diff(new_results))
|
24
|
-
else
|
25
|
-
printer.print_results
|
26
|
-
end
|
27
22
|
|
28
|
-
|
23
|
+
printer.print_results
|
24
|
+
printer.print_ci_warning(lock_file.diff(new_results)) if fail_with_outdated_lock?(diff)
|
29
25
|
|
30
|
-
|
26
|
+
exit_code = error_code(diff)
|
27
|
+
sync_lock_file(diff) if exit_code.zero?
|
28
|
+
exit_code
|
31
29
|
end
|
32
30
|
|
33
31
|
private
|
34
32
|
|
35
|
-
def
|
36
|
-
|
33
|
+
def fail_with_outdated_lock?(diff)
|
34
|
+
Configuration.mode == :check && diff.state != :no_changes
|
37
35
|
end
|
38
36
|
|
39
37
|
def sync_lock_file(diff)
|
40
|
-
return unless Gradual.exit_code.zero?
|
41
38
|
return lock_file.delete if diff.state == :complete
|
42
39
|
|
43
40
|
lock_file.write_results(new_results)
|
44
41
|
end
|
45
42
|
|
46
43
|
def error_code(diff)
|
47
|
-
return 1 if
|
48
|
-
return 1 if diff.state == :worse &&
|
44
|
+
return 1 if fail_with_outdated_lock?(diff)
|
45
|
+
return 1 if diff.state == :worse && Configuration.mode != :force_update
|
49
46
|
|
50
47
|
0
|
51
48
|
end
|
data/lib/rubocop/gradual.rb
CHANGED
@@ -9,18 +9,5 @@ module RuboCop
|
|
9
9
|
# RuboCop Gradual project namespace
|
10
10
|
module Gradual
|
11
11
|
class Error < StandardError; end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
attr_accessor :debug, :exit_code, :mode, :path
|
15
|
-
|
16
|
-
def set_defaults!
|
17
|
-
self.debug = false
|
18
|
-
self.exit_code = 0
|
19
|
-
self.mode = :base
|
20
|
-
self.path = ".rubocop_gradual.lock"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
set_defaults!
|
25
12
|
end
|
26
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-gradual
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Svyatoslav Kryukov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diff-lcs
|
@@ -107,7 +107,11 @@ files:
|
|
107
107
|
- lib/rubocop-gradual.rb
|
108
108
|
- lib/rubocop/gradual.rb
|
109
109
|
- lib/rubocop/gradual/cli.rb
|
110
|
-
- lib/rubocop/gradual/
|
110
|
+
- lib/rubocop/gradual/commands/autocorrect.rb
|
111
|
+
- lib/rubocop/gradual/commands/base.rb
|
112
|
+
- lib/rubocop/gradual/configuration.rb
|
113
|
+
- lib/rubocop/gradual/formatters/autocorrect.rb
|
114
|
+
- lib/rubocop/gradual/formatters/base.rb
|
111
115
|
- lib/rubocop/gradual/lock_file.rb
|
112
116
|
- lib/rubocop/gradual/options.rb
|
113
117
|
- lib/rubocop/gradual/process.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "benchmark"
|
4
|
-
require "pathname"
|
5
|
-
|
6
|
-
require_relative "process"
|
7
|
-
|
8
|
-
module RuboCop
|
9
|
-
module Gradual
|
10
|
-
# Formatter is a RuboCop formatter class that collects RuboCop results and
|
11
|
-
# calls the Gradual::Process class at the end to process them.
|
12
|
-
class Formatter < RuboCop::Formatter::BaseFormatter
|
13
|
-
include PathUtil
|
14
|
-
|
15
|
-
attr_reader :output_hash
|
16
|
-
|
17
|
-
def initialize(_output, options = {})
|
18
|
-
super
|
19
|
-
Gradual.debug = options[:debug]
|
20
|
-
puts "Gradual mode: #{Gradual.mode}" if Gradual.debug
|
21
|
-
@output_hash = { files: [] }
|
22
|
-
end
|
23
|
-
|
24
|
-
def file_finished(file, offenses)
|
25
|
-
print "."
|
26
|
-
return if offenses.empty?
|
27
|
-
|
28
|
-
output_hash[:files] << {
|
29
|
-
path: smart_path(file),
|
30
|
-
issues: offenses.reject(&:corrected?).map { |o| issue_offense(o) }
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
def finished(_inspected_files)
|
35
|
-
puts "\n#{stats_message}"
|
36
|
-
puts "Processing results..."
|
37
|
-
|
38
|
-
time = Benchmark.realtime { Process.new(output_hash).call }
|
39
|
-
|
40
|
-
puts "Finished Gradual processing in #{time} seconds" if options[:debug] || options[:display_time]
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def issue_offense(offense)
|
46
|
-
{
|
47
|
-
line: offense.line,
|
48
|
-
column: offense.real_column,
|
49
|
-
length: offense.location.length,
|
50
|
-
message: offense.message
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def stats_message
|
55
|
-
issues_count = output_hash[:files].sum { |f| f[:issues].size }
|
56
|
-
"Found #{output_hash[:files].size} files with #{issues_count} issue(s)."
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|