code_hunter 0.1.3 → 0.1.4
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.
- data/README.md +11 -0
- data/lib/code_hunter.rb +1 -0
- data/lib/code_hunter/runner.rb +6 -11
- data/lib/code_hunter/version.rb +1 -1
- data/lib/code_hunter/warning.rb +87 -0
- metadata +3 -2
data/README.md
CHANGED
@@ -49,5 +49,16 @@ $ code_hunter --application-path /path/to/rails/root --format json
|
|
49
49
|
[{"service":"brakeman","line":8,"path":"config/routes.rb","message":"All public methods in controllers are available as actions in routes.rb near line 8","sha1":"81887a2fb6efaa9dae59425ce7537c7905516ed0","author":"Ryo Nakamura","email":"r7kamura@gmail.com","modified_at":1357783853},{"service":"rails_best_practices","line":9,"path":"config/routes.rb","message":"restrict auto-generated routes examples (only: [])","sha1":"81887a2fb6efaa9dae59425ce7537c7905516ed0","author":"Ryo Nakamura","email":"r7kamura@gmail.com","modified_at":1357783853}]
|
50
50
|
```
|
51
51
|
|
52
|
+
### Ignore
|
53
|
+
If you want to ignore some warnings, write `# ignore` annotation as code comment.
|
54
|
+
If the detected line hits `/#\s*ignore/i`, it is ignored.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
danger_but_necessary_code # ignore
|
58
|
+
danger_but_necessary_code # IGNORE
|
59
|
+
danger_but_necessary_code # Ignore for some reason
|
60
|
+
```
|
61
|
+
|
62
|
+
|
52
63
|
## Requirements
|
53
64
|
* Ruby >= 1.9
|
data/lib/code_hunter.rb
CHANGED
data/lib/code_hunter/runner.rb
CHANGED
@@ -12,20 +12,15 @@ module CodeHunter
|
|
12
12
|
|
13
13
|
def run
|
14
14
|
warnings = collect_warnings
|
15
|
-
warnings =
|
16
|
-
|
17
|
-
puts
|
15
|
+
warnings = warnings.select(&:has_git_metadata?)
|
16
|
+
warnings = warnings.reject(&:ignore?)
|
17
|
+
puts Renderer.render(warnings.map(&:to_hash), :format => options[:format])
|
18
18
|
end
|
19
19
|
|
20
20
|
def collect_warnings
|
21
|
-
services.map(&:run).compact.inject([], :+)
|
22
|
-
|
23
|
-
|
24
|
-
def merge_git_metadata(warnings)
|
25
|
-
warnings.map do |warning|
|
26
|
-
metadata = GitBlamer.new(warning).blame or next
|
27
|
-
warning.merge(metadata)
|
28
|
-
end.compact
|
21
|
+
services.map(&:run).compact.inject([], :+).map do |attributes|
|
22
|
+
Warning.new(attributes)
|
23
|
+
end
|
29
24
|
end
|
30
25
|
|
31
26
|
private
|
data/lib/code_hunter/version.rb
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
module CodeHunter
|
2
|
+
class Warning
|
3
|
+
def initialize(attributes)
|
4
|
+
@attributes = attributes
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_hash
|
8
|
+
{
|
9
|
+
:line => line,
|
10
|
+
:message => message,
|
11
|
+
:path => path,
|
12
|
+
:service => service,
|
13
|
+
:url => url,
|
14
|
+
:sha1 => sha1,
|
15
|
+
:author => author,
|
16
|
+
:email => email,
|
17
|
+
:modified_at => modified_at,
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def line
|
22
|
+
@attributes[:line]
|
23
|
+
end
|
24
|
+
|
25
|
+
def message
|
26
|
+
@attributes[:message]
|
27
|
+
end
|
28
|
+
|
29
|
+
def path
|
30
|
+
@attributes[:path]
|
31
|
+
end
|
32
|
+
|
33
|
+
def service
|
34
|
+
@attributes[:service]
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
@attributes[:url]
|
39
|
+
end
|
40
|
+
|
41
|
+
def sha1
|
42
|
+
@git_metadata[:sha1]
|
43
|
+
end
|
44
|
+
|
45
|
+
def author
|
46
|
+
@git_metadata[:author]
|
47
|
+
end
|
48
|
+
|
49
|
+
def email
|
50
|
+
@git_metadata[:email]
|
51
|
+
end
|
52
|
+
|
53
|
+
def modified_at
|
54
|
+
@git_metadata[:modified_at]
|
55
|
+
end
|
56
|
+
|
57
|
+
# Fetch @git_metadata only once.
|
58
|
+
def git_metadata
|
59
|
+
case @git_metadata
|
60
|
+
when nil
|
61
|
+
@git_metadata = GitBlamer.new(@attributes).blame || false
|
62
|
+
when false
|
63
|
+
nil
|
64
|
+
else
|
65
|
+
@git_metadata
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def has_git_metadata?
|
70
|
+
!!git_metadata
|
71
|
+
end
|
72
|
+
|
73
|
+
def ignore?
|
74
|
+
path && line && has_ignore_annotation?
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def has_ignore_annotation?
|
80
|
+
line_content =~ /#\s*ignore/i
|
81
|
+
end
|
82
|
+
|
83
|
+
def line_content
|
84
|
+
File.readlines(path)[line - 1]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_hunter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/code_hunter/renderer.rb
|
152
152
|
- lib/code_hunter/runner.rb
|
153
153
|
- lib/code_hunter/version.rb
|
154
|
+
- lib/code_hunter/warning.rb
|
154
155
|
- spec/code_hunter/pendaxes_spec.rb
|
155
156
|
- spec/code_hunter/renderer_spec.rb
|
156
157
|
- spec/code_hunter/runner_spec.rb
|