gnurr 0.4.0 → 0.5.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 +4 -4
- data/bin/gnurr +5 -0
- data/lib/gnurr/cli.rb +18 -3
- data/lib/gnurr/git.rb +1 -3
- data/lib/gnurr/helper.rb +6 -1
- data/lib/gnurr/linter.rb +25 -12
- data/lib/gnurr/linters/ruby_linter.rb +1 -1
- data/lib/gnurr/processor.rb +22 -6
- data/lib/gnurr/version.rb +1 -1
- 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: f3e95befbf1a5e59c904653e1130bc8485433203
|
|
4
|
+
data.tar.gz: de6da161665593392e4e6bbbc1237e461bdd2b37
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dbd58f278889f353499cb650f73a14828acf3d83a6732bb2fc75d8a3d10f1430a48ffc6df4b6e3447ef8c53457acb73062b14d8f05ae7c6680131aaa4c60608e
|
|
7
|
+
data.tar.gz: 0515363f9d4335c17760595293c36a270a9ce5047aa6bea23c0fbcfd87f2aeeae8dd8c07170a4e02374592817e688db44fd3c72b98edae396a3741287a90f6d6
|
data/bin/gnurr
CHANGED
|
@@ -6,6 +6,7 @@ require 'gnurr'
|
|
|
6
6
|
require 'optparse'
|
|
7
7
|
|
|
8
8
|
options = {
|
|
9
|
+
debug: false,
|
|
9
10
|
stdout: true
|
|
10
11
|
}
|
|
11
12
|
|
|
@@ -37,6 +38,10 @@ option_parser = OptionParser.new do |opts|
|
|
|
37
38
|
exit
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
opts.on('--debug', 'Debug mode') do
|
|
42
|
+
options[:debug] = true
|
|
43
|
+
end
|
|
44
|
+
|
|
40
45
|
opts.on('-h', '--help', 'Prints this help') do
|
|
41
46
|
puts opts
|
|
42
47
|
exit
|
data/lib/gnurr/cli.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'colorize'
|
|
2
|
+
require 'open3'
|
|
2
3
|
require 'gnurr/helper'
|
|
3
4
|
|
|
4
5
|
module Gnurr
|
|
@@ -10,6 +11,8 @@ module Gnurr
|
|
|
10
11
|
format_start
|
|
11
12
|
format_messages || format_all_clear
|
|
12
13
|
format_finish
|
|
14
|
+
format_errors
|
|
15
|
+
puts
|
|
13
16
|
messages
|
|
14
17
|
end
|
|
15
18
|
|
|
@@ -41,6 +44,16 @@ module Gnurr
|
|
|
41
44
|
format_linter(message)
|
|
42
45
|
end
|
|
43
46
|
|
|
47
|
+
def format_errors
|
|
48
|
+
return unless (@options[:verbose] || @options[:debug]) && @errors.any?
|
|
49
|
+
puts "#{left_bump}The following messages were encountered:".colorize(mode: :bold)
|
|
50
|
+
@errors.each do |error|
|
|
51
|
+
error.split("\n").each do |line|
|
|
52
|
+
puts "#{left_bump(2)}#{line}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
44
57
|
def format_expanded_notice
|
|
45
58
|
if @options[:expanded]
|
|
46
59
|
puts "#{left_bump(2)}Linting entire files".colorize(mode: :bold)
|
|
@@ -49,10 +62,12 @@ module Gnurr
|
|
|
49
62
|
|
|
50
63
|
def format_finish
|
|
51
64
|
if @options[:verbose]
|
|
52
|
-
puts "#{left_bump}Done linting #{type.to_s.colorize(color)}
|
|
65
|
+
puts "#{left_bump}Done linting #{type.to_s.colorize(color)}"
|
|
66
|
+
.colorize(mode: :bold)
|
|
67
|
+
end
|
|
68
|
+
if violation_count > 0 || @options[:verbose] || @options[:debug]
|
|
69
|
+
puts "#{left_bump}Violations: #{violation_count.to_s.colorize(severity_color(violation_count, files.length))}"
|
|
53
70
|
.colorize(mode: :bold)
|
|
54
|
-
else
|
|
55
|
-
puts
|
|
56
71
|
end
|
|
57
72
|
end
|
|
58
73
|
|
data/lib/gnurr/git.rb
CHANGED
|
@@ -5,8 +5,6 @@ module Gnurr
|
|
|
5
5
|
module Git
|
|
6
6
|
include Gnurr::Helper
|
|
7
7
|
|
|
8
|
-
private
|
|
9
|
-
|
|
10
8
|
def extract_lines(diffs)
|
|
11
9
|
diffs.map do |lines|
|
|
12
10
|
nums = lines.match(/^.+\+(?<from>[0-9]+)(,(?<len>[0-9]+))? .+$/)
|
|
@@ -16,7 +14,7 @@ module Gnurr
|
|
|
16
14
|
|
|
17
15
|
def full_file_diff
|
|
18
16
|
return @diff if @diff
|
|
19
|
-
path = @options[:path].nil? || !@options[:path].any? ? '' : "-- #{@options[:path].join(' ')}"
|
|
17
|
+
path = @options[:path].nil? || !@options[:path].any? ? '' : "-- #{@options[:path].map { |p| escaped_filename(p) }.join(' ')}"
|
|
20
18
|
diff = `git diff #{@options[:base]} --name-only --diff-filter=ACMRTUXB #{path}`
|
|
21
19
|
.split("\n")
|
|
22
20
|
.map { |file| [file, file_diffs(file)] }
|
data/lib/gnurr/helper.rb
CHANGED
|
@@ -19,8 +19,13 @@ module Gnurr
|
|
|
19
19
|
ranges + [Range.new(left, right)]
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def severity_color(violations, files)
|
|
23
|
+
return :green if violations.zero? || files.zero?
|
|
24
|
+
violation_count / files < 1 ? :yellow : :red
|
|
25
|
+
end
|
|
26
|
+
|
|
22
27
|
def escaped_filename(filename)
|
|
23
|
-
filename.
|
|
28
|
+
filename.gsub(/(\s)/,'\\\\\1')
|
|
24
29
|
end
|
|
25
30
|
|
|
26
31
|
def left_bump(indent = 1)
|
data/lib/gnurr/linter.rb
CHANGED
|
@@ -11,7 +11,10 @@ module Gnurr
|
|
|
11
11
|
include Gnurr::CLI
|
|
12
12
|
include Gnurr::Git
|
|
13
13
|
|
|
14
|
+
attr_reader :errors
|
|
15
|
+
|
|
14
16
|
def initialize(options)
|
|
17
|
+
@errors = []
|
|
15
18
|
@options = {
|
|
16
19
|
base: 'master',
|
|
17
20
|
expanded: false,
|
|
@@ -28,17 +31,6 @@ module Gnurr
|
|
|
28
31
|
@options[:stdout] ? print_messages : messages
|
|
29
32
|
end
|
|
30
33
|
|
|
31
|
-
def parse_messages(json)
|
|
32
|
-
return [] unless json.any?
|
|
33
|
-
msgs = json.map { |f| map_errors(f) }
|
|
34
|
-
.select { |_f, m| m && m.any? }
|
|
35
|
-
if @options[:expanded]
|
|
36
|
-
msgs.to_a
|
|
37
|
-
else
|
|
38
|
-
filter_messages(msgs)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
34
|
def files
|
|
43
35
|
@files ||= Hash[full_file_diff.select { |file, _lines| filter(file) }]
|
|
44
36
|
end
|
|
@@ -69,12 +61,16 @@ module Gnurr
|
|
|
69
61
|
|
|
70
62
|
def relevant_messages
|
|
71
63
|
return {} if files.empty?
|
|
72
|
-
JSON.parse(
|
|
64
|
+
JSON.parse(run_command("#{command} #{escaped_files.join(' ')}"))
|
|
73
65
|
rescue => e
|
|
74
66
|
log_error(e)
|
|
75
67
|
{}
|
|
76
68
|
end
|
|
77
69
|
|
|
70
|
+
def violation_count
|
|
71
|
+
messages.map(&:last).flatten.length
|
|
72
|
+
end
|
|
73
|
+
|
|
78
74
|
private
|
|
79
75
|
|
|
80
76
|
def escaped_files
|
|
@@ -96,6 +92,17 @@ module Gnurr
|
|
|
96
92
|
@messages ||= parse_messages(relevant_messages)
|
|
97
93
|
end
|
|
98
94
|
|
|
95
|
+
def parse_messages(json)
|
|
96
|
+
return [] unless json.any?
|
|
97
|
+
msgs = json.map { |f| map_errors(f) }
|
|
98
|
+
.select { |_f, m| m && m.any? }
|
|
99
|
+
if @options[:expanded]
|
|
100
|
+
msgs.to_a
|
|
101
|
+
else
|
|
102
|
+
filter_messages(msgs)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
99
106
|
def relative_filename(filename)
|
|
100
107
|
filename
|
|
101
108
|
end
|
|
@@ -107,5 +114,11 @@ module Gnurr
|
|
|
107
114
|
def standardize_message(_message)
|
|
108
115
|
raise 'Can\'t standardize on base Linter class'
|
|
109
116
|
end
|
|
117
|
+
|
|
118
|
+
def run_command(command)
|
|
119
|
+
output, err = Open3.capture3(command)
|
|
120
|
+
@errors << err unless err.nil? || err.length == 0
|
|
121
|
+
output
|
|
122
|
+
end
|
|
110
123
|
end
|
|
111
124
|
end
|
data/lib/gnurr/processor.rb
CHANGED
|
@@ -6,6 +6,8 @@ require 'gnurr/linters/scss_linter'
|
|
|
6
6
|
module Gnurr
|
|
7
7
|
# Main class for execution
|
|
8
8
|
class Processor
|
|
9
|
+
include Gnurr::Helper
|
|
10
|
+
|
|
9
11
|
LINTERS = {
|
|
10
12
|
es: Gnurr::Linters::EsLinter,
|
|
11
13
|
haml: Gnurr::Linters::HamlLinter,
|
|
@@ -13,8 +15,12 @@ module Gnurr
|
|
|
13
15
|
scss: Gnurr::Linters::ScssLinter
|
|
14
16
|
}.freeze
|
|
15
17
|
|
|
18
|
+
attr_reader :violation_count
|
|
19
|
+
|
|
16
20
|
def initialize(options = {})
|
|
17
21
|
@options = options
|
|
22
|
+
@violation_count = 0
|
|
23
|
+
@files = []
|
|
18
24
|
if @options[:linters] && options[:linters].any?
|
|
19
25
|
@options[:linters] = LINTERS.keys & @options[:linters]
|
|
20
26
|
else
|
|
@@ -24,17 +30,27 @@ module Gnurr
|
|
|
24
30
|
|
|
25
31
|
def execute
|
|
26
32
|
@lints ||= {}
|
|
33
|
+
@violation_count = 0
|
|
27
34
|
@options[:linters].each do |type|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
35
|
+
lint_type(type)
|
|
36
|
+
end
|
|
37
|
+
if @options[:stdout]
|
|
38
|
+
print 'Total Violations: '.colorize(mode: :bold)
|
|
39
|
+
puts @violation_count.to_s.colorize(mode: :bold, color: severity_color(@violation_count, @files.length))
|
|
34
40
|
end
|
|
35
41
|
@lints
|
|
36
42
|
end
|
|
37
43
|
|
|
44
|
+
def lint_type(type)
|
|
45
|
+
@lints[type] = LINTERS[type].new(@options)
|
|
46
|
+
@lints[type].execute
|
|
47
|
+
@violation_count += @lints[type].violation_count
|
|
48
|
+
(@files += @lints[type].files.keys).uniq!
|
|
49
|
+
rescue => e
|
|
50
|
+
log_error(e)
|
|
51
|
+
@lints[type] = e
|
|
52
|
+
end
|
|
53
|
+
|
|
38
54
|
def lints
|
|
39
55
|
@lints ||= {}
|
|
40
56
|
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.
|
|
4
|
+
version: 0.5.0
|
|
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-12-
|
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|