ndr_dev_support 1.1.1 → 1.1.3
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/code_safety.yml +10 -10
- data/lib/ndr_dev_support/rubocop/executor.rb +15 -11
- data/lib/ndr_dev_support/rubocop/range_finder.rb +15 -22
- data/lib/ndr_dev_support/rubocop/reporter.rb +2 -2
- data/lib/ndr_dev_support/version.rb +2 -1
- data/lib/tasks/rubocop.rake +18 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b2f915258a3f3f168328b951e3eeb994ee319ba
|
4
|
+
data.tar.gz: 645d0844ed7125193c2796f79d5a4cf33c1dec70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac14a11fb811aae9b2c0e03c8027efb985eaa68f65f9575543f2c72cb629a119ed371d869e747af519183f0001cf038e3bb00afe461295aaaec320f48b63513
|
7
|
+
data.tar.gz: 46318f642050c869aab20e2d6b02ac902e82a5ade663142b9db0eeb86427231ac7d99124d33b321ce9265464eecb1e99cb998eca14c8c352763af5318fc5d40c
|
data/code_safety.yml
CHANGED
@@ -46,28 +46,28 @@ file safety:
|
|
46
46
|
safe_revision: c59a45986f8b6d087c8c21b1e889f31f7346da17
|
47
47
|
lib/ndr_dev_support/rubocop/executor.rb:
|
48
48
|
comments:
|
49
|
-
reviewed_by:
|
50
|
-
safe_revision:
|
49
|
+
reviewed_by: josh.pencheon
|
50
|
+
safe_revision: 41cf1558f567928faaa1e670a36d941c03c78044
|
51
51
|
lib/ndr_dev_support/rubocop/range_augmenter.rb:
|
52
52
|
comments:
|
53
53
|
reviewed_by: joshpencheon
|
54
54
|
safe_revision: fe5f0a693b77eeecaa39ff6fcf87ad59c4fb46e1
|
55
55
|
lib/ndr_dev_support/rubocop/range_finder.rb:
|
56
56
|
comments:
|
57
|
-
reviewed_by:
|
58
|
-
safe_revision:
|
57
|
+
reviewed_by: josh.pencheon
|
58
|
+
safe_revision: 41cf1558f567928faaa1e670a36d941c03c78044
|
59
59
|
lib/ndr_dev_support/rubocop/reporter.rb:
|
60
60
|
comments:
|
61
|
-
reviewed_by:
|
62
|
-
safe_revision:
|
61
|
+
reviewed_by: josh.pencheon
|
62
|
+
safe_revision: 41cf1558f567928faaa1e670a36d941c03c78044
|
63
63
|
lib/ndr_dev_support/tasks.rb:
|
64
64
|
comments:
|
65
65
|
reviewed_by: joshpencheon
|
66
66
|
safe_revision: a55c971cb770a8e5dc4be7ed66663dd5d695fcd1
|
67
67
|
lib/ndr_dev_support/version.rb:
|
68
68
|
comments:
|
69
|
-
reviewed_by:
|
70
|
-
safe_revision:
|
69
|
+
reviewed_by: josh.pencheon
|
70
|
+
safe_revision: 3f4e55cee33c956405ab82e55b76914be0770577
|
71
71
|
lib/tasks/audit_code.rake:
|
72
72
|
comments: Identical to the version reviewed by josh.pencheon when contained within
|
73
73
|
ndr_support
|
@@ -75,8 +75,8 @@ file safety:
|
|
75
75
|
safe_revision: 0d56ba443b2cddca5ba2d96ea61ec6f2b898436d
|
76
76
|
lib/tasks/rubocop.rake:
|
77
77
|
comments:
|
78
|
-
reviewed_by:
|
79
|
-
safe_revision:
|
78
|
+
reviewed_by: josh.pencheon
|
79
|
+
safe_revision: 41cf1558f567928faaa1e670a36d941c03c78044
|
80
80
|
ndr_dev_support.gemspec:
|
81
81
|
comments:
|
82
82
|
reviewed_by: joshpencheon
|
@@ -6,22 +6,26 @@ module NdrDevSupport
|
|
6
6
|
# This class filters the Rubocop report of a file
|
7
7
|
# to only the given lines.
|
8
8
|
class Executor
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
class << self
|
10
|
+
# Use RuboCop to produce a list of all files that should be scanned.
|
11
|
+
def target_files
|
12
|
+
@target_files ||= `rubocop -L`.each_line.map(&:strip)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
|
16
|
-
@lines.include? offense['location']['line']
|
17
|
-
end
|
16
|
+
def initialize(filenames)
|
17
|
+
@filenames = Executor.target_files & filenames
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def offenses_by_file
|
21
|
+
return [] if @filenames.empty?
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
escaped_paths = @filenames.map { |path| Shellwords.escape(path) }
|
24
|
+
output = JSON.parse(`rubocop --format json #{escaped_paths.join(' ')}`)
|
25
|
+
|
26
|
+
output['files'].each_with_object({}) do |file_output, result|
|
27
|
+
result[file_output['path']] = file_output['offenses']
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'English'
|
2
|
+
require 'open3'
|
2
3
|
require 'rubocop'
|
3
4
|
require 'shellwords'
|
4
5
|
|
@@ -6,19 +7,8 @@ module NdrDevSupport
|
|
6
7
|
module Rubocop
|
7
8
|
# Produces diffs, and parses from them the file/hunk boundaries
|
8
9
|
class RangeFinder
|
9
|
-
class << self
|
10
|
-
# Use RuboCop to produce a list of all files that should be scanned.
|
11
|
-
def target_files
|
12
|
-
@target_files ||= begin
|
13
|
-
defaults = ::RuboCop::ConfigStore.new
|
14
|
-
::RuboCop::TargetFinder.new(defaults, {}).target_files_in_dir
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
10
|
def diff_files(files)
|
20
|
-
|
21
|
-
file_change_locations_from diff
|
11
|
+
file_change_locations_from git_diff(files * ' ')
|
22
12
|
end
|
23
13
|
|
24
14
|
def diff_head
|
@@ -40,9 +30,18 @@ module NdrDevSupport
|
|
40
30
|
private
|
41
31
|
|
42
32
|
def git_diff(args)
|
43
|
-
|
44
|
-
|
45
|
-
|
33
|
+
diff_cmd = 'git diff --no-prefix --unified=0 '
|
34
|
+
diff_cmd << Shellwords.escape(args) unless args.empty?
|
35
|
+
stdout, stderr, status = Open3.capture3(diff_cmd)
|
36
|
+
|
37
|
+
return stdout if status.success?
|
38
|
+
|
39
|
+
fail Rainbow(<<-MSG).red
|
40
|
+
Failed to generate diff from:
|
41
|
+
#{diff_cmd}
|
42
|
+
|
43
|
+
#{stderr}
|
44
|
+
MSG
|
46
45
|
end
|
47
46
|
|
48
47
|
def file_changes_hash
|
@@ -60,13 +59,7 @@ module NdrDevSupport
|
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
# Don't report on changes in files that RuboCop won't understand:
|
67
|
-
def ruby_files_from(changes)
|
68
|
-
whitelist = RangeFinder.target_files
|
69
|
-
changes.reject { |file, _ranges| !whitelist.include? File.join(Dir.pwd, file) }
|
62
|
+
changes
|
70
63
|
end
|
71
64
|
|
72
65
|
def hunk_range_from(line)
|
@@ -16,7 +16,7 @@ module NdrDevSupport
|
|
16
16
|
}.freeze
|
17
17
|
|
18
18
|
def initialize(offenses)
|
19
|
-
@offenses = offenses
|
19
|
+
@offenses = Hash[offenses.sort_by { |file, _offenses| file }]
|
20
20
|
end
|
21
21
|
|
22
22
|
# Prints out a report, and returns an appriopriate
|
@@ -28,7 +28,7 @@ module NdrDevSupport
|
|
28
28
|
print_offenses
|
29
29
|
return @offenses.values.all?(&:empty?)
|
30
30
|
else
|
31
|
-
puts Rainbow('No
|
31
|
+
puts Rainbow('No relevant changes found.').yellow
|
32
32
|
return false
|
33
33
|
end
|
34
34
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# This defines the NdrDevSupport version. If you change it, rebuild and commit the gem.
|
2
3
|
# Use "rake build" to build the gem, see rake -T for all bundler rake tasks (and our own).
|
3
4
|
module NdrDevSupport
|
4
|
-
VERSION = '1.1.
|
5
|
+
VERSION = '1.1.3'.freeze
|
5
6
|
end
|
data/lib/tasks/rubocop.rake
CHANGED
@@ -4,16 +4,25 @@ namespace :rubocop do
|
|
4
4
|
require 'ndr_dev_support/rubocop/executor'
|
5
5
|
require 'ndr_dev_support/rubocop/reporter'
|
6
6
|
|
7
|
+
def filtered_offenses_by_line(offenses, lines)
|
8
|
+
offenses.select do |offense|
|
9
|
+
line = offense['location']['line']
|
10
|
+
1 == line || lines.include?(line)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
# For a given set of change locations (extract from a diff),
|
8
15
|
# run rubocop on the relevant files, and report filtered results.
|
9
16
|
def rubocop_file_ranges(file_ranges)
|
10
|
-
output
|
11
|
-
|
17
|
+
output = {}
|
18
|
+
offenses = NdrDevSupport::Rubocop::Executor.new(file_ranges.keys).offenses_by_file
|
19
|
+
|
20
|
+
threads = offenses.map do |file, file_offenses|
|
12
21
|
Thread.new do
|
13
22
|
# Expand ranges to include entire methods, etc:
|
14
|
-
|
15
|
-
# Get rubocop output for those files:
|
16
|
-
output[file] =
|
23
|
+
augmenter = NdrDevSupport::Rubocop::RangeAugmenter.new(file, file_ranges[file] || [])
|
24
|
+
# Get subset of rubocop output for those files:
|
25
|
+
output[file] = filtered_offenses_by_line(file_offenses, augmenter.augmented_lines)
|
17
26
|
end
|
18
27
|
end
|
19
28
|
threads.each(&:join)
|
@@ -31,8 +40,10 @@ namespace :rubocop do
|
|
31
40
|
rake rubocop:diff master
|
32
41
|
USAGE
|
33
42
|
task :diff do
|
34
|
-
|
35
|
-
|
43
|
+
args = ARGV.dup
|
44
|
+
nil until 'rubocop:diff' == args.shift
|
45
|
+
|
46
|
+
ranges = NdrDevSupport::Rubocop::RangeFinder.new.diff_expr args.join(' ')
|
36
47
|
rubocop_file_ranges ranges
|
37
48
|
end
|
38
49
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ndr_dev_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NCRS Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|