rubocop_lineup 0.1.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -1
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +17 -3
- data/Appraisals +29 -0
- data/Gemfile +4 -0
- data/README.md +40 -11
- data/gemfiles/rubocop_0.35.1.gemfile +13 -0
- data/gemfiles/rubocop_0.46.0.gemfile +13 -0
- data/gemfiles/rubocop_0.52.1.gemfile +13 -0
- data/gemfiles/rubocop_0.56.0.gemfile +13 -0
- data/gemfiles/rubocop_0.58.2.gemfile +13 -0
- data/gemfiles/rubocop_0.69.0.gemfile +13 -0
- data/gemfiles/rubocop_latest.gemfile +13 -0
- data/lib/rubocop_lineup.rb +20 -5
- data/lib/rubocop_lineup/diff_liner.rb +11 -10
- data/lib/rubocop_lineup/duck_punch_rubocop.rb +46 -0
- data/lib/rubocop_lineup/line_number_calculator.rb +1 -3
- data/lib/rubocop_lineup/version.rb +1 -1
- data/rubocop_lineup.gemspec +5 -4
- metadata +33 -12
- data/lib/rubocop_lineup/monkey_patch_rubocop.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef6cd25bb513449b7e8a8e4393667bcc3f14eb7e368a75a05ec51cbe74a3aeec
|
4
|
+
data.tar.gz: 1c8777485957331c3446e24f20c8d8e04e8dfe0f3ac5ec7f1382c9fecb639c56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5b99a93b516be211e3b1442d2727b46df48b8c6b972b93745983e555e3bacd5a8eb8b2eea034ec420f9a6a29ecdc36fff45fa46e87cdfe1d1379f254ed80302
|
7
|
+
data.tar.gz: 5f6bfa3a6808c1d4e95ee1f21f63749a33f3196c266698be650081fbb9ab64b760ed16da397c0e50c927ed0df820faf19a1e65265e1728e8b1f42f4cfc229886
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.3
|
data/.travis.yml
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
2
|
+
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
|
4
|
+
- 2.3.8
|
5
|
+
- 2.4.6
|
6
|
+
- 2.5.5
|
7
|
+
- 2.6.3
|
8
|
+
|
9
|
+
gemfile:
|
10
|
+
- gemfiles/rubocop_latest.gemfile
|
11
|
+
- gemfiles/rubocop_0.69.0.gemfile
|
12
|
+
- gemfiles/rubocop_0.58.2.gemfile
|
13
|
+
- gemfiles/rubocop_0.56.0.gemfile
|
14
|
+
- gemfiles/rubocop_0.52.1.gemfile
|
15
|
+
- gemfiles/rubocop_0.46.0.gemfile
|
16
|
+
- gemfiles/rubocop_0.35.1.gemfile
|
17
|
+
|
18
|
+
|
19
|
+
before_install: gem install bundler -v 1.17.3
|
data/Appraisals
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise "rubocop-latest" do
|
4
|
+
gem "rubocop"
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise "rubocop-0.69.0" do
|
8
|
+
gem "rubocop", "0.69.0"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "rubocop-0.58.2" do
|
12
|
+
gem "rubocop", "0.58.2"
|
13
|
+
end
|
14
|
+
|
15
|
+
appraise "rubocop-0.56.0" do
|
16
|
+
gem "rubocop", "0.56.0"
|
17
|
+
end
|
18
|
+
|
19
|
+
appraise "rubocop-0.52.1" do
|
20
|
+
gem "rubocop", "0.52.1"
|
21
|
+
end
|
22
|
+
|
23
|
+
appraise "rubocop-0.46.0" do
|
24
|
+
gem "rubocop", "0.46.0"
|
25
|
+
end
|
26
|
+
|
27
|
+
appraise "rubocop-0.35.1" do
|
28
|
+
gem "rubocop", "0.35.1"
|
29
|
+
end
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,37 +1,66 @@
|
|
1
1
|
# RubocopLineup
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.com/mysterysci/rubocop_lineup.svg?branch=master)](https://travis-ci.com/mysterysci/rubocop_lineup)
|
4
|
+
|
5
|
+
![Image of Old-Timey Police Lineup](https://upload.wikimedia.org/wikipedia/commons/0/04/Oppstilling-2.jpg)
|
6
|
+
|
7
|
+
If yer trying to bring in a new sheriff to the wild, wild west of your legacy codebase,
|
8
|
+
there's gonna be some outlaws that are just too ornery to contend with. Better to just
|
9
|
+
leave those scoundrels be that aren't in your crosshairs and let yer deputies focus on
|
10
|
+
what's at hand.
|
11
|
+
|
12
|
+
This gem presumes yer a-usin' git for yer revisionin' purposes. For now, it also figgers
|
13
|
+
yer always branchin' from master, which, I know, I know, that ain't always how ever'body
|
14
|
+
out here on the frontier likes to operate, but hey, we're just gettin' started here.
|
15
|
+
|
16
|
+
Also, you should know goin' in that we're duck punchin' into a sweet spot of the Rubocop
|
17
|
+
underbelly, and well, we just may get to fightin' in the future if them Rubocop folk
|
18
|
+
get some fancy refactorin' ideas.
|
19
|
+
|
20
|
+
Not to mention that some o' yer tougher deputies may get sidelined if they need more than
|
21
|
+
a changed line to do thar job ... we'll just have to see about all that down the road.
|
22
|
+
|
23
|
+
I'm not sure how we fell into a old western theme here with a modern robot-type gem, but
|
24
|
+
sometimes ... well, sometimes, the bear eats you.
|
4
25
|
|
5
26
|
## Installation
|
6
27
|
|
7
|
-
Add this
|
28
|
+
Add this to yer Gemfile:
|
8
29
|
|
9
30
|
```ruby
|
10
31
|
gem 'rubocop_lineup'
|
11
32
|
```
|
12
33
|
|
13
|
-
And then
|
34
|
+
And then bundle that up:
|
14
35
|
|
15
36
|
$ bundle
|
16
37
|
|
17
|
-
Or
|
38
|
+
Or just put it in with all yer other gems if so inclined:
|
18
39
|
|
19
40
|
$ gem install rubocop_lineup
|
20
41
|
|
21
42
|
## Usage
|
22
43
|
|
23
|
-
|
44
|
+
To use it regular-like, add this to the
|
45
|
+
[require section](https://github.com/bbatsov/rubocop/blob/master/manual/extensions.md#loading-extensions)
|
46
|
+
of .rubocop.yml:
|
24
47
|
|
25
|
-
|
26
|
-
|
27
|
-
|
48
|
+
```yaml
|
49
|
+
require:
|
50
|
+
- rubocop_lineup
|
51
|
+
```
|
28
52
|
|
29
|
-
|
53
|
+
If you only need to use it ever' now-n-again, inform yer rubocop with the
|
54
|
+
`-r rubocop_lineup` option.
|
30
55
|
|
31
56
|
## Contributing
|
32
57
|
|
33
|
-
|
58
|
+
We'd appreciate hearin' some of yer good ideas about our lil project here, and maybe
|
59
|
+
even if'in you have a problemo or two with it, you might could get some help here
|
60
|
+
with that. Mosey over to the project at https://github.com/mysterysci/rubocop_lineup
|
61
|
+
and have a shot or two with us.
|
34
62
|
|
35
63
|
## License
|
36
64
|
|
37
|
-
|
65
|
+
This gem is one o' them open source deals, and our danged lawyers told us we should
|
66
|
+
refer you to this here pronouncement: [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/rubocop_lineup.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
require "rubocop_lineup/version"
|
4
4
|
require "rubocop_lineup/line_number_calculator"
|
5
5
|
require "rubocop_lineup/diff_liner"
|
6
|
-
require "rubocop_lineup/
|
6
|
+
require "rubocop_lineup/duck_punch_rubocop"
|
7
|
+
require "yaml"
|
7
8
|
|
8
9
|
module RubocopLineup
|
9
10
|
# This defaults the parent branch to 'master'. This is a reasonable
|
@@ -12,18 +13,20 @@ module RubocopLineup
|
|
12
13
|
# parent branch. There are ways to calculate the parent branch name
|
13
14
|
# that cover common cases, but that's more complicated and may be added
|
14
15
|
# in a future version.
|
15
|
-
def self.line_em_up(directory,
|
16
|
+
def self.line_em_up(directory, base_branch = nil)
|
17
|
+
base_branch ||= base_branch_from_config || "master"
|
18
|
+
|
16
19
|
@line_em_up ||= begin
|
17
20
|
Dir.chdir(directory) do
|
18
|
-
|
19
|
-
|
21
|
+
uncommitted = DiffLiner.diff_uncommitted.file_line_changes
|
22
|
+
committed_on_branch = DiffLiner.diff_branch(base_branch).file_line_changes
|
20
23
|
|
21
24
|
# When a file has committed changes AND uncommitted_changes,
|
22
25
|
# we will only include the lines from the uncommitted changes
|
23
26
|
# because the lines in the previous committed changes may not
|
24
27
|
# be accurate anymore. See test suite for a sample case.
|
25
28
|
|
26
|
-
|
29
|
+
committed_on_branch.merge(uncommitted)
|
27
30
|
end
|
28
31
|
end
|
29
32
|
end
|
@@ -31,4 +34,16 @@ module RubocopLineup
|
|
31
34
|
def self.reset
|
32
35
|
@line_em_up = nil
|
33
36
|
end
|
37
|
+
|
38
|
+
def self.rubocop_lineup_config_file
|
39
|
+
".rubocop_lineup.yml"
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.base_branch_from_config
|
43
|
+
return unless File.exist?(rubocop_lineup_config_file)
|
44
|
+
|
45
|
+
settings = YAML.load_file(rubocop_lineup_config_file)
|
46
|
+
|
47
|
+
settings[:base_branch]
|
48
|
+
end
|
34
49
|
end
|
@@ -6,11 +6,11 @@ module RubocopLineup
|
|
6
6
|
# This class depends on git diffs generated the with -U0 option.
|
7
7
|
class DiffLiner
|
8
8
|
def self.diff_uncommitted(dir = Dir.pwd)
|
9
|
-
new(diff_from(dir, "HEAD"))
|
9
|
+
new(diff_from(dir, "HEAD"), dir)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.diff_branch(parent_branch, dir = Dir.pwd)
|
13
|
-
new(diff_from(dir, "#{parent_branch}..."))
|
13
|
+
new(diff_from(dir, "#{parent_branch}..."), dir)
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.diff_from(dir, obj)
|
@@ -22,26 +22,27 @@ module RubocopLineup
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Expects a Git::Diff instance, which handles parsing diff output into files.
|
25
|
-
def initialize(diff)
|
26
|
-
@
|
25
|
+
def initialize(diff, dir)
|
26
|
+
@dir = dir
|
27
|
+
process(diff)
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
-
@
|
30
|
+
def filenames
|
31
|
+
@data_full_paths.keys
|
31
32
|
end
|
32
33
|
|
33
|
-
def
|
34
|
-
@
|
34
|
+
def file_line_changes
|
35
|
+
@data_full_paths
|
35
36
|
end
|
36
37
|
|
37
38
|
private
|
38
39
|
|
39
40
|
def process(diff)
|
40
|
-
Hash[diff.map { |diff_file| process_diff_file(diff_file) }]
|
41
|
+
@data_full_paths = Hash[diff.map { |diff_file| process_diff_file(diff_file) }]
|
41
42
|
end
|
42
43
|
|
43
44
|
def process_diff_file(diff_file)
|
44
|
-
[diff_file.path,
|
45
|
+
[File.join(@dir, diff_file.path),
|
45
46
|
calc_line_numbers(diff_file.patch.scan(/@@(.*)@@/).flatten)]
|
46
47
|
end
|
47
48
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module DuckPunch
|
6
|
+
module CommentConfig
|
7
|
+
def cop_enabled_at_line?(cop, line_number)
|
8
|
+
source_file = processed_source.path
|
9
|
+
files_hash = RubocopLineup.line_em_up(Dir.pwd)
|
10
|
+
return false unless files_hash.key?(source_file)
|
11
|
+
|
12
|
+
changed_line_numbers = files_hash[source_file]
|
13
|
+
changed_line_numbers.include?(line_number) ? super : false
|
14
|
+
|
15
|
+
# Removing support for any line of a block where one or more lines were changed.
|
16
|
+
# It's too unpredictable. Linter cops should probably never do this, but I'm
|
17
|
+
# not sure how to go about that right now.
|
18
|
+
#
|
19
|
+
# offending_lines = (line_number..(last_line || line_number)).to_a
|
20
|
+
# changed_line_numbers = files_hash[source_file]
|
21
|
+
# (changed_line_numbers & offending_lines).empty? ? false : super
|
22
|
+
end
|
23
|
+
|
24
|
+
def last_line
|
25
|
+
# `loc_end` will be nil in cases like Parser::Source::Map::Collection
|
26
|
+
# https://www.rubydoc.info/github/whitequark/parser/Parser/Source/Map/Collection
|
27
|
+
# which point to the entire file, but presumably won't have any range
|
28
|
+
# cops analyzing it (e.g. Gemfile is like this).
|
29
|
+
|
30
|
+
loc_end = processed_source.ast.loc.end
|
31
|
+
loc_end ? loc_end.line : nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module TargetFinder
|
36
|
+
def find(args)
|
37
|
+
# returns an array of full file paths that are the files to inspect.
|
38
|
+
files = super(args)
|
39
|
+
files_hash = RubocopLineup.line_em_up(Dir.pwd)
|
40
|
+
files & files_hash.keys
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RuboCop::CommentConfig.prepend(DuckPunch::CommentConfig)
|
46
|
+
RuboCop::TargetFinder.prepend(DuckPunch::TargetFinder)
|
@@ -6,9 +6,7 @@ module RubocopLineup
|
|
6
6
|
# presumes the text has been parsed already to just the -/+ bits
|
7
7
|
# e.g. "-1 +1"
|
8
8
|
def self.git_line_summary_to_numbers(text)
|
9
|
-
|
10
|
-
_changed, added = text.split(/ /).reject(&:empty?)
|
11
|
-
start, count = added.sub(/^-/, "").split(/,/).map(&:to_i)
|
9
|
+
start, count = text.scan(/\+(.*)/).join.scan(/\d+/).flatten.map(&:to_i)
|
12
10
|
count ||= 1
|
13
11
|
(start..(start + count - 1)).to_a
|
14
12
|
end
|
data/rubocop_lineup.gemspec
CHANGED
@@ -21,12 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.required_ruby_version = "~> 2.
|
24
|
+
spec.required_ruby_version = "~> 2.3"
|
25
25
|
|
26
26
|
spec.add_dependency "git", "~> 1.3"
|
27
|
-
spec.add_dependency "rubocop", "~> 0.
|
27
|
+
spec.add_dependency "rubocop", "~> 0.35"
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler", "
|
30
|
-
spec.add_development_dependency "
|
29
|
+
spec.add_development_dependency "bundler", "> 1.16"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
31
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop_lineup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrismo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -30,42 +30,56 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.35'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.35'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.16'
|
48
48
|
type: :development
|
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: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '12.3'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '12.3'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,16 +106,24 @@ files:
|
|
92
106
|
- ".rubocop.yml"
|
93
107
|
- ".ruby-version"
|
94
108
|
- ".travis.yml"
|
109
|
+
- Appraisals
|
95
110
|
- Gemfile
|
96
111
|
- LICENSE.txt
|
97
112
|
- README.md
|
98
113
|
- Rakefile
|
99
114
|
- bin/console
|
100
115
|
- bin/setup
|
116
|
+
- gemfiles/rubocop_0.35.1.gemfile
|
117
|
+
- gemfiles/rubocop_0.46.0.gemfile
|
118
|
+
- gemfiles/rubocop_0.52.1.gemfile
|
119
|
+
- gemfiles/rubocop_0.56.0.gemfile
|
120
|
+
- gemfiles/rubocop_0.58.2.gemfile
|
121
|
+
- gemfiles/rubocop_0.69.0.gemfile
|
122
|
+
- gemfiles/rubocop_latest.gemfile
|
101
123
|
- lib/rubocop_lineup.rb
|
102
124
|
- lib/rubocop_lineup/diff_liner.rb
|
125
|
+
- lib/rubocop_lineup/duck_punch_rubocop.rb
|
103
126
|
- lib/rubocop_lineup/line_number_calculator.rb
|
104
|
-
- lib/rubocop_lineup/monkey_patch_rubocop.rb
|
105
127
|
- lib/rubocop_lineup/version.rb
|
106
128
|
- rubocop_lineup.gemspec
|
107
129
|
homepage: https://github.com/mysterysci/rubocop_lineup
|
@@ -116,15 +138,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
138
|
requirements:
|
117
139
|
- - "~>"
|
118
140
|
- !ruby/object:Gem::Version
|
119
|
-
version: '2.
|
141
|
+
version: '2.3'
|
120
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
143
|
requirements:
|
122
144
|
- - ">="
|
123
145
|
- !ruby/object:Gem::Version
|
124
146
|
version: '0'
|
125
147
|
requirements: []
|
126
|
-
|
127
|
-
rubygems_version: 2.6.14.1
|
148
|
+
rubygems_version: 3.0.3
|
128
149
|
signing_key:
|
129
150
|
specification_version: 4
|
130
151
|
summary: Rubocop plugin to restrict cops to only changed lines.
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rubocop"
|
4
|
-
|
5
|
-
module DuckPunch
|
6
|
-
module CommentConfig
|
7
|
-
def cop_enabled_at_line?(cop, line_number)
|
8
|
-
source_file = processed_source.path.sub("#{Dir.pwd}/", "")
|
9
|
-
files_hash = RubocopLineup.line_em_up(Dir.pwd)
|
10
|
-
return false unless files_hash.key?(source_file)
|
11
|
-
changed_line_numbers = files_hash[source_file]
|
12
|
-
changed_line_numbers.include?(line_number) ? super : false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
RuboCop::CommentConfig.prepend(DuckPunch::CommentConfig)
|