visionmedia-san 1.0.1 → 1.0.2
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/History.txt +7 -0
- data/README.txt +9 -11
- data/lib/san.rb +56 -54
- data/san.gemspec +2 -3
- metadata +4 -4
- data/test/test_san.rb +0 -1
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -4,22 +4,20 @@ http://vision-media.ca/resources/ruby/source-code-analysis-gem
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
SAN or Source ANalyzer is an open source Ruby program for analyzing the contents
|
8
|
-
of source code, such as line counts and comment ratios.
|
7
|
+
SAN or Source ANalyzer is an open source Ruby program for analyzing the contents
|
8
|
+
of source code, such as line counts and comment ratios.
|
9
9
|
|
10
|
-
==
|
10
|
+
== TODO:
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
none
|
12
|
+
* Optionally blacklist or whitelist languages, extensions, etc
|
13
|
+
* More OO
|
14
|
+
* Use commander
|
17
15
|
|
18
16
|
== AUTHOR:
|
19
17
|
|
20
|
-
TJ Holowaychuk
|
21
|
-
tj@vision-media.ca
|
22
|
-
http://vision-media.ca
|
18
|
+
TJ Holowaychuk
|
19
|
+
tj@vision-media.ca
|
20
|
+
http://vision-media.ca
|
23
21
|
|
24
22
|
== LICENSE:
|
25
23
|
|
data/lib/san.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# == Synopsis
|
4
|
-
#
|
5
|
-
#
|
4
|
+
# SAN is an open source Ruby program for analysing the contents
|
5
|
+
# of source code, such as line counts and comment ratios.
|
6
6
|
#
|
7
7
|
# == Usage
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# san [-hVr] [ dir | file ... ]
|
9
|
+
#
|
10
10
|
# == Examples
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
11
|
+
# Analyse current directory
|
12
|
+
# san
|
13
|
+
#
|
14
|
+
# Analyse current directory recursively
|
15
|
+
# san --recursive
|
16
|
+
#
|
17
|
+
# Analyse specific files and a directory recursively
|
18
|
+
# san -r ./index.php ./cron.php ./sites/all/modules/gui
|
19
|
+
#
|
20
20
|
# == Options
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
21
|
+
# -h, --help Display this help information.
|
22
|
+
# -V, --version Display version of lc.
|
23
|
+
# -r, --recurse Scan directories recursively.
|
24
24
|
#
|
25
25
|
# == Author
|
26
|
-
#
|
26
|
+
# TJ Holowaychuk
|
27
27
|
#
|
28
28
|
# == Copyright
|
29
|
-
#
|
30
|
-
#
|
29
|
+
# Copyright (c) 2008 TJ Holowaychuk. Licensed under the MIT License:
|
30
|
+
# http://www.opensource.org/licenses/mit-license.php
|
31
31
|
|
32
32
|
require 'optparse'
|
33
33
|
require 'rdoc/usage'
|
@@ -78,15 +78,18 @@ $syntax = {
|
|
78
78
|
|
79
79
|
class San
|
80
80
|
|
81
|
-
|
81
|
+
MAJOR = 1
|
82
|
+
MINOR = 0
|
83
|
+
TINY = 2
|
84
|
+
VERSION = [MAJOR, MINOR, TINY].join('.')
|
82
85
|
|
83
86
|
attr_reader :files, :reports
|
84
87
|
attr_accessor :options, :arguments
|
85
88
|
|
86
89
|
# Initialize
|
87
|
-
def initialize
|
88
|
-
|
89
|
-
|
90
|
+
def initialize
|
91
|
+
initialize_options
|
92
|
+
initialize_reports
|
90
93
|
end
|
91
94
|
|
92
95
|
# Initialize option defaults
|
@@ -100,8 +103,8 @@ class San
|
|
100
103
|
@reports = {}
|
101
104
|
@reports[:comment_ratio] = 0
|
102
105
|
@reports[:totals] = {
|
103
|
-
|
104
|
-
|
106
|
+
'files' => 0,
|
107
|
+
'lines' => 0,
|
105
108
|
'lines blank' => 0,
|
106
109
|
'lines comments' => 0,
|
107
110
|
'lines todo' => 0,
|
@@ -119,7 +122,7 @@ class San
|
|
119
122
|
# Start analysis.
|
120
123
|
def run
|
121
124
|
# Parse options
|
122
|
-
|
125
|
+
parse_options
|
123
126
|
|
124
127
|
# Default files to cwd
|
125
128
|
@files = @arguments.empty? ? ['.'] : @arguments
|
@@ -130,16 +133,16 @@ class San
|
|
130
133
|
if File.directory?(file)
|
131
134
|
files = Dir[(@options[:recursive] ? '**/' : '') << file << '/*.{' + file_pattern + '}']
|
132
135
|
files.each do |file|
|
133
|
-
|
136
|
+
parse_script(file)
|
134
137
|
end
|
135
138
|
elsif File.file?(file)
|
136
|
-
|
139
|
+
parse_script(file)
|
137
140
|
end
|
138
141
|
end
|
139
142
|
|
140
143
|
# Report
|
141
|
-
|
142
|
-
|
144
|
+
prep_report
|
145
|
+
output_report
|
143
146
|
exit
|
144
147
|
end
|
145
148
|
|
@@ -147,14 +150,13 @@ class San
|
|
147
150
|
def parse_options
|
148
151
|
opts = OptionParser.new
|
149
152
|
opts.on('-h', '--help') { RDoc.usage(0) }
|
150
|
-
opts.on('-V', '--version') {
|
153
|
+
opts.on('-V', '--version') { output_version; exit 0 }
|
151
154
|
opts.on('-r', '--recursive') { @options[:recursive] = true }
|
152
155
|
begin
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
156
|
+
opts.parse!(@arguments)
|
157
|
+
rescue => e
|
158
|
+
abort e
|
159
|
+
end
|
158
160
|
end
|
159
161
|
|
160
162
|
# Get extension of filepath.
|
@@ -188,21 +190,21 @@ class San
|
|
188
190
|
@reports[:totals]['lines'] += 1
|
189
191
|
@reports[:totals]['lines blank'] += 1 if line.match(lang[:blank])
|
190
192
|
if !line.match(lang[:blank])
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
193
|
+
@reports[:totals]['lines todo'] += 1 if line.match(lang[:todo])
|
194
|
+
case
|
195
|
+
when line.match(lang[:comment]); @reports[:totals]['lines comments'] += 1
|
196
|
+
when line.match(lang[:comment_open]); @reports[:totals]['lines comments'] += 1; comment_open = true
|
197
|
+
when line.match(lang[:comment_close]); @reports[:totals]['lines comments'] += 1; comment_open = false
|
198
|
+
else
|
199
|
+
if comment_open
|
200
|
+
@reports[:totals]['lines comments'] += 1
|
201
|
+
else
|
202
|
+
@reports[:totals]['lines script'] += 1
|
203
|
+
case
|
204
|
+
when lang[:function] && line.match(lang[:function]); @reports[:totals]['declared functions'] += 1
|
205
|
+
when lang[:class] && line.match(lang[:class]); @reports[:totals]['declared classes'] += 1
|
206
|
+
end
|
207
|
+
end
|
206
208
|
end
|
207
209
|
end
|
208
210
|
end
|
@@ -218,9 +220,9 @@ class San
|
|
218
220
|
|
219
221
|
# Output report.
|
220
222
|
def output_report
|
221
|
-
|
222
|
-
|
223
|
-
|
223
|
+
@reports[:totals].keys.sort.each do |k|
|
224
|
+
puts k + ' ' + @reports[:totals][k].to_s unless @reports[:totals][k] == 0
|
225
|
+
end
|
224
226
|
puts 'comment ratio ' << '%.2f' % @reports[:comment_ratio] unless @reports[:comment_ratio] == 0
|
225
227
|
end
|
226
228
|
|
data/san.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "san"
|
3
|
-
s.version = "1.0.
|
4
|
-
s.date = "2008-10-
|
3
|
+
s.version = "1.0.2"
|
4
|
+
s.date = "2008-10-21"
|
5
5
|
s.summary = "Source code analysis script"
|
6
6
|
s.email = "tj@vision-media.ca"
|
7
7
|
s.homepage = "http://vision-media.ca/resources/ruby/source-code-analysis-gem"
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
"lib/san.rb",
|
18
18
|
"bin/san"]
|
19
19
|
s.executables = ["san"]
|
20
|
-
s.test_files = ["test/test_san.rb"]
|
21
20
|
s.rdoc_options = ["--main", "README.txt"]
|
22
21
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
23
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visionmedia-san
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tj@vision-media.ca
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -58,5 +58,5 @@ rubygems_version: 1.2.0
|
|
58
58
|
signing_key:
|
59
59
|
specification_version: 2
|
60
60
|
summary: Source code analysis script
|
61
|
-
test_files:
|
62
|
-
|
61
|
+
test_files: []
|
62
|
+
|
data/test/test_san.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
|