rubocop-gradual 0.2.0 → 0.3.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 +49 -2
- data/README.md +83 -0
- data/lib/rubocop/gradual/commands/autocorrect.rb +9 -13
- data/lib/rubocop/gradual/commands/base.rb +7 -1
- data/lib/rubocop/gradual/configuration.rb +18 -2
- data/lib/rubocop/gradual/git.rb +34 -0
- data/lib/rubocop/gradual/options.rb +31 -9
- data/lib/rubocop/gradual/patch.rb +32 -0
- data/lib/rubocop/gradual/process/calculate_diff.rb +2 -15
- data/lib/rubocop/gradual/process/diff.rb +2 -9
- data/lib/rubocop/gradual/process.rb +11 -2
- data/lib/rubocop/gradual/rake_task.rb +72 -0
- data/lib/rubocop/gradual/results/issue.rb +1 -1
- data/lib/rubocop/gradual/version.rb +1 -1
- data/lib/rubocop/gradual.rb +5 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8d8cb41d6a825538a0b0411867bcef6864d16ec393f24c7d9f84e05f886caa8
|
4
|
+
data.tar.gz: e7230b837f6f39967e4c472a2a8f466d061da24af7ea9efee060175f0617bb17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 223e2e205074038f7af48b2be3d06d98136ef7d9d65b8bcf3c153d8eee937d4f6f45bada38eaf6a5f8f257e4a95230c8e9a7b19b3158abe9e599bf3ce5e53d45
|
7
|
+
data.tar.gz: 57824cdfee2b8423e88c30f50c95b8f8bba78edfcfd36fe94c73e88e4798eba62c899fb1cefc4719baf08b48422e545e59f86c78affe3a835c3aaa68f9a05c25
|
data/CHANGELOG.md
CHANGED
@@ -7,11 +7,57 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.0] - 2022-10-26
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Partial linting (experimental). ([@skryukov])
|
15
|
+
|
16
|
+
Partial linting is useful when you want to run RuboCop Gradual on a subset of files, for example, on changed files in a pull request:
|
17
|
+
|
18
|
+
```shell
|
19
|
+
rubocop-gradual path/to/file # run `rubocop-gradual` on a subset of files
|
20
|
+
rubocop-gradual --staged # run `rubocop-gradual` on staged files
|
21
|
+
rubocop-gradual --unstaged # run `rubocop-gradual` on unstaged files
|
22
|
+
rubocop-gradual --commit origin/main # run `rubocop-gradual` on changed files since the commit
|
23
|
+
|
24
|
+
# it's possible to combine options with autocorrect:
|
25
|
+
rubocop-gradual --staged --autocorrect # run `rubocop-gradual` with autocorrect on staged files
|
26
|
+
```
|
27
|
+
|
28
|
+
- Require mode (experimental). ([@skryukov])
|
29
|
+
|
30
|
+
RuboCop Gradual can be used in "Require mode", which is a way to replace `rubocop` with `rubocop-gradual`:
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
# .rubocop.yml
|
34
|
+
|
35
|
+
require:
|
36
|
+
- rubocop-gradual
|
37
|
+
```
|
38
|
+
|
39
|
+
- Built-in Rake tasks. ([@skryukov])
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# Rakefile
|
43
|
+
require "rubocop/gradual/rake_task"
|
44
|
+
|
45
|
+
RuboCop::Gradual::RakeTask.new
|
46
|
+
```
|
47
|
+
|
48
|
+
### Fixed
|
49
|
+
|
50
|
+
- Issues with the same location ordered by the message. ([@skryukov])
|
51
|
+
|
10
52
|
## [0.2.0] - 2022-07-26
|
11
53
|
|
12
|
-
|
54
|
+
### Added
|
55
|
+
|
56
|
+
- Autocorrection options. ([@skryukov])
|
13
57
|
Run `rubocop-gradual -a` and `rubocop-gradual -A` to autocorrect new and changed files and then update the lock file.
|
14
58
|
|
59
|
+
### Changed
|
60
|
+
|
15
61
|
- Rename `--ci` to `--check` option. ([@skryukov])
|
16
62
|
|
17
63
|
- Rename `-u, --update` to `-U, --force-update` option. ([@skryukov])
|
@@ -34,7 +80,8 @@ and this project adheres to [Semantic Versioning].
|
|
34
80
|
|
35
81
|
[@skryukov]: https://github.com/skryukov
|
36
82
|
|
37
|
-
[Unreleased]: https://github.com/skryukov/rubocop-gradual/compare/v0.
|
83
|
+
[Unreleased]: https://github.com/skryukov/rubocop-gradual/compare/v0.3.0...HEAD
|
84
|
+
[0.3.0]: https://github.com/skryukov/rubocop-gradual/compare/v0.2.0...v0.3.0
|
38
85
|
[0.2.0]: https://github.com/skryukov/rubocop-gradual/compare/v0.1.1...v0.2.0
|
39
86
|
[0.1.1]: https://github.com/skryukov/rubocop-gradual/compare/v0.1.0...v0.1.1
|
40
87
|
[0.1.0]: https://github.com/skryukov/rubocop-gradual/commits/v0.1.0
|
data/README.md
CHANGED
@@ -54,6 +54,89 @@ Proposed workflow:
|
|
54
54
|
-h, --help Prints this help.
|
55
55
|
```
|
56
56
|
|
57
|
+
## Rake tasks
|
58
|
+
|
59
|
+
To use built-in Rake tasks add the following to your Rakefile:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# Rakefile
|
63
|
+
require "rubocop/gradual/rake_task"
|
64
|
+
|
65
|
+
RuboCop::Gradual::RakeTask.new
|
66
|
+
```
|
67
|
+
|
68
|
+
This will add rake tasks:
|
69
|
+
|
70
|
+
```
|
71
|
+
bundle exec rake -T
|
72
|
+
rake rubocop_gradual # Run RuboCop Gradual
|
73
|
+
rake rubocop_gradual:autocorrect # Run RuboCop Gradual with autocorrect (only when it's safe)
|
74
|
+
rake rubocop_gradual:autocorrect_all # Run RuboCop Gradual with autocorrect (safe and unsafe)
|
75
|
+
rake rubocop_gradual:check # Run RuboCop Gradual to check the lock file
|
76
|
+
rake rubocop_gradual:force_update # Run RuboCop Gradual to force update the lock file
|
77
|
+
```
|
78
|
+
|
79
|
+
It's possible to customize the Rake task name and options:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# Rakefile
|
83
|
+
|
84
|
+
require "rubocop/gradual/rake_task"
|
85
|
+
|
86
|
+
RuboCop::Gradual::RakeTask.new(:custom_task_name) do |task|
|
87
|
+
task.options = %w[--gradual-file custom_gradual_file.lock]
|
88
|
+
task.verbose = false
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
## Partial linting (experimental)
|
93
|
+
|
94
|
+
RuboCop Gradual supports partial linting. It's useful when you want to run RuboCop Gradual on a subset of files, for example, on changed files in a pull request:
|
95
|
+
|
96
|
+
```shell
|
97
|
+
rubocop-gradual path/to/file # run `rubocop-gradual` on a subset of files
|
98
|
+
rubocop-gradual --staged # run `rubocop-gradual` on staged files
|
99
|
+
rubocop-gradual --unstaged # run `rubocop-gradual` on unstaged files
|
100
|
+
rubocop-gradual --commit origin/main # run `rubocop-gradual` on changed files since the commit
|
101
|
+
|
102
|
+
# it's possible to combine options with autocorrect:
|
103
|
+
rubocop-gradual --staged --autocorrect # run `rubocop-gradual` with autocorrect on staged files
|
104
|
+
```
|
105
|
+
|
106
|
+
## Require mode (experimental)
|
107
|
+
|
108
|
+
RuboCop Gradual can be used in "Require mode", which is a way to replace `rubocop` with `rubocop-gradual`:
|
109
|
+
|
110
|
+
```yaml
|
111
|
+
# .rubocop.yml
|
112
|
+
|
113
|
+
require:
|
114
|
+
- rubocop-gradual
|
115
|
+
```
|
116
|
+
|
117
|
+
Now base `rubocop` command will run `rubocop-gradual`:
|
118
|
+
|
119
|
+
```shell
|
120
|
+
rubocop # run `rubocop-gradual`
|
121
|
+
rubocop -a # run `rubocop-gradual` with autocorrect (only when it's safe)
|
122
|
+
rubocop -A # run `rubocop-gradual` with autocorrect (safe and unsafe)
|
123
|
+
rubocop gradual check # run `rubocop-gradual` to check the lock file
|
124
|
+
rubocop gradual force_update # run `rubocop-gradual` to force update the lock file
|
125
|
+
```
|
126
|
+
|
127
|
+
To set a custom path to Gradual lock file, add `--gradual-file FILE` to a special `.rubocop-gradual` file:
|
128
|
+
|
129
|
+
```
|
130
|
+
# .rubocop-gradual
|
131
|
+
--rubocop-gradual-file path/to/my_lock_file.lock
|
132
|
+
```
|
133
|
+
|
134
|
+
To temporarily disable RuboCop Gradual, prepend command with `NO_GRADUAL=1`:
|
135
|
+
|
136
|
+
```shell
|
137
|
+
NO_GRADUAL=1 rubocop # run `rubocop`
|
138
|
+
```
|
139
|
+
|
57
140
|
## Alternatives
|
58
141
|
|
59
142
|
- [RuboCop TODO file]. Comes out of the box with RuboCop. Provides a way to ignore offenses on the file level, which is problematic since it is possible to introduce new offenses without any signal from linter.
|
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
RuboCop::CLI::Environment.new(
|
14
14
|
Configuration.rubocop_options.merge(formatters: [[Formatters::Autocorrect, nil]]),
|
15
15
|
Configuration.rubocop_config_store,
|
16
|
-
|
16
|
+
lint_paths
|
17
17
|
)
|
18
18
|
)
|
19
19
|
runner.run
|
@@ -22,6 +22,12 @@ module RuboCop
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def lint_paths
|
26
|
+
return Configuration.target_file_paths if Configuration.lint_paths.any?
|
27
|
+
|
28
|
+
changed_or_untracked_files.map(&:path)
|
29
|
+
end
|
30
|
+
|
25
31
|
def changed_or_untracked_files
|
26
32
|
tracked_files = LockFile.new(Configuration.path).read_results&.files || []
|
27
33
|
|
@@ -31,20 +37,10 @@ module RuboCop
|
|
31
37
|
end
|
32
38
|
|
33
39
|
def target_files
|
34
|
-
Parallel.map(
|
35
|
-
Results::File.new(path:
|
40
|
+
Parallel.map(Configuration.target_file_paths) do |path|
|
41
|
+
Results::File.new(path: path, issues: [])
|
36
42
|
end
|
37
43
|
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
44
|
end
|
49
45
|
end
|
50
46
|
end
|
@@ -27,12 +27,18 @@ module RuboCop
|
|
27
27
|
RuboCop::CLI::Environment.new(
|
28
28
|
rubocop_options,
|
29
29
|
Configuration.rubocop_config_store,
|
30
|
-
|
30
|
+
lint_paths
|
31
31
|
)
|
32
32
|
)
|
33
33
|
rubocop_runner.run
|
34
34
|
end
|
35
35
|
|
36
|
+
def lint_paths
|
37
|
+
return [] if Configuration.lint_paths.empty?
|
38
|
+
|
39
|
+
Configuration.target_file_paths
|
40
|
+
end
|
41
|
+
|
36
42
|
def rubocop_options
|
37
43
|
Configuration.rubocop_options
|
38
44
|
.slice(:config, :debug, :display_time)
|
@@ -5,11 +5,13 @@ module RuboCop
|
|
5
5
|
# Configuration class stores Gradual and Rubocop options.
|
6
6
|
module Configuration
|
7
7
|
class << self
|
8
|
-
attr_reader :options, :rubocop_options, :rubocop_results
|
8
|
+
attr_reader :options, :rubocop_options, :rubocop_results, :lint_paths, :target_file_paths
|
9
9
|
|
10
|
-
def apply(options = {}, rubocop_options = {})
|
10
|
+
def apply(options = {}, rubocop_options = {}, lint_paths = [])
|
11
11
|
@options = options
|
12
12
|
@rubocop_options = rubocop_options
|
13
|
+
@lint_paths = lint_paths
|
14
|
+
@target_file_paths = rubocop_target_file_paths
|
13
15
|
@rubocop_results = []
|
14
16
|
end
|
15
17
|
|
@@ -38,6 +40,20 @@ module RuboCop
|
|
38
40
|
config_store.options_config = rubocop_options[:config] if rubocop_options[:config]
|
39
41
|
end
|
40
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def rubocop_target_file_paths
|
47
|
+
target_finder = RuboCop::TargetFinder.new(rubocop_config_store, rubocop_options)
|
48
|
+
mode = if rubocop_options[:only_recognized_file_types]
|
49
|
+
:only_recognized_file_types
|
50
|
+
else
|
51
|
+
:all_file_types
|
52
|
+
end
|
53
|
+
target_finder
|
54
|
+
.find(lint_paths, mode)
|
55
|
+
.map { |path| RuboCop::PathUtil.smart_path(path) }
|
56
|
+
end
|
41
57
|
end
|
42
58
|
end
|
43
59
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rbconfig"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Gradual
|
7
|
+
# Git class handles git commands.
|
8
|
+
module Git
|
9
|
+
class << self
|
10
|
+
def paths_by(commit)
|
11
|
+
git_installed!
|
12
|
+
|
13
|
+
case commit
|
14
|
+
when :unstaged
|
15
|
+
`git ls-files --others --exclude-standard -m`.split("\n")
|
16
|
+
when :staged
|
17
|
+
`git diff --cached --name-only`.split("\n")
|
18
|
+
else
|
19
|
+
`git diff --name-only #{commit}`.split("\n")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def git_installed!
|
26
|
+
void = /msdos|mswin|djgpp|mingw/.match?(RbConfig::CONFIG["host_os"]) ? "NUL" : "/dev/null"
|
27
|
+
git_found = `git --version >>#{void} 2>&1`
|
28
|
+
|
29
|
+
raise Error, "Git is not found, please install it first." unless git_found
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "shellwords"
|
4
4
|
|
5
|
+
require_relative "git"
|
6
|
+
|
5
7
|
module RuboCop
|
6
8
|
module Gradual
|
7
9
|
# Options class defines RuboCop Gradual cli options.
|
@@ -20,10 +22,10 @@ module RuboCop
|
|
20
22
|
def parse(args)
|
21
23
|
parser = define_options
|
22
24
|
gradual_args, rubocop_args = filter_args(parser, args_from_file + args)
|
23
|
-
@rubocop_options,
|
25
|
+
@rubocop_options, @lint_paths = RuboCop::Options.new.parse(rubocop_args)
|
24
26
|
parser.parse(gradual_args)
|
25
27
|
|
26
|
-
[@options, @rubocop_options]
|
28
|
+
[@options, @rubocop_options, @lint_paths]
|
27
29
|
end
|
28
30
|
|
29
31
|
private
|
@@ -32,6 +34,7 @@ module RuboCop
|
|
32
34
|
OptionParser.new do |opts|
|
33
35
|
define_mode_options(opts)
|
34
36
|
define_gradual_options(opts)
|
37
|
+
define_lint_paths_options(opts)
|
35
38
|
|
36
39
|
define_info_options(opts)
|
37
40
|
end
|
@@ -65,6 +68,18 @@ module RuboCop
|
|
65
68
|
opts.on("--gradual-file FILE", "Specify Gradual lock file.") { |path| @options[:path] = path }
|
66
69
|
end
|
67
70
|
|
71
|
+
def define_lint_paths_options(opts)
|
72
|
+
opts.on("--unstaged", "Lint unstaged files.") do
|
73
|
+
@lint_paths = git_lint_paths(:unstaged)
|
74
|
+
end
|
75
|
+
opts.on("--staged", "Lint staged files.") do
|
76
|
+
@lint_paths = git_lint_paths(:staged)
|
77
|
+
end
|
78
|
+
opts.on("--commit COMMIT", "Lint files changed since the commit.") do |commit|
|
79
|
+
@lint_paths = git_lint_paths(commit)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
68
83
|
def define_info_options(opts)
|
69
84
|
opts.on("-v", "--version", "Display version.") do
|
70
85
|
puts "rubocop-gradual: #{VERSION}, rubocop: #{RuboCop::Version.version}"
|
@@ -77,15 +92,20 @@ module RuboCop
|
|
77
92
|
end
|
78
93
|
end
|
79
94
|
|
95
|
+
def git_lint_paths(commit)
|
96
|
+
@rubocop_options[:only_recognized_file_types] = true
|
97
|
+
RuboCop::Gradual::Git.paths_by(commit)
|
98
|
+
end
|
99
|
+
|
80
100
|
def filter_args(parser, original_args, self_args = [])
|
81
|
-
extract_all_args(parser).each do |
|
101
|
+
extract_all_args(parser).each do |option|
|
82
102
|
loop do
|
83
|
-
break unless (i = original_args.index { |a| a.start_with?(
|
103
|
+
break unless (i = original_args.index { |a| a.start_with?(option[:name]) })
|
104
|
+
|
105
|
+
self_args << original_args.delete_at(i)
|
106
|
+
next if option[:no_args] || original_args.size <= i || original_args[i].start_with?("-")
|
84
107
|
|
85
|
-
|
86
|
-
self_args << original_args.delete_at(i)
|
87
|
-
break if original_args.size <= i || original_args[i].start_with?("-")
|
88
|
-
end
|
108
|
+
self_args << original_args.delete_at(i)
|
89
109
|
end
|
90
110
|
end
|
91
111
|
[self_args, original_args]
|
@@ -93,7 +113,9 @@ module RuboCop
|
|
93
113
|
|
94
114
|
def extract_all_args(parser)
|
95
115
|
parser.top.list.reduce([]) do |res, option|
|
96
|
-
|
116
|
+
no_args = option.is_a?(OptionParser::Switch::NoArgument)
|
117
|
+
options = (option.long + option.short).map { |o| { name: o, no_args: no_args } }
|
118
|
+
res + options
|
97
119
|
end
|
98
120
|
end
|
99
121
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop-gradual"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Gradual
|
7
|
+
# Patching RuboCop::CLI to enable require mode.
|
8
|
+
module Patch
|
9
|
+
def run_command(name)
|
10
|
+
return super if name != :execute_runner || (ARGV & %w[--stdin -s]).any?
|
11
|
+
|
12
|
+
Configuration.apply(*parse_options)
|
13
|
+
puts "Gradual mode: #{Configuration.mode}" if Configuration.debug?
|
14
|
+
load_command(Configuration.command).call.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def load_command(command)
|
20
|
+
require_relative "commands/#{command}"
|
21
|
+
::RuboCop::Gradual::Commands.const_get(command.to_s.capitalize).new
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_options
|
25
|
+
options, rubocop_options = Options.new.parse(ARGV)
|
26
|
+
options[:mode] = :force_update if @env.paths[0..1] == %w[gradual force_update]
|
27
|
+
options[:mode] = :check if @env.paths[0..1] == %w[gradual check]
|
28
|
+
[options, rubocop_options]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -10,7 +10,7 @@ module RuboCop
|
|
10
10
|
module CalculateDiff
|
11
11
|
class << self
|
12
12
|
def call(new_result, old_result)
|
13
|
-
return Diff.new.
|
13
|
+
return Diff.new.add_files(new_result.files, :new) if old_result.nil?
|
14
14
|
|
15
15
|
diff_results(new_result, old_result)
|
16
16
|
end
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
def diff_results(new_result, old_result)
|
21
21
|
new_files, fixed_files, path_files_match, moved_files_match = split_files(new_result, old_result)
|
22
22
|
|
23
|
-
diff = Diff.new.
|
23
|
+
diff = Diff.new.add_files(new_files, :new).add_files(fixed_files, :fixed)
|
24
24
|
path_files_match.chain(moved_files_match).each do |result_file, old_file|
|
25
25
|
diff_issues(diff, result_file, old_file)
|
26
26
|
end
|
@@ -73,19 +73,6 @@ module RuboCop
|
|
73
73
|
end
|
74
74
|
possibilities.min_by { |possibility| issue.distance(possibility) }
|
75
75
|
end
|
76
|
-
|
77
|
-
def map_same_files(left, right)
|
78
|
-
map_files(left.files, right.files) do |new_file, old_file|
|
79
|
-
new_file.path == old_file.path
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def map_files(key_files, value_files)
|
84
|
-
key_files.each_with_object({}) do |key_file, res|
|
85
|
-
same_file = value_files.find { |value_file| yield(key_file, value_file) }
|
86
|
-
res[key_file] = same_file if same_file
|
87
|
-
end
|
88
|
-
end
|
89
76
|
end
|
90
77
|
end
|
91
78
|
end
|
@@ -33,16 +33,9 @@ module RuboCop
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def add_files(files, key)
|
37
37
|
files.each do |file|
|
38
|
-
add_issues(file.path,
|
39
|
-
end
|
40
|
-
self
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_fixed(files)
|
44
|
-
files.each do |file|
|
45
|
-
add_issues(file.path, fixed: file.issues)
|
38
|
+
add_issues(file.path, **{ key => file.issues })
|
46
39
|
end
|
47
40
|
self
|
48
41
|
end
|
@@ -9,15 +9,17 @@ module RuboCop
|
|
9
9
|
module Gradual
|
10
10
|
# Process is a class that handles the processing of RuboCop results.
|
11
11
|
class Process
|
12
|
-
attr_reader :
|
12
|
+
attr_reader :lock_file, :old_results, :new_results
|
13
13
|
|
14
14
|
def initialize(rubocop_result)
|
15
15
|
@lock_file = LockFile.new(Configuration.path)
|
16
|
+
@old_results = lock_file.read_results
|
16
17
|
@new_results = Results.new(files: rubocop_result)
|
18
|
+
add_skipped_files_to_new_results!
|
17
19
|
end
|
18
20
|
|
19
21
|
def call
|
20
|
-
diff = CalculateDiff.call(new_results,
|
22
|
+
diff = CalculateDiff.call(new_results, old_results)
|
21
23
|
printer = Printer.new(diff)
|
22
24
|
|
23
25
|
printer.print_results
|
@@ -46,6 +48,13 @@ module RuboCop
|
|
46
48
|
|
47
49
|
0
|
48
50
|
end
|
51
|
+
|
52
|
+
def add_skipped_files_to_new_results!
|
53
|
+
return if Configuration.lint_paths.none? || old_results.nil?
|
54
|
+
|
55
|
+
skipped_files = old_results.files.reject { |file| Configuration.target_file_paths.include?(file.path) }
|
56
|
+
new_results.files.concat(skipped_files).sort!
|
57
|
+
end
|
49
58
|
end
|
50
59
|
end
|
51
60
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rake"
|
4
|
+
require "rake/tasklib"
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module Gradual
|
8
|
+
# Rake tasks for RuboCop::Gradual.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# require "rubocop/gradual/rake_task"
|
12
|
+
# RuboCop::Gradual::RakeTask.new
|
13
|
+
#
|
14
|
+
class RakeTask < ::Rake::TaskLib
|
15
|
+
attr_accessor :name, :verbose, :options
|
16
|
+
|
17
|
+
def initialize(name = :rubocop_gradual, *args, &task_block)
|
18
|
+
super()
|
19
|
+
@name = name
|
20
|
+
@verbose = true
|
21
|
+
@options = []
|
22
|
+
define(args, &task_block)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def define(args, &task_block)
|
28
|
+
desc "Run RuboCop Gradual" unless ::Rake.application.last_description
|
29
|
+
define_task(name, nil, args, &task_block)
|
30
|
+
setup_subtasks(args, &task_block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_subtasks(args, &task_block)
|
34
|
+
namespace(name) do
|
35
|
+
desc "Run RuboCop Gradual with autocorrect (only when it's safe)."
|
36
|
+
define_task(:autocorrect, "--autocorrect", args, &task_block)
|
37
|
+
|
38
|
+
desc "Run RuboCop Gradual with autocorrect (safe and unsafe)."
|
39
|
+
define_task(:autocorrect_all, "--autocorrect-all", args, &task_block)
|
40
|
+
|
41
|
+
desc "Run RuboCop Gradual to check the lock file."
|
42
|
+
define_task(:check, "--check", args, &task_block)
|
43
|
+
|
44
|
+
desc "Run RuboCop Gradual to force update the lock file."
|
45
|
+
define_task(:force_update, "--force-update", args, &task_block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def define_task(name, option, args, &task_block)
|
50
|
+
task(name, *args) do |_, task_args|
|
51
|
+
RakeFileUtils.verbose(verbose) do
|
52
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if task_block
|
53
|
+
run_cli(verbose, option)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def run_cli(verbose, option)
|
59
|
+
require "rubocop-gradual"
|
60
|
+
|
61
|
+
cli = CLI.new
|
62
|
+
puts "Running RuboCop Gradual..." if verbose
|
63
|
+
result = cli.run(full_options(option))
|
64
|
+
abort("RuboCop Gradual failed!") if result.nonzero?
|
65
|
+
end
|
66
|
+
|
67
|
+
def full_options(option)
|
68
|
+
option ? options.flatten.unshift(option) : options.flatten
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/rubocop/gradual.rb
CHANGED
@@ -11,3 +11,8 @@ module RuboCop
|
|
11
11
|
class Error < StandardError; end
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
if ENV["NO_GRADUAL"] != "1" && (RuboCop::ConfigLoader.loaded_features & %w[rubocop-gradual rubocop/gradual]).any?
|
16
|
+
require_relative "gradual/patch"
|
17
|
+
RuboCop::CLI.prepend(RuboCop::Gradual::Patch)
|
18
|
+
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.3.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-
|
11
|
+
date: 2022-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diff-lcs
|
@@ -112,13 +112,16 @@ files:
|
|
112
112
|
- lib/rubocop/gradual/configuration.rb
|
113
113
|
- lib/rubocop/gradual/formatters/autocorrect.rb
|
114
114
|
- lib/rubocop/gradual/formatters/base.rb
|
115
|
+
- lib/rubocop/gradual/git.rb
|
115
116
|
- lib/rubocop/gradual/lock_file.rb
|
116
117
|
- lib/rubocop/gradual/options.rb
|
118
|
+
- lib/rubocop/gradual/patch.rb
|
117
119
|
- lib/rubocop/gradual/process.rb
|
118
120
|
- lib/rubocop/gradual/process/calculate_diff.rb
|
119
121
|
- lib/rubocop/gradual/process/diff.rb
|
120
122
|
- lib/rubocop/gradual/process/matcher.rb
|
121
123
|
- lib/rubocop/gradual/process/printer.rb
|
124
|
+
- lib/rubocop/gradual/rake_task.rb
|
122
125
|
- lib/rubocop/gradual/results.rb
|
123
126
|
- lib/rubocop/gradual/results/file.rb
|
124
127
|
- lib/rubocop/gradual/results/issue.rb
|
@@ -149,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
152
|
- !ruby/object:Gem::Version
|
150
153
|
version: '0'
|
151
154
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
155
|
+
rubygems_version: 3.3.7
|
153
156
|
signing_key:
|
154
157
|
specification_version: 4
|
155
158
|
summary: Gradual RuboCop plugin
|