jsmetric 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.
Files changed (45) hide show
  1. data/.gitignore +6 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +2 -0
  4. data/README +36 -0
  5. data/Rakefile +37 -0
  6. data/bin/jsmetric +16 -0
  7. data/boot.rb +5 -0
  8. data/build +1 -0
  9. data/features/cyclometric_complexity/boolean_complexity_counting.feature +46 -0
  10. data/features/cyclometric_complexity/case_complexity_counting.feature +117 -0
  11. data/features/cyclometric_complexity/exception_complexity_counting.feature +81 -0
  12. data/features/cyclometric_complexity/function_detection.feature +128 -0
  13. data/features/cyclometric_complexity/if_else_complexity_counting.feature +178 -0
  14. data/features/cyclometric_complexity/loop_complexity_counting.feature +81 -0
  15. data/features/graphing/draw_basic_graph.feature +14 -0
  16. data/features/reporting/report.feature +13 -0
  17. data/features/sample_js_files_for_test/foobar.js +30 -0
  18. data/features/step_definitions/cyclometric_complexity_steps.rb +31 -0
  19. data/features/step_definitions/graph_steps.rb +10 -0
  20. data/features/step_definitions/reporting_steps.rb +14 -0
  21. data/features/support/env.rb +1 -0
  22. data/jsgraphlib/Curry-1.0.1.js +29 -0
  23. data/jsgraphlib/dracula_algorithms.js +599 -0
  24. data/jsgraphlib/dracula_graffle.js +106 -0
  25. data/jsgraphlib/dracula_graph.js +534 -0
  26. data/jsgraphlib/graphtest.html +57 -0
  27. data/jsgraphlib/jquery-1.4.2.min.js +154 -0
  28. data/jsgraphlib/jsgraphsource.js +12 -0
  29. data/jsgraphlib/raphael-min.js +7 -0
  30. data/jsgraphlib/seedrandom.js +266 -0
  31. data/jsmetric.gemspec +26 -0
  32. data/lib/cc_report.rb +20 -0
  33. data/lib/complexity_analyser.rb +90 -0
  34. data/lib/fulljslint.js +6100 -0
  35. data/lib/graphing/graph_analyser.rb +19 -0
  36. data/lib/js_lint.rb +28 -0
  37. data/lib/json2.js +480 -0
  38. data/lib/options.js +24 -0
  39. data/lib/report.rb +9 -0
  40. data/lib/utils.rb +18 -0
  41. data/lib/version.rb +3 -0
  42. data/spec/spec_helper.rb +1 -0
  43. data/tasks/dev.rb +4 -0
  44. data/tasks/run.rb +55 -0
  45. metadata +175 -0
@@ -0,0 +1,24 @@
1
+ var options = {
2
+ browser : true,
3
+ undef : true,
4
+ eqeqeq: true,
5
+ bitwise: true,
6
+ newcap : true,
7
+ predef : [
8
+ "_place",
9
+ "_placeModel",
10
+ "_dfwData",
11
+ "$",
12
+ "AjaxUpload",
13
+ "Class",
14
+ "Cookie",
15
+ "jQuery",
16
+ "nokia",
17
+ "Ovi",
18
+ "ovi",
19
+ "places",
20
+ "player",
21
+ "ts",
22
+ "window"
23
+ ]
24
+ }
@@ -0,0 +1,9 @@
1
+ require "cc_report"
2
+ class Report
3
+
4
+ def self.for file_path
5
+ contents = File.open(file_path, 'r') { |f| f.read }
6
+ CCReport.generate_for contents
7
+ end
8
+
9
+ end
@@ -0,0 +1,18 @@
1
+ def strip_js(data)
2
+ non_empty_strings = []
3
+ stripped_data = data.gsub(/('|").*?[^\\]\1/) { |m|
4
+ non_empty_strings.push $&
5
+ "!temp-string-replacement-#{non_empty_strings.size}!"
6
+ }
7
+ stripped_data.gsub(/\/\*.*?\*\//m, "\n").gsub(/\/\/.*$/, "").gsub(/( |\t)+$/, "").gsub(/\n+/, "\n").gsub(/!temp-string-replacement-([0-9]+)!/) { |m| non_empty_strings[$1.to_i] }
8
+ end
9
+
10
+
11
+ def word_freq_in the_file
12
+ store = Hash.new
13
+ the_file.each_line { |line|
14
+ line.split.each { |word| store.has_key?(word) ? store[word] += 1 : store[word] = 1 }
15
+ }
16
+ store.sort { |a, b| a[1]<=>b[1] }
17
+ store
18
+ end
@@ -0,0 +1,3 @@
1
+ module Jsmetric
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require(File.join(File.dirname(__FILE__),'..','boot'))
@@ -0,0 +1,4 @@
1
+ desc "Run all cukes tagged with @current"
2
+ Cucumber::Rake::Task.new(:current) do |t|
3
+ t.cucumber_opts = "--tags @current"
4
+ end
@@ -0,0 +1,55 @@
1
+ #TODO : Replace with execution path through bin/jsmetric
2
+
3
+ namespace :run do
4
+
5
+ desc "Produces a CSV list of LOC & number of functions per js file in a given directory (recursive)"
6
+ task :loc_func_map, :dir do |task, args|
7
+
8
+ raise "No Dir specified" unless args.dir
9
+ puts "Name,Dir,LOC,Functions"
10
+ Dir.chdir(args.dir) do
11
+ js_files = Dir.glob(File.join("**", "*.js"))
12
+ js_files.each do |file|
13
+ contents = File.open(file, 'r') { |f| f.read }
14
+ cleaned_content = strip_js(contents)
15
+ functions = cleaned_content.split("function")
16
+ puts "#{Pathname.new(file).basename},#{Pathname.new(file).dirname},#{cleaned_content.split("\n").size - 1 },#{functions.size}"
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ desc "Produces a CSV list of LOC & overall complexity per js file in a given directory (recursive)"
23
+ task :loc_complexity_map, :dir do |task, args|
24
+ raise "No Dir specified" unless args.dir
25
+
26
+ Dir.chdir(args.dir) do
27
+ js_files = Dir.glob(File.join("**", "*.js"))
28
+ js_files.reject! { |file| file.include?(".core.js") }
29
+ outputs = []
30
+ js_files.each do |file|
31
+ contents = File.open(file, 'r') { |f| f.read }
32
+ analyser = ComplexityAnalyser.new
33
+ begin
34
+ analyser.parse contents
35
+ outputs << {file => analyser.functions}
36
+ rescue
37
+ p "WARNING: Could not parse #{file} : SKIPPED #{file}"
38
+ end
39
+ end
40
+
41
+ puts "dir,file,funcs,totalcc"
42
+ outputs.each do |output|
43
+ output.each do |file_name, report|
44
+ file_complexity = 0
45
+
46
+ report.each do |analysis|
47
+ file_complexity += analysis[:complexity]
48
+ end
49
+ puts "#{Pathname.new(file_name).dirname},#{Pathname.new(file_name).basename},#{report.size},#{file_complexity}"
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsmetric
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Nigel Fernandes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-06 00:00:00 +10:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.4.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.8.7
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: cucumber
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.10.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: therubyracer
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.8.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ description: Cyclometric complexity analyser for Javascript
61
+ email:
62
+ - jsmetric@nigel.in
63
+ executables:
64
+ - jsmetric
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - .gitignore
71
+ - .rvmrc
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - README
75
+ - Rakefile
76
+ - bin/jsmetric
77
+ - boot.rb
78
+ - build
79
+ - features/cyclometric_complexity/boolean_complexity_counting.feature
80
+ - features/cyclometric_complexity/case_complexity_counting.feature
81
+ - features/cyclometric_complexity/exception_complexity_counting.feature
82
+ - features/cyclometric_complexity/function_detection.feature
83
+ - features/cyclometric_complexity/if_else_complexity_counting.feature
84
+ - features/cyclometric_complexity/loop_complexity_counting.feature
85
+ - features/graphing/draw_basic_graph.feature
86
+ - features/reporting/report.feature
87
+ - features/sample_js_files_for_test/foobar.js
88
+ - features/step_definitions/cyclometric_complexity_steps.rb
89
+ - features/step_definitions/graph_steps.rb
90
+ - features/step_definitions/reporting_steps.rb
91
+ - features/support/env.rb
92
+ - jsgraphlib/Curry-1.0.1.js
93
+ - jsgraphlib/dracula_algorithms.js
94
+ - jsgraphlib/dracula_graffle.js
95
+ - jsgraphlib/dracula_graph.js
96
+ - jsgraphlib/graphtest.html
97
+ - jsgraphlib/jquery-1.4.2.min.js
98
+ - jsgraphlib/jsgraphsource.js
99
+ - jsgraphlib/raphael-min.js
100
+ - jsgraphlib/seedrandom.js
101
+ - jsmetric.gemspec
102
+ - lib/cc_report.rb
103
+ - lib/complexity_analyser.rb
104
+ - lib/fulljslint.js
105
+ - lib/graphing/graph_analyser.rb
106
+ - lib/js_lint.rb
107
+ - lib/json2.js
108
+ - lib/options.js
109
+ - lib/report.rb
110
+ - lib/utils.rb
111
+ - lib/version.rb
112
+ - spec/spec_helper.rb
113
+ - tasks/dev.rb
114
+ - tasks/run.rb
115
+ - vendor/cache/builder-3.0.0.gem
116
+ - vendor/cache/cucumber-0.10.0.gem
117
+ - vendor/cache/diff-lcs-1.1.2.gem
118
+ - vendor/cache/gherkin-2.3.3.gem
119
+ - vendor/cache/json-1.4.6.gem
120
+ - vendor/cache/rake-0.8.7.gem
121
+ - vendor/cache/rspec-2.4.0.gem
122
+ - vendor/cache/rspec-core-2.4.0.gem
123
+ - vendor/cache/rspec-expectations-2.4.0.gem
124
+ - vendor/cache/rspec-mocks-2.4.0.gem
125
+ - vendor/cache/term-ansicolor-1.0.5.gem
126
+ - vendor/cache/therubyracer-0.8.0.gem
127
+ has_rdoc: true
128
+ homepage: ""
129
+ licenses: []
130
+
131
+ post_install_message:
132
+ rdoc_options: []
133
+
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: -3687799591561362010
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: -3687799591561362010
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ requirements: []
155
+
156
+ rubyforge_project: jsmetric
157
+ rubygems_version: 1.6.2
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Cyclometric complexity analyser for Javascript
161
+ test_files:
162
+ - features/cyclometric_complexity/boolean_complexity_counting.feature
163
+ - features/cyclometric_complexity/case_complexity_counting.feature
164
+ - features/cyclometric_complexity/exception_complexity_counting.feature
165
+ - features/cyclometric_complexity/function_detection.feature
166
+ - features/cyclometric_complexity/if_else_complexity_counting.feature
167
+ - features/cyclometric_complexity/loop_complexity_counting.feature
168
+ - features/graphing/draw_basic_graph.feature
169
+ - features/reporting/report.feature
170
+ - features/sample_js_files_for_test/foobar.js
171
+ - features/step_definitions/cyclometric_complexity_steps.rb
172
+ - features/step_definitions/graph_steps.rb
173
+ - features/step_definitions/reporting_steps.rb
174
+ - features/support/env.rb
175
+ - spec/spec_helper.rb