jsmetric4java 0.1
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/.gitignore +7 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -0
- data/README +16 -0
- data/Rakefile +37 -0
- data/bin/jsmetric4java +20 -0
- data/boot.rb +5 -0
- data/build +1 -0
- data/features/cyclometric_complexity/boolean_complexity_counting.feature +46 -0
- data/features/cyclometric_complexity/case_complexity_counting.feature +117 -0
- data/features/cyclometric_complexity/exception_complexity_counting.feature +81 -0
- data/features/cyclometric_complexity/function_detection.feature +128 -0
- data/features/cyclometric_complexity/if_else_complexity_counting.feature +178 -0
- data/features/cyclometric_complexity/loop_complexity_counting.feature +81 -0
- data/features/graphing/draw_basic_graph.feature +14 -0
- data/features/reporting/report.feature +13 -0
- data/features/sample_js_files_for_test/foobar.js +30 -0
- data/features/step_definitions/cyclometric_complexity_steps.rb +31 -0
- data/features/step_definitions/graph_steps.rb +10 -0
- data/features/step_definitions/reporting_steps.rb +14 -0
- data/features/support/env.rb +1 -0
- data/jsgraphlib/Curry-1.0.1.js +29 -0
- data/jsgraphlib/dracula_algorithms.js +599 -0
- data/jsgraphlib/dracula_graffle.js +106 -0
- data/jsgraphlib/dracula_graph.js +534 -0
- data/jsgraphlib/graphtest.html +57 -0
- data/jsgraphlib/jquery-1.4.2.min.js +154 -0
- data/jsgraphlib/jsgraphsource.js +12 -0
- data/jsgraphlib/raphael-min.js +7 -0
- data/jsgraphlib/seedrandom.js +266 -0
- data/jsmetric.gemspec +23 -0
- data/lib/cc_report.rb +24 -0
- data/lib/complexity_analyser.rb +90 -0
- data/lib/fulljslint.js +6100 -0
- data/lib/graphing/graph_analyser.rb +19 -0
- data/lib/js_lint.rb +23 -0
- data/lib/json2.js +480 -0
- data/lib/options.js +24 -0
- data/lib/report.rb +26 -0
- data/lib/utils.rb +18 -0
- data/lib/version.rb +3 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/dev.rb +4 -0
- data/tasks/run.rb +55 -0
- metadata +129 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
@loops
|
2
|
+
Feature: Calculate LOOP complexity for a stand alone Javascript function
|
3
|
+
|
4
|
+
Scenario: Single FOR loop
|
5
|
+
Given javascript code as:
|
6
|
+
"""
|
7
|
+
function foo() {
|
8
|
+
var i;
|
9
|
+
for(i=1;i<3;i++) {}
|
10
|
+
};
|
11
|
+
"""
|
12
|
+
When I run the complexity analysis on it
|
13
|
+
Then the complexity is reported as "2"
|
14
|
+
|
15
|
+
Scenario: Single WHILE loop
|
16
|
+
Given javascript code as:
|
17
|
+
"""
|
18
|
+
function foo() {
|
19
|
+
while(true) {}
|
20
|
+
};
|
21
|
+
"""
|
22
|
+
When I run the complexity analysis on it
|
23
|
+
Then the complexity is reported as "2"
|
24
|
+
|
25
|
+
Scenario: Single DO/WHILE loop
|
26
|
+
Given javascript code as:
|
27
|
+
"""
|
28
|
+
function foo() {
|
29
|
+
do { }
|
30
|
+
while (true);
|
31
|
+
}
|
32
|
+
"""
|
33
|
+
When I run the complexity analysis on it
|
34
|
+
Then the complexity is reported as "2"
|
35
|
+
|
36
|
+
Scenario: Multiple WHILE/DO loops in sequence
|
37
|
+
Given javascript code as:
|
38
|
+
"""
|
39
|
+
function foo() {
|
40
|
+
while (true)
|
41
|
+
{
|
42
|
+
// do something
|
43
|
+
}
|
44
|
+
|
45
|
+
do {
|
46
|
+
// something else
|
47
|
+
}
|
48
|
+
while (true);
|
49
|
+
}
|
50
|
+
"""
|
51
|
+
When I run the complexity analysis on it
|
52
|
+
Then the complexity is reported as "3"
|
53
|
+
|
54
|
+
Scenario: Nested FOR loops
|
55
|
+
Given javascript code as:
|
56
|
+
"""
|
57
|
+
function foo() {
|
58
|
+
var i,j;
|
59
|
+
for(i=1;i<3;i++) {
|
60
|
+
for(j=1;j<3;j++) {
|
61
|
+
}
|
62
|
+
}
|
63
|
+
};
|
64
|
+
"""
|
65
|
+
When I run the complexity analysis on it
|
66
|
+
Then the complexity is reported as "3"
|
67
|
+
|
68
|
+
Scenario: Nested FOR loops
|
69
|
+
Given javascript code as:
|
70
|
+
"""
|
71
|
+
function foo() {
|
72
|
+
while(true) {
|
73
|
+
do {
|
74
|
+
|
75
|
+
}
|
76
|
+
while(true)
|
77
|
+
}
|
78
|
+
};
|
79
|
+
"""
|
80
|
+
When I run the complexity analysis on it
|
81
|
+
Then the complexity is reported as "3"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: Output JSON to describe calls within a class
|
2
|
+
|
3
|
+
Scenario: Empty graph data when there is no JavaScript
|
4
|
+
Given javascript code as:
|
5
|
+
"""
|
6
|
+
|
7
|
+
"""
|
8
|
+
When I run the graph analysis on it
|
9
|
+
Then the JSON object returned is:
|
10
|
+
"""
|
11
|
+
{
|
12
|
+
"graphdata" : {}
|
13
|
+
}
|
14
|
+
"""
|
@@ -0,0 +1,13 @@
|
|
1
|
+
@reports
|
2
|
+
Feature: Generate a report for a given JS file
|
3
|
+
|
4
|
+
Scenario: CC and Function name report generated for single sample JS file
|
5
|
+
Given a sample JS file called "foobar"
|
6
|
+
When the CC report target in run on it
|
7
|
+
Then the contents of the report are as follows
|
8
|
+
"""
|
9
|
+
Name, CC
|
10
|
+
Klass,3
|
11
|
+
constructor,2
|
12
|
+
Annonymous,2
|
13
|
+
"""
|
@@ -0,0 +1,30 @@
|
|
1
|
+
// A Sample Test function
|
2
|
+
function Klass(definition)
|
3
|
+
{
|
4
|
+
var prototype = definition;
|
5
|
+
|
6
|
+
if (definition['_extends'] !== undefined)
|
7
|
+
{
|
8
|
+
$.each(definition['_extends'].prototype, function(k, v){
|
9
|
+
|
10
|
+
if (prototype[k] === undefined) {
|
11
|
+
prototype[k] = v;
|
12
|
+
} else {
|
13
|
+
prototype[k+'_super'] = v;
|
14
|
+
}
|
15
|
+
});
|
16
|
+
}
|
17
|
+
|
18
|
+
var constructor = definition['_init'];
|
19
|
+
if (constructor === undefined)
|
20
|
+
{
|
21
|
+
constructor = function()
|
22
|
+
{
|
23
|
+
if (this.prototype('_init_super')) {
|
24
|
+
this._init_super();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
constructor.prototype = prototype;
|
29
|
+
return constructor
|
30
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#TODO: rename this file
|
2
|
+
|
3
|
+
Given /^javascript code as:$/ do |string|
|
4
|
+
@code = string
|
5
|
+
end
|
6
|
+
|
7
|
+
When /^I run the complexity analysis on it$/ do
|
8
|
+
@analyser = ComplexityAnalyser.new
|
9
|
+
@analyser.parse(@code)
|
10
|
+
end
|
11
|
+
|
12
|
+
Then /^the number of functions is reported as "([^"]*)"$/ do |num_funcs|
|
13
|
+
@analyser.functions.count.should eql num_funcs.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
Then /^the complexity is reported as "([^"]*)"$/ do |complexity|
|
17
|
+
@analyser.functions.first[:complexity].should eql complexity.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
And /^the function name is "([^"]*)"$/ do |func_name|
|
21
|
+
@analyser.functions.first[:name].should eql func_name
|
22
|
+
end
|
23
|
+
|
24
|
+
And /^the function names are:$/ do |table|
|
25
|
+
table.hashes.each do |function|
|
26
|
+
match = @analyser.functions.find {|func| func[:name].eql?(function["Name"])}
|
27
|
+
match.should_not be_nil, "Could not find function with name '#{function["Name"]}' in #{@analyser.functions}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Given /^a sample JS file called "([^"]*)"$/ do |filename|
|
2
|
+
@filename = filename
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^the CC report target in run on it$/ do
|
6
|
+
path = File.join(File.dirname(__FILE__),'..', "sample_js_files_for_test", @filename + ".js")
|
7
|
+
contents = File.open(path, 'r') { |f| f.read }
|
8
|
+
@results = CCReport.new(contents).as_csv
|
9
|
+
end
|
10
|
+
|
11
|
+
Then /^the contents of the report are as follows$/ do |expected_report|
|
12
|
+
@results.should == expected_report
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require(File.join(File.dirname(__FILE__),'..' ,'..','boot'))
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* Curry - Function currying
|
3
|
+
* Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
|
4
|
+
* Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)
|
5
|
+
* Date: 10/4/2008
|
6
|
+
*
|
7
|
+
* @author Ariel Flesler
|
8
|
+
* @version 1.0.1
|
9
|
+
*/
|
10
|
+
|
11
|
+
function curry( fn ){
|
12
|
+
return function(){
|
13
|
+
var args = curry.args(arguments),
|
14
|
+
master = arguments.callee,
|
15
|
+
self = this;
|
16
|
+
|
17
|
+
return args.length >= fn.length ? fn.apply(self,args) : function(){
|
18
|
+
return master.apply( self, args.concat(curry.args(arguments)) );
|
19
|
+
};
|
20
|
+
};
|
21
|
+
};
|
22
|
+
|
23
|
+
curry.args = function( args ){
|
24
|
+
return Array.prototype.slice.call(args);
|
25
|
+
};
|
26
|
+
|
27
|
+
Function.prototype.curry = function(){
|
28
|
+
return curry(this);
|
29
|
+
};
|