fukuzatsu 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/lib/fukuzatsu.rb +1 -0
- data/lib/fukuzatsu/cli.rb +22 -8
- data/lib/fukuzatsu/formatters/html.rb +14 -2
- data/lib/fukuzatsu/formatters/html_index.rb +39 -0
- data/lib/fukuzatsu/formatters/templates/index.html.haml +73 -0
- data/lib/fukuzatsu/formatters/templates/output.html.haml +3 -2
- data/lib/fukuzatsu/version.rb +1 -1
- metadata +3 -2
- data/lib/fukuzatsu/util.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1321229a0d5c57e3bd0b2938e295115514c2e73a
|
4
|
+
data.tar.gz: c205ccb2a0e79826e14c6988f1beba80cacff8c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99cb838cafffc71182f18591d22d5ec89c3e5af058a19abd3e3792e0938f5f4a1554e4da4c6c1bf133d78e87bd19d60701513751a68554b962b379c653df5897
|
7
|
+
data.tar.gz: d7c6dfa10faf25af7b7b0cc6d431b02e05d4c09e058b52a5925e91d2bc8d8deef691d2e0c17c758382385b9a587cb01e863c60068668fe45b213950cba68b4d3
|
data/README.md
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
*Note: this gem is a work in progress and should not be considered production-ready until version 1.0*
|
4
4
|
|
5
|
-
Fukuzatsu ("complexity") is a tool for measuring code complexity in Ruby class files. Its analysis
|
6
|
-
|
7
|
-
You can learn more about cyclomatic complexity at http://en.wikipedia.org/wiki/Cyclomatic_complexity
|
5
|
+
Fukuzatsu ("complexity") is a tool for measuring code complexity in Ruby class files. Its analysis generates relative complexity figures similar to the results of cyclomatic complexity algorithms. (You can learn more about cyclomatic complexity at http://en.wikipedia.org/wiki/Cyclomatic_complexity)
|
8
6
|
|
9
7
|
Why should you care about this kind of complexity? More complex code tends to attract bugs and to increase the friction around extending features or refactoring code.
|
10
8
|
|
data/lib/fukuzatsu.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "fukuzatsu/cli"
|
|
8
8
|
require_relative "fukuzatsu/formatters/base"
|
9
9
|
require_relative "fukuzatsu/formatters/csv"
|
10
10
|
require_relative "fukuzatsu/formatters/html"
|
11
|
+
require_relative "fukuzatsu/formatters/html_index"
|
11
12
|
require_relative "fukuzatsu/formatters/text"
|
12
13
|
require_relative "fukuzatsu/parsed_file"
|
13
14
|
require_relative "fukuzatsu/parsed_method"
|
data/lib/fukuzatsu/cli.rb
CHANGED
@@ -14,8 +14,11 @@ module Fukuzatsu
|
|
14
14
|
|
15
15
|
def check(path)
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
file_summary = []
|
18
|
+
file_complexities = []
|
19
|
+
|
20
|
+
file_list(path).each do |path_to_file|
|
21
|
+
file = ParsedFile.new(path_to_file: path_to_file)
|
19
22
|
case options['format']
|
20
23
|
when 'html'
|
21
24
|
Formatters::Html.new(file).export
|
@@ -24,20 +27,31 @@ module Fukuzatsu
|
|
24
27
|
else
|
25
28
|
Formatters::Text.new(file).export
|
26
29
|
end
|
27
|
-
file.complexity
|
30
|
+
file_summary << {path_to_file: path_to_file, class_name: file.class_name, complexity: file.complexity}
|
31
|
+
file_complexities << file.complexity
|
28
32
|
end
|
29
33
|
|
30
|
-
|
34
|
+
Formatters::HtmlIndex.new(file_summary).export if options['format'] == 'html'
|
31
35
|
|
32
|
-
|
33
|
-
puts "Maximum complexity is #{highest_complexity}, which is greater than the threshold of #{options['threshold']}."
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
+
handle_complexity(file_complexities.sort.last, options['threshold'])
|
36
37
|
|
37
38
|
end
|
38
39
|
|
39
40
|
private
|
40
41
|
|
42
|
+
def write_index(file_list)
|
43
|
+
Formatters::Html.write_index(file_list)
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle_complexity(max, threshold)
|
47
|
+
return if options['threshold'] == 0
|
48
|
+
return if highest_complexity <= options['threshold']
|
49
|
+
puts "=" * 40
|
50
|
+
puts "Maximum complexity is #{highest_complexity}, which is greater than the threshold of #{options['threshold']}."
|
51
|
+
puts "=" * 40
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
|
41
55
|
def file_list(start_file)
|
42
56
|
if File.directory?(start_file)
|
43
57
|
return Dir.glob(File.join(start_file, "**", "*")).select{|n| n =~ /\.rb$/}
|
@@ -4,12 +4,24 @@ module Formatters
|
|
4
4
|
|
5
5
|
include Formatters::Base
|
6
6
|
|
7
|
+
def self.write_index(file_list)
|
8
|
+
index_template = File.read(File.dirname(__FILE__) + "/templates/index.html.haml")
|
9
|
+
Haml::Engine.new(index_template).render(
|
10
|
+
Object.new, {
|
11
|
+
file_list: file_list,
|
12
|
+
date: Time.now.strftime("%Y/%m/%d"),
|
13
|
+
time: Time.now.strftime("%l:%M %P")
|
14
|
+
}
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
7
18
|
def header
|
8
19
|
columns.map{|col| "<th>#{col.titleize}</th>"}.join("\r\n")
|
9
20
|
end
|
10
21
|
|
11
22
|
def content
|
12
|
-
Haml::Engine.new(
|
23
|
+
Haml::Engine.new(output_template).render(
|
24
|
+
Object.new, {
|
13
25
|
header: header,
|
14
26
|
rows: rows,
|
15
27
|
class_name: file.class_name,
|
@@ -20,7 +32,7 @@ module Formatters
|
|
20
32
|
)
|
21
33
|
end
|
22
34
|
|
23
|
-
def
|
35
|
+
def output_template
|
24
36
|
File.read(File.dirname(__FILE__) + "/templates/output.html.haml")
|
25
37
|
end
|
26
38
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Formatters
|
2
|
+
|
3
|
+
class HtmlIndex
|
4
|
+
|
5
|
+
include Formatters::Base
|
6
|
+
|
7
|
+
attr_accessor :file_summary
|
8
|
+
|
9
|
+
def initialize(file_summary)
|
10
|
+
self.file_summary = file_summary
|
11
|
+
end
|
12
|
+
|
13
|
+
def filename
|
14
|
+
"index.htm"
|
15
|
+
end
|
16
|
+
|
17
|
+
def output_path
|
18
|
+
output_path = "doc/fukuzatsu/"
|
19
|
+
FileUtils.mkpath(output_path)
|
20
|
+
output_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def content
|
24
|
+
Haml::Engine.new(output_template).render(
|
25
|
+
Object.new, {
|
26
|
+
file_summary: file_summary,
|
27
|
+
date: Time.now.strftime("%Y/%m/%d"),
|
28
|
+
time: Time.now.strftime("%l:%M %P")
|
29
|
+
}
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def output_template
|
34
|
+
File.read(File.dirname(__FILE__) + "/templates/index.html.haml")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title
|
5
|
+
Fukuzatsu
|
6
|
+
%link{href: "http://cdn.datatables.net/1.10.0/css/jquery.dataTables.css", rel: "stylesheet"}
|
7
|
+
%script{language: "javascript", src: "http://code.jquery.com/jquery-1.11.0.min.js", type: "text/javascript"}
|
8
|
+
%script{language: "javascript", src: "http://code.jquery.com/jquery-migrate-1.2.1.min.js", type: "text/javascript"}
|
9
|
+
%script{language: "javascript", src: "http://cdn.datatables.net/1.10.0/js/jquery.dataTables.js", type: "text/javascript"}
|
10
|
+
|
11
|
+
%style{media: "screen", type: "text/css"}
|
12
|
+
body { background: #593232; color: #fff; font-family: arial, sans-serif; padding: 2em; }
|
13
|
+
table { border: 10px solid #000; border-collapse: collapse; min-width: 50%; }
|
14
|
+
tr { border-top: 1px solid #000; }
|
15
|
+
tr.header { background: rgba(255, 255, 255, 0.75)}
|
16
|
+
tr.even { background: rgba(128, 128, 128, 0.5) !important;}
|
17
|
+
tr.odd { background: rgba(128, 128, 128, 0.25) !important;}
|
18
|
+
tr.even:hover, tr.odd:hover { background: rgba(128, 128, 128, 0.75) !important;}
|
19
|
+
th { background: #000; text-align: left; padding: .5em; text-transform: uppercase; font-size: .8em}
|
20
|
+
td { text-align: left; padding: .5em; padding-left: 1.25em !important;}
|
21
|
+
td.center { text-align: center; }
|
22
|
+
tfoot { background: #000; border-top: 10px solid #000; font-family: courier; margin-top: 4em; font-size: .75em; }
|
23
|
+
a:link, a:visited { color: #aaa }
|
24
|
+
h1 { color:#593232; font-size: 1.25em; }
|
25
|
+
h2 { color:#593232; font-size: .75em; margin-top: -1em}
|
26
|
+
td.sorting_1 { background: none !important; padding-left: 1.25em !important; }
|
27
|
+
div.dataTables_filter label { color: #fff; }
|
28
|
+
div.dataTables_paginate { display: none !important; }
|
29
|
+
div.dataTables_info { display: none !important; }
|
30
|
+
|
31
|
+
%body
|
32
|
+
%table{class: "output-table"}
|
33
|
+
%thead
|
34
|
+
%tr
|
35
|
+
%th
|
36
|
+
File
|
37
|
+
%th
|
38
|
+
Module/Class Name
|
39
|
+
%th
|
40
|
+
Complexity
|
41
|
+
%th
|
42
|
+
Details
|
43
|
+
%tbody
|
44
|
+
- file_summary.each do |summary|
|
45
|
+
%tr
|
46
|
+
%td
|
47
|
+
= summary[:path_to_file]
|
48
|
+
%td
|
49
|
+
= summary[:class_name]
|
50
|
+
%td
|
51
|
+
= summary[:complexity]
|
52
|
+
%td
|
53
|
+
%a{href: "#{summary[:path_to_file]}.htm"}
|
54
|
+
View Details
|
55
|
+
%tfoot
|
56
|
+
%tr
|
57
|
+
%td.center{colspan: 4}
|
58
|
+
%em
|
59
|
+
Analyzed on
|
60
|
+
= date
|
61
|
+
at
|
62
|
+
= time
|
63
|
+
by
|
64
|
+
%a{href: "https://gitlab.com/coraline/fukuzatsu", target: "_new"}
|
65
|
+
Fukuzatsu
|
66
|
+
:javascript
|
67
|
+
$(document).ready(function(){
|
68
|
+
$('.output-table').dataTable({
|
69
|
+
bLengthChange: false,
|
70
|
+
iDisplayLength: 25000
|
71
|
+
});
|
72
|
+
});
|
73
|
+
|
@@ -16,14 +16,15 @@
|
|
16
16
|
tr.header { background: rgba(255, 255, 255, 0.75)}
|
17
17
|
tr.even { background: rgba(128, 128, 128, 0.5) !important;}
|
18
18
|
tr.odd { background: rgba(128, 128, 128, 0.25) !important}
|
19
|
+
tr.even:hover, tr.odd:hover { background: rgba(128, 128, 128, 0.75) !important;}
|
19
20
|
th { background: #000; text-align: left; padding: .5em; text-transform: uppercase; font-size: .8em}
|
20
|
-
td { text-align: left; padding: .5em;}
|
21
|
+
td { text-align: left; padding: .5em; padding-left: 1.25em !important;}
|
21
22
|
td.center { text-align: center; }
|
23
|
+
td.sorting_1 { background: none !important; padding-left: 1.25em !important; }
|
22
24
|
tfoot { background: #000; border-top: 10px solid #000; font-family: courier; margin-top: 4em; font-size: .75em; }
|
23
25
|
a:link, a:visited { color: #aaa }
|
24
26
|
h1 { color:#593232; font-size: 1.25em; }
|
25
27
|
h2 { color:#593232; font-size: .75em; margin-top: -1em}
|
26
|
-
td.sorting_1 { background: none !important; }
|
27
28
|
div.dataTables_filter { display: none !important; }
|
28
29
|
div.dataTables_paginate { display: none !important; }
|
29
30
|
div.dataTables_info { display: none !important; }
|
data/lib/fukuzatsu/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fukuzatsu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bantik
|
@@ -145,11 +145,12 @@ files:
|
|
145
145
|
- lib/fukuzatsu/formatters/base.rb
|
146
146
|
- lib/fukuzatsu/formatters/csv.rb
|
147
147
|
- lib/fukuzatsu/formatters/html.rb
|
148
|
+
- lib/fukuzatsu/formatters/html_index.rb
|
149
|
+
- lib/fukuzatsu/formatters/templates/index.html.haml
|
148
150
|
- lib/fukuzatsu/formatters/templates/output.html.haml
|
149
151
|
- lib/fukuzatsu/formatters/text.rb
|
150
152
|
- lib/fukuzatsu/parsed_file.rb
|
151
153
|
- lib/fukuzatsu/parsed_method.rb
|
152
|
-
- lib/fukuzatsu/util.rb
|
153
154
|
- lib/fukuzatsu/version.rb
|
154
155
|
- spec/analyzer_spec.rb
|
155
156
|
- spec/fixtures/program_1.rb
|
data/lib/fukuzatsu/util.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
util.rb
|