gnurr 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gnurr +4 -0
- data/gnurr.gemspec +0 -2
- data/lib/gnurr/cli.rb +19 -8
- data/lib/gnurr/git.rb +27 -0
- data/lib/gnurr/linter.rb +33 -16
- data/lib/gnurr/processor.rb +1 -24
- data/lib/gnurr/ruby_base_linter.rb +1 -0
- data/lib/gnurr/version.rb +1 -1
- metadata +3 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f014991bd857985d010c0f65bd97ad5adbd8cb85
|
4
|
+
data.tar.gz: d2166bfeb7b6a73d91c796c69ca0abb4d56cbe97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa234f3f589d9c6e27302b4e9d06af7f2237dafe171dfb4dd31e204b0979e5b18f45ab7c10a569a2f419af5774fbfc370935fb3919c1278bf5762142791771ae
|
7
|
+
data.tar.gz: 2cb0fb5fd2dd42d0ad22ba5ff50a4a7182b4ebf351e3561dab21ab3587fd49d64e1bf4fe4e3cfad40a02a2da592f6ca56df5bda6c13c984725d506e6ef2572a4
|
data/bin/gnurr
CHANGED
@@ -16,18 +16,22 @@ option_parser = OptionParser.new do |opts|
|
|
16
16
|
'Base branch: branch to diff against (default: master)') do |v|
|
17
17
|
options[:branch] = v
|
18
18
|
end
|
19
|
+
|
19
20
|
opts.on('-e', '--expanded',
|
20
21
|
'Show lints for all changed files, not just changed lines (false',
|
21
22
|
'unless specified)') do
|
22
23
|
options[:expanded] = true
|
23
24
|
end
|
25
|
+
|
24
26
|
opts.on('-l', '--linters LIST',
|
25
27
|
'Linters to use (default: es,haml,ruby,scss (all))') do |v|
|
26
28
|
options[:linters] = v.split(',').map(&:to_sym)
|
27
29
|
end
|
30
|
+
|
28
31
|
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
29
32
|
options[:verbose] = v
|
30
33
|
end
|
34
|
+
|
31
35
|
opts.on('--version', 'Show version') do
|
32
36
|
puts Gnurr::VERSION
|
33
37
|
exit
|
data/gnurr.gemspec
CHANGED
@@ -29,8 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
31
31
|
spec.add_development_dependency 'rake'
|
32
|
-
spec.add_development_dependency 'git', '~> 1.3.0'
|
33
|
-
spec.add_development_dependency 'pry'
|
34
32
|
|
35
33
|
spec.add_runtime_dependency 'colorize'
|
36
34
|
end
|
data/lib/gnurr/cli.rb
CHANGED
@@ -17,7 +17,7 @@ module Gnurr
|
|
17
17
|
|
18
18
|
def format_messages
|
19
19
|
format_line_diffs if @options[:verbose]
|
20
|
-
return if messages.empty?
|
20
|
+
return false if messages.empty?
|
21
21
|
puts "#{left_bump(2)}Messages:".colorize(mode: :bold)
|
22
22
|
messages.each do |filename, messages|
|
23
23
|
messages.each do |message|
|
@@ -36,6 +36,12 @@ module Gnurr
|
|
36
36
|
format_linter(message)
|
37
37
|
end
|
38
38
|
|
39
|
+
def format_expanded_notice
|
40
|
+
if @options[:expanded]
|
41
|
+
puts "#{left_bump(2)}Linting entire files".colorize(mode: :bold)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
39
45
|
def format_finish
|
40
46
|
if @options[:verbose]
|
41
47
|
puts "#{left_bump}Done linting #{type.to_s.colorize(color)}\n"
|
@@ -53,20 +59,25 @@ module Gnurr
|
|
53
59
|
|
54
60
|
def format_line_diffs
|
55
61
|
diffs = line_diffs
|
56
|
-
if diffs
|
57
|
-
|
58
|
-
|
59
|
-
puts "#{left_bump(
|
60
|
-
diffs.each do |filename, lines|
|
61
|
-
puts "#{left_bump(3)}#{filename}:#{lines.join(', ').colorize(:cyan)}"
|
62
|
-
end
|
62
|
+
return if format_no_changes(diffs)
|
63
|
+
puts "#{left_bump(2)}Lines changed:".colorize(mode: :bold)
|
64
|
+
diffs.each do |filename, lines|
|
65
|
+
puts "#{left_bump(3)}#{filename}:#{lines.join(', ').colorize(:cyan)}"
|
63
66
|
end
|
67
|
+
format_expanded_notice
|
64
68
|
end
|
65
69
|
|
66
70
|
def format_linter(message)
|
67
71
|
message[:linter] ? " (#{message[:linter]})".colorize(:cyan) : ''
|
68
72
|
end
|
69
73
|
|
74
|
+
def format_no_changes(diffs)
|
75
|
+
if diffs.empty?
|
76
|
+
puts "#{left_bump(2)}No changes.".colorize(mode: :bold)
|
77
|
+
true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
70
81
|
def format_severity(message)
|
71
82
|
if message[:severity] == :error
|
72
83
|
'[E]'.colorize(:red)
|
data/lib/gnurr/git.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gnurr
|
2
|
+
# For handling/reading Git output
|
3
|
+
module Git
|
4
|
+
private
|
5
|
+
|
6
|
+
def extract_lines(diffs)
|
7
|
+
diffs.map do |lines|
|
8
|
+
nums = lines.match(/^.+\+(?<from>[0-9]+)(,(?<len>[0-9]+))? .+$/)
|
9
|
+
Range.new(nums[:from].to_i, nums[:from].to_i + nums[:len].to_i)
|
10
|
+
end.map(&:to_a).flatten
|
11
|
+
end
|
12
|
+
|
13
|
+
def full_file_diff
|
14
|
+
return @diff if @diff
|
15
|
+
diff = `git diff #{@options[:branch]} --name-only --diff-filter=ACMRTUXB`
|
16
|
+
.split("\n")
|
17
|
+
.map { |file| [file, file_diffs(file)] }
|
18
|
+
@diff = Hash[diff.select { |_k, v| v && v.any? }]
|
19
|
+
end
|
20
|
+
|
21
|
+
def file_diffs(file)
|
22
|
+
diffs = `git diff --unified=0 #{@options[:branch]} #{file} \
|
23
|
+
| egrep '\\+[0-9]+(,[1-9][0-9]*)? '`
|
24
|
+
extract_lines(diffs.split("\n"))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/gnurr/linter.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'gnurr/helper'
|
2
2
|
require 'gnurr/cli'
|
3
|
+
require 'gnurr/git'
|
3
4
|
|
4
5
|
module Gnurr
|
5
6
|
# Base linter class from which each linter extends
|
6
7
|
class Linter
|
7
8
|
include Gnurr::Helper
|
8
9
|
include Gnurr::CLI
|
10
|
+
include Gnurr::Git
|
9
11
|
|
10
|
-
def initialize(
|
11
|
-
raise "Dependency not available for #{type}" unless requirements_met?
|
12
|
+
def initialize(options)
|
12
13
|
@options = options
|
13
|
-
|
14
|
-
@messages = {} if @files.empty?
|
14
|
+
raise "Dependency not available for #{type}" unless requirements_met?
|
15
15
|
rescue => e
|
16
16
|
log_error(e)
|
17
17
|
end
|
@@ -22,34 +22,44 @@ module Gnurr
|
|
22
22
|
|
23
23
|
def parse_messages(json)
|
24
24
|
return [] unless json.any?
|
25
|
-
|
26
|
-
|
25
|
+
msgs = json.map { |f| map_errors(f) }
|
26
|
+
.select { |_f, m| m && m.any? }
|
27
27
|
if @options[:expanded]
|
28
|
-
|
28
|
+
msgs.to_a
|
29
29
|
else
|
30
|
-
filter_messages(
|
30
|
+
filter_messages(msgs)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def files
|
35
|
+
@files ||= Hash[full_file_diff.select { |file, _lines| filter(file) }]
|
36
|
+
end
|
37
|
+
|
34
38
|
def filter_messages(messages)
|
35
39
|
messages.map do |filename, msgs|
|
36
|
-
msgs.reject! { |msg|
|
40
|
+
msgs.reject! { |msg| !files[filename].include?(msg[:line]) }
|
37
41
|
msgs.empty? ? nil : [filename, msgs]
|
38
42
|
end.reject(&:nil?)
|
39
43
|
end
|
40
44
|
|
45
|
+
def full_range(filename)
|
46
|
+
[Range.new(1, `wc -l < #{filename}`.to_i + 1)]
|
47
|
+
end
|
48
|
+
|
41
49
|
def line_diffs
|
42
50
|
Hash[
|
43
|
-
|
44
|
-
[
|
51
|
+
files.map do |filename, lines|
|
52
|
+
[
|
53
|
+
filename,
|
54
|
+
@options[:expanded] ? full_range(filename) : array_to_ranges(lines)
|
55
|
+
]
|
45
56
|
end
|
46
57
|
]
|
47
58
|
end
|
48
59
|
|
49
60
|
def relevant_messages
|
50
|
-
|
51
|
-
|
52
|
-
| xargs #{command}`)
|
61
|
+
return {} if files.empty?
|
62
|
+
JSON.parse(`#{command} #{escaped_files.join(' ')}`)
|
53
63
|
rescue => e
|
54
64
|
log_error(e)
|
55
65
|
{}
|
@@ -57,8 +67,10 @@ module Gnurr
|
|
57
67
|
|
58
68
|
private
|
59
69
|
|
60
|
-
def
|
61
|
-
|
70
|
+
def escaped_files
|
71
|
+
files.map do |file, _lines|
|
72
|
+
file.sub(/(\s)/, '\\\\\1')
|
73
|
+
end
|
62
74
|
end
|
63
75
|
|
64
76
|
def map_errors(file)
|
@@ -71,9 +83,14 @@ module Gnurr
|
|
71
83
|
end
|
72
84
|
|
73
85
|
def messages
|
86
|
+
return @messages = {} if files.empty?
|
74
87
|
@messages ||= parse_messages(relevant_messages)
|
75
88
|
end
|
76
89
|
|
90
|
+
def requirements_met?
|
91
|
+
true # Set by subclasses
|
92
|
+
end
|
93
|
+
|
77
94
|
def standardize_message(message)
|
78
95
|
{
|
79
96
|
column: message['column'],
|
data/lib/gnurr/processor.rb
CHANGED
@@ -25,7 +25,7 @@ module Gnurr
|
|
25
25
|
lints = {}
|
26
26
|
@options[:linters].each do |type|
|
27
27
|
begin
|
28
|
-
lints[type] = LINTERS[type].new(
|
28
|
+
lints[type] = LINTERS[type].new(@options)
|
29
29
|
lints[type].execute
|
30
30
|
rescue => e
|
31
31
|
lints[type] = e.inspect
|
@@ -33,28 +33,5 @@ module Gnurr
|
|
33
33
|
end
|
34
34
|
lints
|
35
35
|
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def git_diffs
|
40
|
-
return @diff if @diff
|
41
|
-
diff = `git diff #{@options[:branch]} --name-only --diff-filter=ACMRTUXB`
|
42
|
-
.split("\n")
|
43
|
-
.map { |file| [file, file_diffs(file)] }
|
44
|
-
@diff = Hash[diff.select { |_k, v| v && v.any? }]
|
45
|
-
end
|
46
|
-
|
47
|
-
def file_diffs(file)
|
48
|
-
diffs = `git diff --unified=0 #{@options[:branch]} #{file} \
|
49
|
-
| egrep '\\+[0-9]+(,[1-9][0-9]*)? '`
|
50
|
-
line_diffs(diffs.split("\n"))
|
51
|
-
end
|
52
|
-
|
53
|
-
def line_diffs(diffs)
|
54
|
-
diffs.map do |lines|
|
55
|
-
nums = lines.match(/^.+\+(?<from>[0-9]+)(,(?<len>[0-9]+))? .+$/)
|
56
|
-
Range.new(nums[:from].to_i, nums[:from].to_i + nums[:len].to_i)
|
57
|
-
end.map(&:to_a).flatten
|
58
|
-
end
|
59
36
|
end
|
60
37
|
end
|
data/lib/gnurr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnurr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Saufley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,34 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: git
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.3.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.3.0
|
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'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: colorize
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,6 +71,7 @@ files:
|
|
99
71
|
- lib/gnurr.rb
|
100
72
|
- lib/gnurr/cli.rb
|
101
73
|
- lib/gnurr/es_linter.rb
|
74
|
+
- lib/gnurr/git.rb
|
102
75
|
- lib/gnurr/haml_linter.rb
|
103
76
|
- lib/gnurr/helper.rb
|
104
77
|
- lib/gnurr/linter.rb
|