commentval 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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +20 -0
  4. data/bin/commentval +5 -0
  5. data/lib/commentval.rb +56 -0
  6. metadata +64 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2abf50dc0dfd5babdc920bd41f910a2485fd9b93
4
+ data.tar.gz: beb3c88cb6c2ea27ebd7d3ea7a64db414a7d8861
5
+ SHA512:
6
+ metadata.gz: 6b11798058f3168819bd92c648c56cf1586842a73b04d256c504b44df57aa1927cd6c1a37ef8ce740065563031416cde068eed9cfe62225de10d3bbb6182db90
7
+ data.tar.gz: 2d3c5286083d3d39f70942ef81fceee570df341886fe665c4a7c695013c0d69d3abf39f5a7f895aa9ce3d9b50f066e9486a74f92f5d0a44be135d03668198ed9
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Andrew Moore
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ Comment Validator
2
+ ===========
3
+
4
+ This is a gem which will read the comments from files and check if they meet the targeted percentage.
5
+
6
+ # How to use?
7
+
8
+ ```
9
+ commentval <folders (seperate by comma)> <file extnesions (seperate by comma)> <comment threshold>
10
+ ```
11
+
12
+ Example:
13
+
14
+ ```
15
+ commentval propertyfrontend/ .py 0.9
16
+ ```
17
+
18
+ # How does it check for a comment?
19
+
20
+ It checks if there is either a # or a // in the file. If one of this is found this will count as a comment.
data/bin/commentval ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'commentval.rb'
data/lib/commentval.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'nokogiri'
2
+
3
+ if (ARGV[0].nil?) then
4
+ puts "Error: No Code folder provided"
5
+ exit(1)
6
+ end
7
+
8
+ code_folders = ARGV[0].split(',')
9
+
10
+ if (ARGV[1].nil?) then
11
+ puts "Error: No Code extensions provided"
12
+ exit(1)
13
+ end
14
+
15
+ code_extensions = ARGV[1].split(',')
16
+
17
+ if (ARGV[2].nil?) then
18
+ puts "Error: Coverage target missing"
19
+ exit(1)
20
+ end
21
+
22
+ target = ARGV[2].to_f;
23
+
24
+ files = Array.new();
25
+
26
+ code_folders.each do |filename|
27
+ all_files = Dir[filename + '**/**']
28
+ all_files.each do |filename|
29
+ if (code_extensions.include? File.extname(filename)) then
30
+ files.push(filename)
31
+ end
32
+ end
33
+ end
34
+
35
+ total = 0;
36
+ passed = 0;
37
+
38
+ files.each do |filename|
39
+ File.open(filename, "r") do |file_handle|
40
+ file_handle.each_line do |file_line|
41
+ total = total + 1
42
+ if ((file_line.scan(/#/i).count > 0) || (file_line.scan(/\/\//i).count > 0)) then
43
+ passed = passed + 1
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ actual = (passed.to_f / total.to_f).round(2)
50
+
51
+ if (actual < target) then
52
+ puts "Error: Commenting is below target. Expected: >" + target.to_s + ", Actual: " + actual.to_s
53
+ exit(1)
54
+ end
55
+
56
+ puts "Success: Commenting is at or above target. Expected: >" + target.to_s + ", Actual: " + actual.to_s
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commentval
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Moore
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.15
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.15
27
+ description: This gem will check if there the code has sufficient amount of comments.
28
+ This can be used in tools such as Jenkins to check if the comment meets the expected
29
+ quantity.
30
+ email: mooreandrew@gmail.com
31
+ executables:
32
+ - commentval
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/commentval.rb
37
+ - README.md
38
+ - LICENSE
39
+ - bin/commentval
40
+ homepage: https://github.com/mooreandrew/commentval
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.0.14
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: ''
64
+ test_files: []