rubocop_lineup 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cfa56198440d7781eaacc424900d3138531ce33
4
- data.tar.gz: 167f93d1795b139ea974f6a1c8f3a6ff16721fe4
3
+ metadata.gz: 2a55e094b399226f398dbad21723ff58589c3988
4
+ data.tar.gz: 9f56dead4432a8a87c85d070093d311600500e9d
5
5
  SHA512:
6
- metadata.gz: 625887be5c29eb398c84e41787a06a853fbdd96826fbac4d10eace54113eacf6071cdb8ab08bcc6859f6ab5a04b4f28da2957c422a31706d59bc96571a8f2bd0
7
- data.tar.gz: e15d9f1a333954e0cbb2e701b0b4424ef5446fec35378de6e052fb3af277905e4020554810ce0936fc76a17ba9ec38ff510eeecc549d577f40a11a3ce711ba34
6
+ metadata.gz: e75a2f07204d1a6cfeadbcb71051c2f9ecff7194909f32dd5c01ca709e5fd0719f68ad2d0fa3f3f078e9f8b15db894e14068e51ac2c2dbca76fe2ea829745095
7
+ data.tar.gz: a01da1538723ff07e023a9549d38d7246a80dab6acb64c5b4a57c1ea5a3557c848a5707255c1cac3dc63c10e2805a1c972f2eb6bea6a82e34239f938361abe33
data/README.md CHANGED
@@ -1,37 +1,64 @@
1
1
  # RubocopLineup
2
2
 
3
- TODO: Delete this and the text above, and describe your gem
3
+ ![Image of Old-Timey Police Lineup](https://upload.wikimedia.org/wikipedia/commons/0/04/Oppstilling-2.jpg)
4
+
5
+ If yer trying to bring in a new sheriff to the wild, wild west of your legacy codebase,
6
+ there's gonna be some outlaws that are just too ornery to contend with. Better to just
7
+ leave those scoundrels be that aren't in your crosshairs and let yer deputies focus on
8
+ what's at hand.
9
+
10
+ This gem presumes yer a-usin' git for yer revisionin' purposes. For now, it also figgers
11
+ yer always branchin' from master, which, I know, I know, that ain't always how ever'body
12
+ out here on the frontier likes to operate, but hey, we're just gettin' started here.
13
+
14
+ Also, you should know goin' in that we're duck punchin' into a sweet spot of the Rubocop
15
+ underbelly, and well, we just may get to fightin' in the future if them Rubocop folk
16
+ get some fancy refactorin' ideas.
17
+
18
+ Not to mention that some o' yer tougher deputies may get sidelined if they need more than
19
+ a changed line to do thar job ... we'll just have to see about all that down the road.
20
+
21
+ I'm not sure how we fell into a old western theme here with a modern robot-type gem, but
22
+ sometimes ... well, sometimes, the bear eats you.
4
23
 
5
24
  ## Installation
6
25
 
7
- Add this line to your application's Gemfile:
26
+ Add this to yer Gemfile:
8
27
 
9
28
  ```ruby
10
29
  gem 'rubocop_lineup'
11
30
  ```
12
31
 
13
- And then execute:
32
+ And then bundle that up:
14
33
 
15
34
  $ bundle
16
35
 
17
- Or install it yourself as:
36
+ Or just put it in with all yer other gems if so inclined:
18
37
 
19
38
  $ gem install rubocop_lineup
20
39
 
21
40
  ## Usage
22
41
 
23
- TODO: Write usage instructions here
24
-
25
- ## Development
42
+ To use it regular-like, add this to the
43
+ [require section](https://github.com/bbatsov/rubocop/blob/master/manual/extensions.md#loading-extensions)
44
+ of .rubocop.yml:
26
45
 
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+ ```yaml
47
+ require:
48
+ - rubocop_lineup
49
+ ```
28
50
 
29
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+ If you only need to use it ever' now-n-again, inform yer rubocop with the
52
+ `-r rubocop_lineup` option.
30
53
 
31
54
  ## Contributing
32
55
 
33
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubocop_lineup.
56
+ We'd appreciate hearin' some of yer good ideas about our lil project here, and maybe
57
+ even if'in you have a problemo or two with it, you might could get some help here
58
+ with that. Mosey over to the project at https://github.com/mysterysci/rubocop_lineup
59
+ and have a shot or two with us.
34
60
 
35
61
  ## License
36
62
 
37
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+ This gem is one o' them open source deals, and our danged lawyers told us we should
64
+ refer you to this here pronouncement: [MIT License](https://opensource.org/licenses/MIT).
data/bin/console CHANGED
@@ -6,9 +6,5 @@ require "rubocop_lineup"
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
9
+ require "pry"
10
+ Pry.start
@@ -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
- @data = process(diff)
25
+ def initialize(diff, dir)
26
+ @dir = dir
27
+ process(diff)
27
28
  end
28
29
 
29
- def files
30
- @data.keys
30
+ def filenames
31
+ @data_full_paths.keys
31
32
  end
32
33
 
33
- def changed_line_numbers
34
- @data
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,39 @@
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
+ offending_lines = (line_number..(last_line || line_number)).to_a
13
+ changed_line_numbers = files_hash[source_file]
14
+ (changed_line_numbers & offending_lines).empty? ? false : super
15
+ end
16
+
17
+ def last_line
18
+ # `loc_end` will be nil in cases like Parser::Source::Map::Collection
19
+ # https://www.rubydoc.info/github/whitequark/parser/Parser/Source/Map/Collection
20
+ # which point to the entire file, but presumably won't have any range
21
+ # cops analyzing it (e.g. Gemfile is like this).
22
+
23
+ loc_end = processed_source.ast.loc.end
24
+ loc_end ? loc_end.line : nil
25
+ end
26
+ end
27
+
28
+ module TargetFinder
29
+ def find(args)
30
+ # returns an array of full file paths that are the files to inspect.
31
+ files = super(args)
32
+ files_hash = RubocopLineup.line_em_up(Dir.pwd)
33
+ files & files_hash.keys
34
+ end
35
+ end
36
+ end
37
+
38
+ RuboCop::CommentConfig.prepend(DuckPunch::CommentConfig)
39
+ RuboCop::TargetFinder.prepend(DuckPunch::TargetFinder)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopLineup
4
- VERSION = "0.1.1".freeze
4
+ VERSION = "0.2.0".freeze
5
5
  end
@@ -3,7 +3,7 @@
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/monkey_patch_rubocop"
6
+ require "rubocop_lineup/duck_punch_rubocop"
7
7
 
8
8
  module RubocopLineup
9
9
  # This defaults the parent branch to 'master'. This is a reasonable
@@ -15,15 +15,15 @@ module RubocopLineup
15
15
  def self.line_em_up(directory, parent_branch = "master")
16
16
  @line_em_up ||= begin
17
17
  Dir.chdir(directory) do
18
- uncommitted_changes = DiffLiner.diff_uncommitted.changed_line_numbers
19
- committed_changes_on_branch = DiffLiner.diff_branch(parent_branch).changed_line_numbers
18
+ uncommitted = DiffLiner.diff_uncommitted.file_line_changes
19
+ committed_on_branch = DiffLiner.diff_branch(parent_branch).file_line_changes
20
20
 
21
21
  # When a file has committed changes AND uncommitted_changes,
22
22
  # we will only include the lines from the uncommitted changes
23
23
  # because the lines in the previous committed changes may not
24
24
  # be accurate anymore. See test suite for a sample case.
25
25
 
26
- committed_changes_on_branch.merge(uncommitted_changes)
26
+ committed_on_branch.merge(uncommitted)
27
27
  end
28
28
  end
29
29
  end
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "rubocop", "~> 0.55"
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "pry"
30
31
  spec.add_development_dependency "rake", "~> 10.0"
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrismo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-11 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -52,6 +52,20 @@ dependencies:
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
@@ -100,8 +114,8 @@ files:
100
114
  - bin/setup
101
115
  - lib/rubocop_lineup.rb
102
116
  - lib/rubocop_lineup/diff_liner.rb
117
+ - lib/rubocop_lineup/duck_punch_rubocop.rb
103
118
  - lib/rubocop_lineup/line_number_calculator.rb
104
- - lib/rubocop_lineup/monkey_patch_rubocop.rb
105
119
  - lib/rubocop_lineup/version.rb
106
120
  - rubocop_lineup.gemspec
107
121
  homepage: https://github.com/mysterysci/rubocop_lineup
@@ -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)