dirtycop 0.0.3 → 0.0.4
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/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/bin/dirty +1 -3
- data/dirtycop.gemspec +1 -1
- data/lib/dirty/cop.rb +46 -32
- data/lib/dirty/cop/version.rb +1 -1
- data/spec/diff_mocks/company +19 -0
- data/spec/diff_mocks/name_only +2 -0
- data/spec/diff_mocks/user +12 -0
- data/spec/dirty/cop_spec.rb +101 -0
- data/spec/spec_helper.rb +3 -0
- metadata +15 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 121d4582aab6c06fa5479d106e623ac34dfe9b43
|
4
|
+
data.tar.gz: 8f4d5b5330c2954bf5d0667b7d96908b59ea73bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b443bb242d5444c345df81c0c5438e7fe59cda4fcefdddbf2c6f005dcef42c43f1f7fa3fa887c0ce0c3d8cee212bee011377041347d6f0cc4ee3811bd54b671e
|
7
|
+
data.tar.gz: 9e956db18397072297a03017d888ea41e9b4ddf915bbd79ae42cb71eefe056303cbffed06e3b4a6fee72b288465ae6c640f6ab412cdc68782dd1518233826c4d
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/bin/dirty
CHANGED
@@ -5,13 +5,11 @@ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib/dirty')
|
|
5
5
|
require 'benchmark'
|
6
6
|
require 'cop'
|
7
7
|
|
8
|
-
changed_files = `git diff --name-only | grep \.rb$`.split("\n") # list of changed ruby files
|
9
|
-
|
10
8
|
cli = RuboCop::CLI.new
|
11
9
|
result = 0
|
12
10
|
|
13
11
|
time = Benchmark.realtime do
|
14
|
-
my_args = ARGV
|
12
|
+
my_args = ARGV
|
15
13
|
result = cli.run(my_args)
|
16
14
|
end
|
17
15
|
|
data/dirtycop.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'dirty/cop/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "dirtycop"
|
8
8
|
spec.version = Dirty::Cop::VERSION
|
9
|
-
spec.authors = ["Adam Hess"]
|
9
|
+
spec.authors = ["Adam Hess", 'Melch']
|
10
10
|
spec.email = ["adamhess1991@gmail.com"]
|
11
11
|
spec.summary = %q{Corrupt cop that avoids unchanged violations}
|
12
12
|
spec.description = %q{Takes your current diff as the input for rubocop}
|
data/lib/dirty/cop.rb
CHANGED
@@ -38,25 +38,32 @@
|
|
38
38
|
# unmodified code if they are reported in modified lines.
|
39
39
|
|
40
40
|
require 'rubocop'
|
41
|
+
# require 'pry'
|
41
42
|
|
42
43
|
module DirtyCop
|
43
44
|
extend self # In your face, style guide!
|
44
45
|
|
45
46
|
def bury_evidence?(file, line)
|
46
|
-
process_bribe
|
47
47
|
!report_offense_at?(file, line)
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
|
50
|
+
def ref
|
51
|
+
'HEAD'
|
52
|
+
end
|
53
|
+
|
54
|
+
def files_to_inspect(whitelisted_files, args)
|
55
|
+
return @files ||= args unless args.empty?
|
56
|
+
|
57
|
+
@files ||= (changed_files(ref) & whitelisted_files)
|
52
58
|
end
|
53
59
|
|
54
60
|
def cover_up_unmodified(ref, only_changed_lines = true)
|
55
|
-
@
|
56
|
-
@line_filter ||= build_line_filter(@files, ref) if only_changed_lines
|
61
|
+
@line_filter ||= changed_files_and_lines(ref) if only_changed_lines
|
57
62
|
end
|
58
63
|
|
59
64
|
def process_bribe
|
65
|
+
# leaving this unused method as a placeholder of flags that purportedly work
|
66
|
+
# (potential feature set)
|
60
67
|
only_changed_lines = true
|
61
68
|
|
62
69
|
# I am specifying the ref above instead of getting it from args since
|
@@ -83,52 +90,62 @@ module DirtyCop
|
|
83
90
|
# end
|
84
91
|
# return unless ref
|
85
92
|
|
86
|
-
ref = 'HEAD'
|
87
|
-
|
88
93
|
cover_up_unmodified ref, only_changed_lines
|
89
94
|
end
|
90
95
|
|
91
|
-
private
|
92
|
-
|
93
96
|
def report_offense_at?(file, line)
|
94
|
-
|
97
|
+
changed_lines_for_file(file).include? line
|
95
98
|
end
|
96
99
|
|
97
|
-
def
|
98
|
-
|
100
|
+
def changed_lines_for_file(file)
|
101
|
+
changed_files_and_lines(ref)[file] || []
|
102
|
+
end
|
103
|
+
|
104
|
+
def changed_files(ref)
|
105
|
+
@changed_files ||= git_diff_name_only
|
99
106
|
.lines
|
100
107
|
.map(&:chomp)
|
101
108
|
.grep(/\.rb$/)
|
102
109
|
.map { |file| File.absolute_path(file) }
|
103
110
|
end
|
104
111
|
|
105
|
-
def
|
112
|
+
def git_diff_name_only
|
113
|
+
`git diff --diff-filter=AM --name-only #{ref}`
|
114
|
+
end
|
115
|
+
|
116
|
+
def changed_files_and_lines(ref)
|
106
117
|
result = {}
|
107
118
|
|
108
|
-
|
109
|
-
|
110
|
-
result[file] = lines_modified_since(file, ref)
|
119
|
+
changed_files(ref).each do |file|
|
120
|
+
result[file] = changed_lines(file, ref)
|
111
121
|
end
|
112
122
|
|
113
123
|
result
|
114
124
|
end
|
115
125
|
|
116
|
-
def
|
117
|
-
|
118
|
-
|
119
|
-
.lines
|
120
|
-
.grep(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/) { Regexp.last_match[1].to_i..(Regexp.last_match[1].to_i + Regexp.last_match[2].to_i) }
|
121
|
-
.reverse
|
122
|
-
|
123
|
-
mask = Array.new(ranges.first.end)
|
126
|
+
def git_diff(file, ref)
|
127
|
+
`git diff -p -U0 #{ref} #{file}`
|
128
|
+
end
|
124
129
|
|
125
|
-
|
126
|
-
|
127
|
-
|
130
|
+
def changed_lines(file, ref)
|
131
|
+
ranges = git_diff(file, ref)
|
132
|
+
.each_line
|
133
|
+
.grep(/@@ -(\d+)(?:,)?(\d+)? \+(\d+)(?:,)?(\d+)? @@/) {
|
134
|
+
[
|
135
|
+
Regexp.last_match[3].to_i,
|
136
|
+
(Regexp.last_match[4] || 1).to_i
|
137
|
+
]
|
138
|
+
}.reverse
|
139
|
+
|
140
|
+
mask = Set.new
|
141
|
+
|
142
|
+
ranges.each do |changed_line_number, number_of_changed_lines|
|
143
|
+
number_of_changed_lines.times do |line_delta|
|
144
|
+
mask << changed_line_number + line_delta
|
128
145
|
end
|
129
146
|
end
|
130
147
|
|
131
|
-
mask
|
148
|
+
mask.to_a
|
132
149
|
end
|
133
150
|
|
134
151
|
def eat_a_donut
|
@@ -144,10 +161,7 @@ module RuboCop
|
|
144
161
|
alias_method :find_unpatched, :find
|
145
162
|
|
146
163
|
def find(args)
|
147
|
-
|
148
|
-
return replacement if replacement
|
149
|
-
|
150
|
-
find_unpatched(args)
|
164
|
+
DirtyCop.files_to_inspect(find_unpatched(args), args)
|
151
165
|
end
|
152
166
|
end
|
153
167
|
|
data/lib/dirty/cop/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
[1mdiff --git a/app/models/submittal_package.rb b/app/models/submittal_package.rb[m
|
2
|
+
[1mindex 9ec391b..b39fff7 100755[m
|
3
|
+
[1m--- a/app/models/submittal_package.rb[m
|
4
|
+
[1m+++ b/app/models/submittal_package.rb[m
|
5
|
+
[36m@@ -4 +4 @@[m
|
6
|
+
[31m-#[m
|
7
|
+
[32m+[m[32m# foo[m
|
8
|
+
[36m@@ -6,4 +6,4 @@[m
|
9
|
+
[31m-# project_id :integer[m
|
10
|
+
[31m-# specification_section_id :integer[m
|
11
|
+
[31m-# created_at :datetime[m
|
12
|
+
[31m-# deleted_at :datetime[m
|
13
|
+
[32m+[m[32m# project_id :integer foo[m
|
14
|
+
[32m+[m[32m# specification_section_id :integer foo[m
|
15
|
+
[32m+[m[32m# created_at :datetime foo[m
|
16
|
+
[32m+[m[32m# deleted_at :datetime foo[m
|
17
|
+
[36m@@ -12 +12 @@[m
|
18
|
+
[31m-# created_by_id :integer[m
|
19
|
+
[32m+[m[32m# created_by_id :integer foo[m
|
@@ -0,0 +1,12 @@
|
|
1
|
+
[1mdiff --git a/spec/models/submittal_log_spec.rb b/spec/models/submittal_log_spec.rb[m
|
2
|
+
[1mindex f9c743f..de36350 100755[m
|
3
|
+
[1m--- a/spec/models/submittal_log_spec.rb[m
|
4
|
+
[1m+++ b/spec/models/submittal_log_spec.rb[m
|
5
|
+
[36m@@ -2,2 +2,2 @@[m [mrequire 'rails_helper'[m
|
6
|
+
[31m-require 'shared_examples_for_location_name_setter'[m
|
7
|
+
[31m-[m
|
8
|
+
[32m+[m[32mrequire 'shared_examples_for_location_name_setter' bar[m
|
9
|
+
[32m+[m[32m bar[m
|
10
|
+
[36m@@ -6 +6 @@[m [mRSpec.describe SubmittalLog, type: :model do[m
|
11
|
+
[31m- let(:project) { FactoryGirl.create(:project, time_zone: "Pacific Time (US & Canada)") }[m
|
12
|
+
[32m+[m[32m let(:project) { FactoryGirl.create(:project, time_zone: "Pacific Time (US & Canada)") } bar[m
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
class RubocopTest
|
6
|
+
include DirtyCop
|
7
|
+
end
|
8
|
+
|
9
|
+
describe DirtyCop do
|
10
|
+
let(:rubocop) { RubocopTest.new }
|
11
|
+
let(:ref) { 'HEAD' }
|
12
|
+
|
13
|
+
describe '#files_to_inspect' do
|
14
|
+
context 'files passed in' do
|
15
|
+
it 'returns files passed into rubocop that have changes' do
|
16
|
+
files = ['company', 'user']
|
17
|
+
rubocop_allowed_files = ['dont_care']
|
18
|
+
result = rubocop.files_to_inspect(rubocop_allowed_files, files)
|
19
|
+
expect(result).to eq(files)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'no files passed in' do
|
24
|
+
it 'returns all files that have changes' do
|
25
|
+
changed_files = ['company', 'user']
|
26
|
+
rubocop_allowed_files = changed_files
|
27
|
+
rubocop.stub(:changed_files) { changed_files }
|
28
|
+
|
29
|
+
result = rubocop.files_to_inspect(rubocop_allowed_files, [])
|
30
|
+
expect(result).to eq(changed_files)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns files that have changes that are okayed by rubocop' do
|
34
|
+
changed_files = ['company', 'user', 'project']
|
35
|
+
rubocop_allowed_files = ['app', 'company', 'user']
|
36
|
+
rubocop.stub(:changed_files) { changed_files }
|
37
|
+
|
38
|
+
result = rubocop.files_to_inspect(rubocop_allowed_files, [])
|
39
|
+
expect(result).to eq(['company', 'user'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#changed_files' do
|
45
|
+
it 'returns an array of full path of files changed' do
|
46
|
+
rubocop.stub(:git_diff_name_only) { File.open('spec/diff_mocks/name_only') }
|
47
|
+
expected = [
|
48
|
+
"#{Dir.pwd}/lib/dirty/cop.rb",
|
49
|
+
"#{Dir.pwd}/spec/dirty/cop_spec.rb"
|
50
|
+
]
|
51
|
+
expect(rubocop.changed_files(ref)).to eq(expected)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#changed_lines' do
|
56
|
+
let(:file) { 'company' }
|
57
|
+
|
58
|
+
it 'returns an array, containing line numbers that have changed' do
|
59
|
+
rubocop.stub(:git_diff) { File.open('spec/diff_mocks/company') }
|
60
|
+
result = rubocop.changed_lines(file, ref)
|
61
|
+
expected = [4, 6, 7, 8, 9, 12]
|
62
|
+
expect(result.sort).to eq(expected)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#report_offense_at?' do
|
67
|
+
it 'should respond if a line was changed at past file and line' do
|
68
|
+
changed_files_and_lines = {
|
69
|
+
'company' => [4, 6, 7, 8, 9, 12],
|
70
|
+
'user' => [2, 3, 6]
|
71
|
+
}
|
72
|
+
rubocop.stub(:changed_files_and_lines) { changed_files_and_lines }
|
73
|
+
expect(rubocop.report_offense_at?('company', 6)).to be_truthy
|
74
|
+
expect(rubocop.report_offense_at?('company', 1)).to be_falsy
|
75
|
+
expect(rubocop.report_offense_at?('other_file', 6)).to be_falsy
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should not blow up if no files were changed' do
|
79
|
+
changed_files_and_lines = {}
|
80
|
+
rubocop.stub(:changed_files_and_lines) { changed_files_and_lines }
|
81
|
+
expect(rubocop.report_offense_at?('company', 1)).to be_falsy
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#changed_files_and_lines' do
|
86
|
+
it 'should return a hash with filenames and changed lines' do
|
87
|
+
rubocop.stub(:changed_files) { %w(company user) }
|
88
|
+
rubocop.stub(:git_diff).with('company', 'HEAD') { File.open('spec/diff_mocks/company') }
|
89
|
+
rubocop.stub(:git_diff).with('user', 'HEAD') { File.open('spec/diff_mocks/user') }
|
90
|
+
expected = {
|
91
|
+
'company' => [4, 6, 7, 8, 9, 12],
|
92
|
+
'user' => [2, 3, 6]
|
93
|
+
}
|
94
|
+
result = rubocop.changed_files_and_lines(ref)
|
95
|
+
expect(result.keys).to eq(expected.keys)
|
96
|
+
result.keys.each do |key|
|
97
|
+
expect(result[key].sort).to eq(expected[key].sort)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dirtycop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hess
|
8
|
+
- Melch
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rubocop
|
@@ -70,6 +71,11 @@ files:
|
|
70
71
|
- dirtycop.gemspec
|
71
72
|
- lib/dirty/cop.rb
|
72
73
|
- lib/dirty/cop/version.rb
|
74
|
+
- spec/diff_mocks/company
|
75
|
+
- spec/diff_mocks/name_only
|
76
|
+
- spec/diff_mocks/user
|
77
|
+
- spec/dirty/cop_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
73
79
|
homepage: ''
|
74
80
|
licenses:
|
75
81
|
- MIT
|
@@ -90,9 +96,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
96
|
version: '0'
|
91
97
|
requirements: []
|
92
98
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.2.2
|
94
100
|
signing_key:
|
95
101
|
specification_version: 4
|
96
102
|
summary: Corrupt cop that avoids unchanged violations
|
97
|
-
test_files:
|
98
|
-
|
103
|
+
test_files:
|
104
|
+
- spec/diff_mocks/company
|
105
|
+
- spec/diff_mocks/name_only
|
106
|
+
- spec/diff_mocks/user
|
107
|
+
- spec/dirty/cop_spec.rb
|
108
|
+
- spec/spec_helper.rb
|