Skip to content

Commit 93e5446

Browse files
committed
Added initial logic
extracts changed line numbers from git diff and does a cross comparison with the rails best practices output
1 parent 578ab85 commit 93e5446

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

bin/odor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ trap("INT") do
66
exit
77
end
88

9-
# resolve bin path, ignoring symlinks
10-
require "pathname"
11-
bin_file = Pathname.new(__FILE__).realpath
9+
# resolve bin path, ignoring symlinks
10+
require "pathname"
11+
bin_file = Pathname.new(__FILE__).realpath
1212

1313
Odor.run(*ARGV)

lib/odor.rb

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,52 @@ def self.run(*args)
1010
end
1111

1212
def self.check_file(filename)
13+
line_numbers = line_changes(filename)
14+
issues = %x[rails_best_practices -f text #{filename} --silent]
15+
issues = issues.split("\n")
16+
17+
issues.each do |hint|
18+
line_numbers.each do |num|
19+
if hint.include?(num.to_s)
20+
puts hint
21+
break
22+
end
23+
end
24+
end
25+
return true
26+
end
27+
28+
def self.line_changes(filename)
1329
changes = %x[git diff -U0 #{filename}]
14-
15-
puts changes.split("\n")
16-
issues = %x[rails_best_practices -f text #{filename}]
17-
puts issues
30+
changes = changes.split("\n")
31+
changes.shift(4)
32+
#changes = changes.map{ |c| c if !c.nil? && c.start_with?('@') }
33+
34+
line_changes = []
35+
changes.each do |c|
36+
line_changes << c if !c.nil? && c.start_with?('@')
37+
end
38+
39+
lines = []
40+
41+
line_changes.each do |s|
42+
s = s.split
43+
44+
s.shift(2)
45+
li = s.first[1, 50].split(',')
46+
47+
li.last.to_i.times do |i|
48+
lines << li.first.to_i + i
49+
end
50+
end
51+
52+
# s = changes.first.split
53+
# s.shift(2)
54+
# li = s.first[1, 50].split(',')
55+
#
56+
# li.last.to_i.times do |i|
57+
# lines << li.first.to_i + i
58+
# end
59+
return lines
1860
end
1961
end

0 commit comments

Comments
 (0)