gloc 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +89 -16
  3. data/exe/gloc +13 -10
  4. data/lib/gloc/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '03680f8522160a0bd3f6b4f6d2294c9683010dbd'
4
- data.tar.gz: dc7387860aaa9e4737f3953e64ab738c0cfc09ed
3
+ metadata.gz: bb008de5d3e4876e1fdfc917d9c9f8c8b29560c0
4
+ data.tar.gz: a90bd40e3e81f8f5f5a9bd1848d1ac219dac3b1d
5
5
  SHA512:
6
- metadata.gz: f3246c72e55d068e2e2c9e88258ac5425ab8c91dade985c62d7e19d8f84bda4d16032c0c6afc121f52342c25ee2b2b5ba4898a2e26be9504c414db14299e55b9
7
- data.tar.gz: be2f66713645f3318901361da7317034f9e2040ba56123692e2ee2629af2e90c62e08c9d2f921484aa1207d27385c76ce91fd2ed2d046b3100d48fccd5febbb6
6
+ metadata.gz: 329271c34e3ce802253be45beabe866e8747ceaa5705dde7448359248d6a3bfc6071a9f065f00392fed5ece92aed9ec9b67904e02ddd6ef138a20208ec8cf47a
7
+ data.tar.gz: a669b54dd3a4875954ec6002d47e9be98d5fbfcc237b023e44fd34f70cc343921f5d5f8de7361ab2404f6ab0c00323402cd1707c60c90c69b25fed8107df53a5
data/README.md CHANGED
@@ -1,8 +1,60 @@
1
- # Gloc
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gloc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- ## What it is not:
1
+ # Gloc(k) Model 17 - 9mm
2
+
3
+ `gloc` is an opinionated utility to count lines of code.
4
+
5
+ * it groups files based on their file extension, instead of trying to guess their language and grouping them that way
6
+ * it doesn't ignore files just because it doesn't recognise them _(ie. cannot correctly guess their language)_
7
+ * in a git repo, it processes `$( git ls-files )` by default
8
+ * in a non-git repo, it processes `$( find . -type f)` by default
9
+ * it generates human-friendly, `loc`-alike output
10
+ * it is Unix pipeline friendly, by design:
11
+ * it reads the list of filenames to process from `stdin` if `[ ! -t 0 ]`
12
+ * it writes machine-parsable JSON output to `stdout` if `[ ! -t 1 ]`
13
+
14
+ ## Example
15
+
16
+ For the popular Ruby on Rails framework, `gloc` generates the following `loc`-alike output:
17
+
18
+ --------------------------------------------------------------------------------
19
+ Language Files Lines Blank Comment Code
20
+ --------------------------------------------------------------------------------
21
+ *.rb 2,149 304,495 47,846 42,651 213,998
22
+ *.md 74 49,604 14,204 0 35,400
23
+ *.js 39 9,717 1,452 564 7,701
24
+ *.yml 150 3,367 278 0 3,089
25
+ *.erb 408 2,183 254 0 1,929
26
+ * 81 2,255 392 0 1,863
27
+ *.css 24 1,640 214 32 1,394
28
+ *.coffee 24 1,190 197 0 993
29
+ *.rake 16 864 137 0 727
30
+ *.rdoc 11 985 352 0 633
31
+ *.tt 28 515 88 0 427
32
+ *.lock 1 437 11 0 426
33
+ *.yaml 1 231 1 0 230
34
+ *.gemspec 11 306 79 0 227
35
+ *.html 28 225 15 3 207
36
+ *.json 3 65 0 0 65
37
+ *.builder 19 62 2 0 60
38
+ *.y 1 50 4 0 46
39
+ *.sql 1 49 6 0 43
40
+ *.zoo 2 8 0 0 8
41
+ *.ru 2 8 2 0 6
42
+ *.txt 6 6 0 0 6
43
+ *.ruby 2 4 0 0 4
44
+ *.erb~ 4 4 0 0 4
45
+ *.raw 2 2 0 0 2
46
+ *.styles 1 1 0 0 1
47
+ *.log 1 1 0 0 1
48
+ *.dtd 1 1 0 0 1
49
+ *.mab 1 1 0 0 1
50
+ *.javascript 1 1 0 0 1
51
+ --------------------------------------------------------------------------------
52
+ Total 3,092 378,277 65,534 43,250 269,493
53
+ --------------------------------------------------------------------------------
54
+
55
+ ## What It Is Not!
56
+
57
+ For various reasons, none of these existing utilities to count lines of code are fit for _(my)_ purpose:
6
58
 
7
59
  * [cgag/loc](https://github.com/cgag/loc)
8
60
  * [AlDanial/cloc](https://github.com/AlDanial/cloc)
@@ -11,23 +63,45 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
11
63
 
12
64
  ## Installation
13
65
 
14
- Add this line to your application's Gemfile:
66
+ gem install gloc
15
67
 
16
- ```ruby
17
- gem 'gloc'
18
- ```
68
+ ## Usage
19
69
 
20
- And then execute:
70
+ The simplest way to use `gloc` is to simply run:
21
71
 
22
- $ bundle
72
+ gloc
23
73
 
24
- Or install it yourself as:
74
+ It should behave pretty much as you'd expect!
25
75
 
26
- $ gem install gloc
76
+ ### in a git repo
27
77
 
28
- ## Usage
78
+ In a git repo, running `gloc` will process all files known to git, so is roughly equivalent to:
79
+
80
+ git ls-files | gloc
81
+
82
+ ### in a non-git repo
83
+
84
+ In a non-git repo, running `gloc` will process all files in the directory, so is roughly equivalent to:
29
85
 
30
- TODO: Write usage instructions here
86
+ find . -type f | gloc
87
+
88
+ ## Sorting
89
+
90
+ The results are sorted by "lines of code" by default _(with "lines of code" defined as lines that aren't blank or comment-only)_ but the following options are supported to sort the results differently:
91
+
92
+ gloc -files # sort by number of files
93
+ gloc -lines # sort by the total number of lines
94
+ gloc -blank # sort by the number of blank lines
95
+ gloc -comment # sort by the number of comment lines
96
+ gloc -code # sort by lines of code (default)
97
+
98
+ ## Known Issues
99
+
100
+ * identify comment-only lines for a lot more languages
101
+ * support more file encodings (not just `UTF-8` and `ISO-8859-1`)
102
+
103
+ * (?) installation via Homebrew
104
+ * (?) convert script to Perl for performance
31
105
 
32
106
  ## Development
33
107
 
@@ -43,4 +117,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/pvdb/g
43
117
  ## License
44
118
 
45
119
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
-
data/exe/gloc CHANGED
@@ -33,10 +33,11 @@ end
33
33
  # see buffer_is_binary() function
34
34
  source_files.delete_if { |file|
35
35
  (
36
- File.extname(file) == '.pdf' || # skip bl**dy PDF documents
37
- !File.exist?(file) || # skip non-existent paths
38
- !File.file?(file) || # skip directories
39
- !File.size?(file) || # skip empty files
36
+ File.extname(file) == '.pdf' || # skip bl**dy PDF documents
37
+ File.basename(file) =~ /\A\..*\z/ || # skip hidden ".*" files
38
+ !File.exist?(file) || # skip non-existent paths
39
+ !File.file?(file) || # skip directories
40
+ !File.size?(file) || # skip empty files
40
41
  !File.read(file, 16)["\0"].nil? # skip binary files
41
42
  ) && ( $verbose && warn("SKIPPING #{file}...") ; true )
42
43
  }
@@ -64,7 +65,9 @@ source_stats = source_files.each_with_object({}) { |file, stats|
64
65
  comment_count: 0,
65
66
  })
66
67
  end
67
- source_lines = File.read(file).each_line
68
+ file_content = File.read(file, :encoding => 'UTF-8') # FIXME what about other encodings?
69
+ file_content = File.read(file, :encoding => 'ISO-8859-1') unless content.valid_encoding?
70
+ source_lines = file_content.each_line
68
71
  stats_for_ext.file_count += 1
69
72
  stats_for_ext.line_count += source_lines.count
70
73
  stats_for_ext.blank_count += source_lines.grep(BLANKS).count
@@ -94,11 +97,11 @@ source_stats = Hash[
94
97
  ]
95
98
 
96
99
  source_stats["TOTAL"] = OpenStruct.new({
97
- file_count: source_stats.values.map(&:file_count).reduce(:+),
98
- line_count: source_stats.values.map(&:line_count).reduce(:+),
99
- blank_count: source_stats.values.map(&:blank_count).reduce(:+),
100
- comment_count: source_stats.values.map(&:comment_count).reduce(:+),
101
- code_count: source_stats.values.map(&:code_count).reduce(:+),
100
+ file_count: source_stats.values.map(&:file_count).reduce(:+) || 0,
101
+ line_count: source_stats.values.map(&:line_count).reduce(:+) || 0,
102
+ blank_count: source_stats.values.map(&:blank_count).reduce(:+) || 0,
103
+ comment_count: source_stats.values.map(&:comment_count).reduce(:+) || 0,
104
+ code_count: source_stats.values.map(&:code_count).reduce(:+) || 0,
102
105
  })
103
106
 
104
107
  #
@@ -1,3 +1,3 @@
1
1
  module GLOC
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Vandenberk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-30 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler