loco 0.0.4 → 0.0.5

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.
@@ -0,0 +1,116 @@
1
+ # Loco
2
+
3
+ Loco counts all of the lines in all of the files in the current directory and recursively in
4
+ subdirectories. Then it tells you how many lines in how many files. Now you have a pretty
5
+ distribution graph of file sizes in your project. Loco will also show a breakdown of file
6
+ and line counts by file extension. Loco does not count blank lines, but it does count comment
7
+ files because loco is not going to try to guess all the comment formats for all of the
8
+ languages you use.
9
+
10
+ ## Installation
11
+
12
+ $ gem install loco
13
+
14
+ ## Usage
15
+
16
+ $ loco
17
+
18
+ will produce something like this:
19
+
20
+ ### extensions ###
21
+ .rb - 791 files, 25907 lines
22
+ .haml - 391 files, 6938 lines
23
+ .yml - 173 files, 7512 lines
24
+ .rake - 8 files, 383 lines
25
+ .html - 4 files, 179 lines
26
+ .js - 14 files, 840 lines
27
+
28
+ ### longest files ###
29
+ 145 public/javascripts/validations.js
30
+ 145 spec/models/invoice_spec.rb
31
+ 144 app/models/widget/stage.rb
32
+ 144 app/models/invoice.rb
33
+ 144 app/models/widget/address_extractor.rb
34
+ 143 spec/models/invoice_presenter_spec.rb
35
+ 143 app/helpers/html_helper.rb
36
+ 141 config/routes.rb
37
+ 141 app/controllers/people/people_controller.rb
38
+ 138 spec/models/person_spec.rb
39
+ 138 spec/models/xaction_spec.rb
40
+ 137 app/controllers/welcome_controller.rb
41
+ 135 app/views/invoices/show.html.haml
42
+ 132 spec/support/factory.rb
43
+ 131 app/models/person.rb
44
+ 129 public/javascripts/application.js
45
+
46
+ ### distribution ###
47
+ 0 lines 10 **********
48
+ 1 lines 13 *************
49
+ 5 lines 29 *****************************
50
+ 6 lines 44 ********************************************
51
+ 10 lines 55 **********************************************************
52
+ 11 lines 33 *********************************
53
+ 15 lines 27 ***************************
54
+ 16 lines 27 ***************************
55
+ 20 lines 35 *************************
56
+ 21 lines 29 ********************
57
+ 25 lines 16 ****************
58
+ 26 lines 15 ***************
59
+ 30 lines 15 ***************
60
+ 31 lines 16 ****************
61
+ 35 lines 12 ************
62
+ 36 lines 13 *************
63
+ 40 lines 9 *********
64
+ 41 lines 11 ***********
65
+ 45 lines 9 *********
66
+ 46 lines 11 ***********
67
+ 50 lines 5 *****
68
+ 51 lines 8 ********
69
+ 52 lines 2 **
70
+ 53 lines 8 ********
71
+ 54 lines 9 *********
72
+ 55 lines 4 ****
73
+ 56 lines 5 *****
74
+ 69 lines 3 ***
75
+ 71 lines 1 *
76
+ 80 lines 2 **
77
+ 95 lines 1 *
78
+ 128 lines 1 *
79
+
80
+
81
+ You can also run any of :
82
+
83
+ $ loco js
84
+ # => shows stats for .js files in your project
85
+
86
+ $ loco rb
87
+ # => shows stats for .rb files in your project
88
+
89
+ $ loco haml
90
+ # => shows stats for .haml files in your project
91
+
92
+ $ loco views
93
+ # => shows stats for files in your project under app/views/
94
+
95
+ $ loco spec
96
+ # => shows stats for files in your project under spec/
97
+
98
+ $ loco empty
99
+ # => shows stats for empty files in your project (same as loco size 0)
100
+
101
+ $ loco size 8
102
+ # => shows stats for project files that are 8 lines long
103
+
104
+
105
+ ## Contributing
106
+
107
+ 1. Fork it
108
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
109
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
110
+ 4. Push to the branch (`git push origin my-new-feature`)
111
+ 5. Create new Pull Request
112
+
113
+
114
+ ## License
115
+
116
+ Loco is released under the MIT license.
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ lib_path = File.join(File.dirname(File.dirname(__FILE__)), "lib")
5
+ $LOAD_PATH.unshift(lib_path)
6
+
7
+ require "loco"
8
+
9
+ settings = "./.loco"
10
+ load settings if File.exist?(settings)
11
+
12
+ patterns = {
13
+ :all => { :pattern => /.*/ },
14
+ :js => { :pattern => /.*\.js$/ },
15
+ :rb => { :pattern => /.*\.rb$/ },
16
+ :haml => { :pattern => /.*\.haml$/ },
17
+ :views => { :pattern => /^app\/views\// },
18
+ :app => { :pattern => /^app\// },
19
+ :models => { :pattern => /^app\/models\// },
20
+ :migrations=> { :pattern => /^db\/migrate\// },
21
+ :spec => { :pattern => /^spec\// },
22
+ :empty => { :pattern => /.*/, :size => 0 },
23
+ :size => { :pattern => /.*/, :size => ARGV[1].to_i }
24
+ }
25
+
26
+ help = {
27
+ :all => "show loc for all files",
28
+ :js => "show loc for all .js files",
29
+ :rb => "show loc for all .rb files",
30
+ :haml => "show loc for all .haml files",
31
+ :views => "show loc for all app/views files",
32
+ :app => "show loc for all app/** files",
33
+ :models => "show loc for all app/models/** files",
34
+ :migrations => "show loc for all db/migrate/** files",
35
+ :spec => "show loc for all spec/** files",
36
+ :empty => "show details for empty files",
37
+ :size => "show details for files of length specified by ENV['SIZE']",
38
+ :help => "show this help"
39
+ }
40
+
41
+ command = (ARGV[0] || "all").to_sym
42
+ Loco::Counter.new.analyse_loc patterns[command]
43
+
@@ -1,4 +1,7 @@
1
1
  require "loco/version"
2
+ require "loco/util"
3
+ require "loco/stats"
4
+ require "loco/counter"
2
5
 
3
6
  module Loco
4
7
  require 'loco/railtie' if defined?(Rails)
@@ -0,0 +1,90 @@
1
+ module Loco
2
+ class Counter
3
+ include Loco::Util
4
+
5
+ EXCLUDE = [
6
+ /\.sqlite3/,
7
+ /\.gem/,
8
+ /^db\/schema.rb/,
9
+ /^db\/backups/,
10
+ /^db\/migrate/,
11
+ /^vendor/,
12
+ /^public\/system/,
13
+ /^public\/images/,
14
+ /^public\/stylesheets/,
15
+ /^config\/newrelic.yml/,
16
+ /^tmp/,
17
+ /^coverage/,
18
+ /^log/,
19
+ /^doc/,
20
+ /^script/,
21
+ /^stories/,
22
+ /^static/,
23
+ /^public\/fonts/,
24
+ /\.#.+/,
25
+ /\.png/,
26
+ /\.pdf/,
27
+ /\.ico/,
28
+ /lib\/tasks\/.+\.txt/,
29
+ /^README/,
30
+ /^Gemfile.lock/,
31
+ /^public\/javascripts\/jquery/
32
+ ]
33
+
34
+ def exclude? path
35
+ EXCLUDE.each { |regex|
36
+ if path =~ regex
37
+ return true
38
+ end
39
+ }
40
+ false
41
+ end
42
+
43
+ def analyse_loc opts={ }
44
+ regexp = opts[:pattern]
45
+ @stats = []
46
+ @exts = Hash.new { |h, k| h[k] = 0 }
47
+ @ext_lines = Hash.new { |h, k| h[k] = 0 }
48
+ @sizes = Hash.new { |h, k| h[k] = [] }
49
+ total_lines = 0
50
+
51
+ here = File.expand_path "."
52
+ Dir.glob("#{here}/**/*").each do |full_path|
53
+ unless File.stat(full_path).directory?
54
+ path = full_path.sub("#{here}/", '')
55
+ unless exclude?(path) || !regexp.match(path)
56
+ s = Stats.new(path)
57
+ if s.matches(opts)
58
+ @stats << s
59
+ @exts[File.extname(path)] += 1
60
+ @ext_lines[File.extname(path)] += s.lines
61
+ @sizes[s.lines] << path
62
+ total_lines += s.lines
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ puts "\n### extensions ###"
69
+ @exts.each { |ext, count| puts "#{align ext} - #{align count} files, #{align @ext_lines[ext]} lines"}
70
+
71
+ puts "\n### distribution ###"
72
+ @sizes = @sizes.to_a.sort { |a, b|
73
+ a[0] <=> b[0]
74
+ }
75
+
76
+ @sizes.each { |size, files|
77
+ puts "#{align size} lines #{align files.size} #{"*" * files.size}"
78
+ }
79
+
80
+ total = @stats.size
81
+ @stats = @stats.sort { |a, b| b.lines <=> a.lines }
82
+ @stats = @stats[0..50] if @stats.size > 50
83
+
84
+ puts "\n### longest files ###"
85
+ @stats.each { |s| puts s }
86
+
87
+ puts "\n### Total #{regexp.inspect} : #{total} files, #{total_lines} lines, #{"%.3f" % (1.0 * total_lines / total)} avg loc per file ###"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Loco
4
+ class Stats
5
+ include Loco::Util
6
+
7
+ attr_accessor :path, :lines
8
+
9
+ def initialize(path)
10
+ @path = path
11
+ @lines = count_lines(path)
12
+ end
13
+
14
+ def blank? str
15
+ str.nil? || str.strip == ""
16
+ end
17
+
18
+ def count_lines path
19
+ File.read(path).split(/\n/).inject(0) {|sum, line| sum + (blank?(line) ? 0 : 1) }
20
+ rescue Exception => e
21
+ puts "ERROR: reading #{path}: #{e.message}"
22
+ puts ""
23
+ puts "consider adding this line to your .loco:"
24
+ puts ""
25
+ puts "Loco::Counter::EXCLUDE << /^#{path.gsub /\//, "\\/"}/"
26
+ puts ""
27
+ 0
28
+ end
29
+
30
+ def to_s
31
+ "#{align lines} #{path}"
32
+ end
33
+
34
+ def matches options
35
+ options[:size].nil? || (options[:size] == lines)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module Loco
2
+ module Util
3
+ def align x
4
+ x.to_s.rjust(8, " ")
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Loco
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-28 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Count lines of code in project files, excluding a bunch of common
15
15
  defaults, and show (a) for each N, how many files have N lines of code; (b) how
@@ -17,18 +17,22 @@ description: ! 'Count lines of code in project files, excluding a bunch of commo
17
17
  and their length '
18
18
  email:
19
19
  - conan@conandalton.net
20
- executables: []
20
+ executables:
21
+ - loco
21
22
  extensions: []
22
23
  extra_rdoc_files: []
23
24
  files:
24
25
  - .gitignore
25
26
  - Gemfile
26
- - README.txt
27
+ - README.md
27
28
  - Rakefile
29
+ - bin/loco
28
30
  - lib/loco.rb
31
+ - lib/loco/counter.rb
29
32
  - lib/loco/railtie.rb
33
+ - lib/loco/stats.rb
34
+ - lib/loco/util.rb
30
35
  - lib/loco/version.rb
31
- - lib/tasks/loco.rake
32
36
  - loco.gemspec
33
37
  homepage: https://github.com/conanite/loco
34
38
  licenses: []
data/README.txt DELETED
@@ -1,68 +0,0 @@
1
-
2
- rake loco
3
-
4
- will produce something like this:
5
-
6
- ### longest files ###
7
- 145 public/javascripts/validations.js
8
- 145 spec/models/invoice_spec.rb
9
- 144 app/models/widget/stage.rb
10
- 144 app/models/invoice.rb
11
- 144 app/models/widget/address_extractor.rb
12
- 143 spec/models/invoice_presenter_spec.rb
13
- 143 app/helpers/html_helper.rb
14
- 141 config/routes.rb
15
- 141 app/controllers/people/people_controller.rb
16
- 138 spec/models/person_spec.rb
17
- 138 spec/models/xaction_spec.rb
18
- 137 app/controllers/welcome_controller.rb
19
- 135 app/views/invoices/show.html.haml
20
- 132 spec/support/factory.rb
21
- 131 app/models/person.rb
22
- 129 public/javascripts/application.js
23
-
24
- ### distribution ###
25
- 0 lines 10 **********
26
- 1 lines 13 *************
27
- 5 lines 29 *****************************
28
- 6 lines 44 ********************************************
29
- 10 lines 55 **********************************************************
30
- 11 lines 33 *********************************
31
- 15 lines 27 ***************************
32
- 16 lines 27 ***************************
33
- 20 lines 35 *************************
34
- 21 lines 29 ********************
35
- 25 lines 16 ****************
36
- 26 lines 15 ***************
37
- 30 lines 15 ***************
38
- 31 lines 16 ****************
39
- 35 lines 12 ************
40
- 36 lines 13 *************
41
- 40 lines 9 *********
42
- 41 lines 11 ***********
43
- 45 lines 9 *********
44
- 46 lines 11 ***********
45
- 50 lines 5 *****
46
- 51 lines 8 ********
47
- 52 lines 2 **
48
- 53 lines 8 ********
49
- 54 lines 9 *********
50
- 55 lines 4 ****
51
- 56 lines 5 *****
52
- 69 lines 3 ***
53
- 71 lines 1 *
54
- 80 lines 2 **
55
- 95 lines 1 *
56
- 128 lines 1 *
57
-
58
- ### extensions ###
59
- .rb - 791 files, 25907 lines
60
- .haml - 391 files, 6938 lines
61
- .yml - 173 files, 7512 lines
62
- .rake - 8 files, 383 lines
63
- .html - 4 files, 179 lines
64
- .js - 14 files, 840 lines
65
-
66
- == License
67
-
68
- Loco is released under the MIT license.
@@ -1,143 +0,0 @@
1
- namespace :loco do
2
- @exclude = [
3
- /^db\/schema.rb/,
4
- /^db\/backups/,
5
- /^db\/migrate/,
6
- /^vendor/,
7
- /^public\/system/,
8
- /^public\/images/,
9
- /^public\/stylesheets/,
10
- /^config\/newrelic.yml/,
11
- /^tmp/,
12
- /^coverage/,
13
- /^log/,
14
- /^doc/,
15
- /^script/,
16
- /^stories/,
17
- /^static/,
18
- /^public\/fonts/,
19
- /\.#.+/,
20
- /\.png/,
21
- /\.pdf/,
22
- /\.ico/,
23
- /lib\/tasks\/.+\.txt/,
24
- /^README/,
25
- /^Gemfile.lock/,
26
- /^public\/javascripts\/jquery/
27
- ]
28
-
29
- def exclude? path
30
- @exclude.each { |regex|
31
- if path =~ regex
32
- return true
33
- end
34
- }
35
- false
36
- end
37
-
38
- def align x
39
- x.to_s.rjust(8, " ")
40
- end
41
-
42
- class Stats
43
- attr_accessor :path, :lines
44
- def initialize(path)
45
- @path = path
46
- @lines = count_lines(path)
47
- end
48
-
49
- def count_lines path
50
- File.read(path).split(/\n/).inject(0) {|sum, line| sum + (line.blank? ? 0 : 1) }
51
- end
52
-
53
- def to_s
54
- "#{align lines} #{path}"
55
- end
56
-
57
- def matches options
58
- options[:size].blank? || (options[:size] == lines)
59
- end
60
- end
61
-
62
- def analyse_loc regexp, opts={ }
63
- @stats = []
64
- @exts = Hash.new { |h, k| h[k] = 0 }
65
- @ext_lines = Hash.new { |h, k| h[k] = 0 }
66
- @sizes = Hash.new { |h, k| h[k] = [] }
67
- total_lines = 0
68
-
69
- Dir.glob("#{Rails.root}/**/*").each do |full_path|
70
- unless File.stat(full_path).directory?
71
- path = full_path.sub(Rails.root.to_s + "/", '')
72
- unless exclude?(path) || !regexp.match(path)
73
- s = Stats.new(path)
74
- if s.matches(opts)
75
- @stats << s
76
- @exts[File.extname(path)] += 1
77
- @ext_lines[File.extname(path)] += s.lines
78
- @sizes[s.lines] << path
79
- total_lines += s.lines
80
- end
81
- end
82
- end
83
- end
84
-
85
- puts "\n### extensions ###"
86
- @exts.each { |ext, count| puts "#{align ext} - #{align count} files, #{align @ext_lines[ext]} lines"}
87
-
88
- puts "\n### distribution ###"
89
- @sizes = @sizes.to_a.sort { |a, b|
90
- a[0] <=> b[0]
91
- }
92
-
93
- @sizes.each { |size, files|
94
- puts "#{align size} lines #{align files.size} #{"*" * files.size}"
95
- }
96
-
97
- total = @stats.size
98
- @stats = @stats.sort { |a, b| b.lines <=> a.lines }
99
- @stats = @stats[0..50] if @stats.size > 50
100
-
101
- puts "\n### longest files ###"
102
- @stats.each { |s| puts s }
103
-
104
- puts "\n### Total #{regexp.inspect} : #{total} files, #{total_lines} lines, #{"%.3f" % (1.0 * total_lines / total)} avg loc per file ###"
105
- end
106
-
107
- desc "show loc for all files"
108
- task(:all) { analyse_loc /.*/ }
109
-
110
- desc "show loc for all .js files"
111
- task(:js) { analyse_loc /.*\.js$/ }
112
-
113
- desc "show loc for all .rb files"
114
- task(:rb) { analyse_loc /.*\.rb$/ }
115
-
116
- desc "show loc for all .haml files"
117
- task(:haml) { analyse_loc /.*\.haml$/ }
118
-
119
- desc "show loc for all app/views files"
120
- task(:views) { analyse_loc /^app\/views\// }
121
-
122
- desc "show loc for all app/** files"
123
- task(:app) { analyse_loc /^app\// }
124
-
125
- desc "show loc for all app/models/** files"
126
- task(:models) { analyse_loc /^app\/models\// }
127
-
128
- desc "show loc for all db/migrate/** files"
129
- task(:migrations) { analyse_loc /^db\/migrate\// }
130
-
131
- desc "show loc for all spec/** files"
132
- task(:spec) { analyse_loc /^spec\// }
133
-
134
- desc "show details for empty files"
135
- task(:empty) { analyse_loc /.*/, :size => 0 }
136
-
137
- desc "show details for files of length specified by ENV['SIZE']"
138
- task(:size) { analyse_loc /.*/, :size => ENV['SIZE'].to_i }
139
- end
140
-
141
- task :loco => "loco:all"
142
-
143
-