fukuzatsu 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -0
- data/lib/fukuzatsu/analyzer.rb +14 -1
- data/lib/fukuzatsu/cli.rb +36 -9
- data/lib/fukuzatsu/util.rb +1 -0
- data/lib/fukuzatsu/version.rb +1 -1
- data/spec/fixtures/program_4.rb +1 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efab3a434a8c65a1adb32fd0d7094305b2b9d0af
|
4
|
+
data.tar.gz: 5c00a9a29a444a828ef9004ed6dd49973daf487d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae7fe25e982c111c13744a8d07ed9699e987a20d8ba15decd8cb2bc367e8f04e790b828968a0a69d94a0b98eadf88468288e2dbe19cb103d46c4f41a95ca8252
|
7
|
+
data.tar.gz: e10e18df2971b516b966508d68a747564e09a5a81fe344c058fbc0d6eb8cd0f7376b7b9c921895d41091d1e034a2ce17cd2f9b849535ecc9249308eda12e2d56
|
data/Rakefile
CHANGED
data/lib/fukuzatsu/analyzer.rb
CHANGED
@@ -24,12 +24,25 @@ class Analyzer
|
|
24
24
|
|
25
25
|
def extract_class_name
|
26
26
|
return self.class_name if self.class_name
|
27
|
-
|
27
|
+
child = find_class(parsed)
|
28
|
+
return "?" unless child
|
29
|
+
name = child.loc.name
|
28
30
|
self.class_name = self.content[name.begin_pos..(name.end_pos - 1)]
|
29
31
|
end
|
30
32
|
|
31
33
|
private
|
32
34
|
|
35
|
+
def find_class(parsed)
|
36
|
+
return parsed if parsed.respond_to?(:type) && (parsed.type == :class || (parsed.type == :module && parsed.children.empty?))
|
37
|
+
child_nodes = parsed.respond_to?(:children) ? parsed.children : parsed
|
38
|
+
child_nodes.each do |child_node|
|
39
|
+
next unless child_node.respond_to?(:type)
|
40
|
+
return child_node if child_node.type == :class
|
41
|
+
return find_class(child_node.children) if child_node.type == :module
|
42
|
+
end
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
33
46
|
def extend_graph
|
34
47
|
self.edges += 2
|
35
48
|
self.nodes += 2
|
data/lib/fukuzatsu/cli.rb
CHANGED
@@ -5,17 +5,44 @@ module Fukuzatsu
|
|
5
5
|
|
6
6
|
class CLI < Thor
|
7
7
|
|
8
|
-
|
8
|
+
desc_text = "Formats are text (default, to STDOUT), html, and csv. "
|
9
|
+
desc_text << "Example: fuku check foo/ -f html"
|
10
|
+
|
11
|
+
desc "check PATH_TO_FILE [-f FORMAT] [-t MAX_COMPLEXITY_ALLOWED]", desc_text
|
9
12
|
method_option :format, :type => :string, :default => 'text', :aliases => "-f"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
method_option :threshold, :type => :numeric, :default => 0, :aliases => "-t"
|
14
|
+
|
15
|
+
def check(path)
|
16
|
+
|
17
|
+
file_complexities = file_list(path).map do |file|
|
18
|
+
file = ParsedFile.new(path_to_file: file)
|
19
|
+
case options['format']
|
20
|
+
when 'html'
|
21
|
+
Formatters::Html.new(file).export
|
22
|
+
when 'csv'
|
23
|
+
Formatters::Csv.new(file).export
|
24
|
+
else
|
25
|
+
Formatters::Text.new(file).export
|
26
|
+
end
|
27
|
+
file.complexity
|
28
|
+
end
|
29
|
+
|
30
|
+
highest_complexity = file_complexities.sort.last
|
31
|
+
|
32
|
+
if options['threshold'] != 0 && highest_complexity > options['threshold']
|
33
|
+
puts "Maximum complexity is #{highest_complexity}, which is greater than the threshold of #{options['threshold']}."
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def file_list(start_file)
|
42
|
+
if File.directory?(start_file)
|
43
|
+
return Dir.glob(File.join(start_file, "**", "*")).select{|n| n =~ /\.rb$/}
|
17
44
|
else
|
18
|
-
|
45
|
+
return [start_file]
|
19
46
|
end
|
20
47
|
end
|
21
48
|
|
@@ -0,0 +1 @@
|
|
1
|
+
util.rb
|
data/lib/fukuzatsu/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
program_4.rb
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bantik
|
@@ -149,11 +149,13 @@ files:
|
|
149
149
|
- lib/fukuzatsu/formatters/text.rb
|
150
150
|
- lib/fukuzatsu/parsed_file.rb
|
151
151
|
- lib/fukuzatsu/parsed_method.rb
|
152
|
+
- lib/fukuzatsu/util.rb
|
152
153
|
- lib/fukuzatsu/version.rb
|
153
154
|
- spec/analyzer_spec.rb
|
154
155
|
- spec/fixtures/program_1.rb
|
155
156
|
- spec/fixtures/program_2.rb
|
156
157
|
- spec/fixtures/program_3.rb
|
158
|
+
- spec/fixtures/program_4.rb
|
157
159
|
- spec/spec_helper.rb
|
158
160
|
homepage: https://gitlab.com/coraline/fukuzatsu/tree/master
|
159
161
|
licenses:
|
@@ -184,4 +186,5 @@ test_files:
|
|
184
186
|
- spec/fixtures/program_1.rb
|
185
187
|
- spec/fixtures/program_2.rb
|
186
188
|
- spec/fixtures/program_3.rb
|
189
|
+
- spec/fixtures/program_4.rb
|
187
190
|
- spec/spec_helper.rb
|