dirtycop 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 53c1b724f0ac87802d4eb831485de2a65244a047
4
+ data.tar.gz: 2f9cf6527aa30e9079121ba5c0dc8fa7ab407d0f
5
+ SHA512:
6
+ metadata.gz: 1046a4e5337aed84fe3ce7f2f300c4f695380c55e1f53d35145d2f43acfa6eb29d7981b154de754742fbc2efb2af4a741f321ffbfe3ca0ff3ffe6a8d6d6b7af7
7
+ data.tar.gz: 5bc6b1b448d329b4a0936e096d218d5ec4fe44a4fa399b5b6829b820e7d7fc37cba96948cb21b9494f921db9287a12effb24d4fc147f3b14c3a004aa29e6976b
data/.gitignore ADDED
@@ -0,0 +1,33 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Documentation cache and generated files:
14
+ /.yardoc/
15
+ /_yardoc/
16
+ /doc/
17
+ /rdoc/
18
+
19
+ ## Environment normalisation:
20
+ /.bundle/
21
+ /vendor/bundle
22
+ /lib/bundler/man/
23
+
24
+ # for a library or gem, you might want to ignore these files since the code is
25
+ # intended to run in multiple environments; otherwise, check them in:
26
+ # Gemfile.lock
27
+ .ruby-version
28
+ .ruby-gemset
29
+
30
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
31
+ .rvmrc
32
+
33
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dirtycop.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dirty-cop (0.0.1)
5
+ rubocop
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.1.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
13
+ parser (2.2.2.6)
14
+ ast (>= 1.1, < 3.0)
15
+ powerpack (0.1.1)
16
+ rainbow (2.0.0)
17
+ rake (10.4.2)
18
+ rubocop (0.32.1)
19
+ astrolabe (~> 1.3)
20
+ parser (>= 2.2.2.5, < 3.0)
21
+ powerpack (~> 0.1)
22
+ rainbow (>= 1.99.1, < 3.0)
23
+ ruby-progressbar (~> 1.4)
24
+ ruby-progressbar (1.7.5)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.7)
31
+ dirty-cop!
32
+ rake (~> 10.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Adam Hess
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Dirty::Cop
2
+
3
+ ## Credit
4
+ A modification of skanev's gist, original found here: https://gist.github.com/skanev/9d4bec97d5a6825eaaf6
5
+
6
+
7
+
8
+ ## Installation
9
+
10
+ ```ruby
11
+ gem 'dirtycop'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install dirtycop
21
+
22
+ ## Usage
23
+
24
+ ```shell
25
+ $ dirty
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/[my-github-username]/dirtycop/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/dirty ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
4
+ require 'rubocop'
5
+ require 'benchmark'
6
+
7
+ changed_files = `git diff --name-only | grep \.rb$`.split("\n") # list of changed ruby files
8
+
9
+ cli = RuboCop::CLI.new
10
+ result = 0
11
+
12
+ time = Benchmark.realtime do
13
+ my_args = ARGV + changed_files
14
+ result = cli.run(my_args)
15
+ end
16
+
17
+ puts "Finished in #{time} seconds" if cli.options[:debug]
18
+ exit result
data/dirtycop.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dirty/cop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dirtycop"
8
+ spec.version = Dirty::Cop::VERSION
9
+ spec.authors = ["Adam Hess"]
10
+ spec.email = ["adamhess1991@gmail.com"]
11
+ spec.summary = %q{Corrupt cop that avoids unchanged violations}
12
+ spec.description = %q{Takes your current diff as the input for rubocop}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['dirty']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rubocop'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,5 @@
1
+ module Dirty
2
+ module Cop
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/dirty/cop.rb ADDED
@@ -0,0 +1,164 @@
1
+ # Modified from skanev's https://gist.github.com/skanev/9d4bec97d5a6825eaaf6
2
+ #
3
+ # A sneaky wrapper around Rubocop that allows you to run it only against
4
+ # the recent changes, as opposed to the whole project. It lets you
5
+ # enforce the style guide for new/modified code only, as opposed to
6
+ # having to restyle everything or adding cops incrementally. It relies
7
+ # on git to figure out which files to check.
8
+ #
9
+ # Here are some options you can pass in addition to the ones in rubocop:
10
+ #
11
+ # --local Check only the changes you are about to push
12
+ # to the remote repository.
13
+ #
14
+ # --uncommitted Check only changes in files that have not been
15
+ # --index committed (i.e. either in working directory or
16
+ # staged).
17
+ #
18
+ # --against REFSPEC Check changes since REFSPEC. This can be
19
+ # anything that git will recognize.
20
+ #
21
+ # --branch Check only changes in the current branch.
22
+ #
23
+ # --courage Without this option, only the modified lines
24
+ # are inspected. When supplied, it will check
25
+ # the full contents of the file. You should have
26
+ # the courage to fix your style violations as
27
+ # you see them, you know.
28
+ #
29
+ # Caveat emptor:
30
+ #
31
+ # * Monkey patching ahead. This script relies on Rubocop internals and
32
+ # has been tested against 0.25.0. Newer (or older) versions might
33
+ # break it.
34
+ #
35
+ # * While it does try to check modified lines only, there might be some
36
+ # quirks. It might not show offenses in modified code if they are
37
+ # reported at unmodified lines. It might also show offenses in
38
+ # unmodified code if they are reported in modified lines.
39
+
40
+ require 'rubocop'
41
+
42
+ module DirtyCop
43
+ extend self # In your face, style guide!
44
+
45
+ def bury_evidence?(file, line)
46
+ process_bribe
47
+ !report_offense_at?(file, line)
48
+ end
49
+
50
+ def uncovered_targets
51
+ @files
52
+ end
53
+
54
+ def cover_up_unmodified(ref, only_changed_lines = true)
55
+ @files ||= files_modified_since(ref)
56
+ @line_filter ||= build_line_filter(@files, ref) if only_changed_lines
57
+ end
58
+
59
+ def process_bribe
60
+ eat_a_donut if ARGV.empty?
61
+ only_changed_lines = true
62
+
63
+ # I am specifying the ref instead of getting it from args since
64
+ # getting it from args seems to be broken
65
+ # ref = nil
66
+ # loop do
67
+ # arg = ARGV.shift
68
+ # case arg
69
+ # when '--local'
70
+ # ref = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`.chomp
71
+ # exit 1 unless $?.success?
72
+ # when '--against'
73
+ # ref = ARGV.shift
74
+ # when '--uncommitted', '--index'
75
+ # ref = 'HEAD'
76
+ # when '--branch'
77
+ # ref = `git merge-base HEAD master`.chomp
78
+ # when '--courage'
79
+ # only_changed_lines = false
80
+ # else
81
+ # ARGV.unshift arg
82
+ # break
83
+ # end
84
+ # end
85
+ # return unless ref
86
+
87
+ ref = 'HEAD'
88
+
89
+ cover_up_unmodified ref, only_changed_lines
90
+ end
91
+
92
+ private
93
+
94
+ def report_offense_at?(file, line)
95
+ !@line_filter || @line_filter.fetch(file)[line]
96
+ end
97
+
98
+ def files_modified_since(ref)
99
+ `git diff --diff-filter=AM --name-only #{ref}`
100
+ .lines
101
+ .map(&:chomp)
102
+ .grep(/\.rb$/)
103
+ .map { |file| File.absolute_path(file) }
104
+ end
105
+
106
+ def build_line_filter(_files, ref)
107
+ result = {}
108
+
109
+ suspects = files_modified_since(ref)
110
+ suspects.each do |file|
111
+ result[file] = lines_modified_since(file, ref)
112
+ end
113
+
114
+ result
115
+ end
116
+
117
+ def lines_modified_since(file, ref)
118
+ ranges =
119
+ `git diff -p -U0 #{ref} #{file}`
120
+ .lines
121
+ .grep(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/) { Regexp.last_match[1].to_i..(Regexp.last_match[1].to_i + Regexp.last_match[2].to_i) }
122
+ .reverse
123
+
124
+ mask = Array.new(ranges.first.end)
125
+
126
+ ranges.each do |range|
127
+ range.each do |line|
128
+ mask[line] = true
129
+ end
130
+ end
131
+
132
+ mask
133
+ end
134
+
135
+ def eat_a_donut
136
+ puts "#{$PROGRAM_NAME}: The dirty cop Alex Murphy could have been"
137
+ puts
138
+ puts File.read(__FILE__)[/(?:^#(?:[^!].*)?\n)+/s].gsub(/^#/, ' ')
139
+ exit
140
+ end
141
+ end
142
+
143
+ module RuboCop
144
+ class TargetFinder
145
+ alias_method :find_unpatched, :find
146
+
147
+ def find(args)
148
+ replacement = DirtyCop.uncovered_targets
149
+ return replacement if replacement
150
+
151
+ find_unpatched(args)
152
+ end
153
+ end
154
+
155
+ class Runner
156
+ alias_method :inspect_file_unpatched, :inspect_file
157
+
158
+ def inspect_file(file)
159
+ offenses, updated = inspect_file_unpatched(file)
160
+ offenses = offenses.reject { |o| DirtyCop.bury_evidence?(file.path, o.line) }
161
+ [offenses, updated]
162
+ end
163
+ end
164
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dirtycop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Hess
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Takes your current diff as the input for rubocop
56
+ email:
57
+ - adamhess1991@gmail.com
58
+ executables:
59
+ - dirty
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/dirty
70
+ - dirtycop.gemspec
71
+ - lib/dirty/cop.rb
72
+ - lib/dirty/cop/version.rb
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.5
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Corrupt cop that avoids unchanged violations
97
+ test_files: []
98
+ has_rdoc: