quality 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 619cb08a5ce09129ca03e5cb3b6a04c927e35c03
4
+ data.tar.gz: 3ec8da62bbba3f08de40e56649ab94af6d8e00da
5
+ SHA512:
6
+ metadata.gz: 04a2137f381c27549507c9772842b5025715ed5f7ee298d4743392e23396bf2d306ad183ba52049c4567ecd3fc7898210c8e02d69fab1039437ecbfe9e39e8ae
7
+ data.tar.gz: 904af73ba671ee5f9752e922490c569ab061959908a3705cfbbe14ae4cfd087ee8421364decc7f74e61de2f87c0c2fa35c122d16b8cc0011b857c691d1925e65
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Vincent Broz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ require 'rake/clean'
2
+ require "bundler/gem_tasks"
3
+
4
+ $:.unshift File.dirname(__FILE__) + '/lib'
5
+
6
+ PROJECT_NAME = 'quality'
7
+
8
+ BUILD_DIR = 'build'; directory BUILD_DIR
9
+ PKG_DIR = "#{BUILD_DIR}/pkg"; directory PKG_DIR
10
+
11
+ GEM_MANIFEST = "Manifest.txt"
12
+ VERSION_FILE = 'lib/quality.rb'
13
+
14
+ CLOBBER.include("#{BUILD_DIR}/*")
15
+
16
+ Dir['tasks/**/*.rake'].each { |t| load t }
17
+
18
+ task :default => [:test]
19
+
@@ -0,0 +1,195 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake'
4
+ require 'rake/tasklib'
5
+
6
+ module Quality
7
+
8
+ #
9
+ # Defines a task library for running quality's various tools
10
+ # (Classes here will be configured via the Rakefile, and therefore will
11
+ # possess a :reek:attribute or two.)
12
+ #
13
+ module Rake
14
+
15
+ # A Rake task that run quality tools on a set of source files, and
16
+ # enforce a ratcheting quality level.
17
+ #
18
+ # Example:
19
+ #
20
+ # require 'quality/rake/task'
21
+ #
22
+ # Quality::Rake::Task.new do |t|
23
+ # end
24
+ #
25
+ # This will create a task that can be run with:
26
+ #
27
+ # rake quality
28
+ #
29
+ class Task < ::Rake::TaskLib
30
+
31
+ # Name of reek task.
32
+ # Defaults to :reek.
33
+ attr_accessor :name
34
+
35
+ # Array of directories to be added to $LOAD_PATH before running reek.
36
+ # Defaults to ['<the absolute path to reek's lib directory>']
37
+ attr_accessor :libs
38
+
39
+ # Use verbose output. If this is set to true, the task will print
40
+ # the reek command to stdout. Defaults to false.
41
+ attr_accessor :verbose
42
+
43
+ # Defines a new task, using the name +name+.
44
+ def initialize(name = :quality)
45
+ @name = name
46
+ @libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
47
+ @config_files = nil
48
+ @source_files = nil
49
+ @ruby_opts = []
50
+ @reek_opts = ''
51
+ @fail_on_error = true
52
+ @sort = nil
53
+
54
+ yield self if block_given?
55
+ @config_files ||= 'config/**/*.reek'
56
+ @source_files ||= 'lib/**/*.rb'
57
+ define
58
+ end
59
+
60
+ private
61
+
62
+ def define # :nodoc:
63
+ desc 'Verify quality has increased or stayed' +
64
+ 'the same' unless ::Rake.application.last_comment
65
+ task(name) { run_task }
66
+ self
67
+ end
68
+
69
+ def run_task
70
+ quality_cane
71
+ quality_reek
72
+ quality_flog
73
+ quality_flay
74
+ end
75
+
76
+ def quality_quality_cmd(cmd,
77
+ args: nil,
78
+ emacs_format: false,
79
+ &process_output_line)
80
+ violations = 0
81
+ out = ""
82
+ found_output = false
83
+ full_cmd = cmd
84
+ if !args.nil?
85
+ full_cmd = "#{cmd} #{args}"
86
+ end
87
+ IO.popen(full_cmd) do |f|
88
+ while line = f.gets
89
+ if emacs_format
90
+ if line =~ /^ *(\S*.rb:[0-9]*) *(.*)/
91
+ out << $1 << ": " << $2 << "\n"
92
+ elsif line =~ /^ *(.*) +(\S*.rb:[0-9]*) *(.*)/
93
+ out << $2 << ": " << $1 << "\n"
94
+ else
95
+ out << line
96
+ end
97
+ else
98
+ out << line
99
+ end
100
+ found_output = true
101
+ violations += yield line
102
+ end
103
+ end
104
+ exit_status = $?.exitstatus
105
+ if !found_output
106
+ fail "#{full_cmd} execution failed! Exit status is #{exit_status}"
107
+ end
108
+ filename = "#{cmd}_high_water_mark"
109
+ if File.exist?(filename)
110
+ existing_violations = IO.read(filename).to_i
111
+ else
112
+ existing_violations = 9999999999
113
+ end
114
+ puts "Existing violations: #{existing_violations}"
115
+ puts "Found #{violations} #{cmd} violations"
116
+ if violations > existing_violations
117
+ fail "Output from #{cmd}\n\n#{out}\n\n" +
118
+ "Reduce total number of #{cmd} violations to #{existing_violations} or below!"
119
+ elsif violations < existing_violations
120
+ puts "Ratcheting quality up..."
121
+ File.open(filename, 'w') {|f| f.write(violations.to_s) }
122
+ end
123
+ end
124
+
125
+ def quality_cane
126
+ quality_quality_cmd("cane",
127
+ emacs_format: true) { |line|
128
+ if line =~ /\(([0-9]*)\):$/
129
+ $1.to_i
130
+ else
131
+ 0
132
+ end
133
+ }
134
+ end
135
+
136
+ def quality_reek
137
+ quality_quality_cmd("reek",
138
+ args: "--line-number *.rb lib/*.rb 2>/dev/null",
139
+ emacs_format: true) { |line|
140
+ if line =~ /^ .* (.*)$/
141
+ 1
142
+ else
143
+ 0
144
+ end
145
+ }
146
+ end
147
+
148
+ def quality_flog
149
+ threshold = 50
150
+ quality_quality_cmd("flog",
151
+ args: "--all --continue --methods-only . 2>/dev/null",
152
+ emacs_format: true) { |line|
153
+ if line =~ /^ *([0-9.]*): flog total$/
154
+ 0
155
+ #$1.to_i
156
+ elsif line =~ /^ *([0-9.]*): (.*) .\/.*.rb:[0-9]*$/
157
+ score = $1.to_i
158
+ if score > threshold
159
+ 1
160
+ else
161
+ 0
162
+ end
163
+ else
164
+ 0
165
+ end
166
+ }
167
+ end
168
+
169
+ def quality_flay
170
+ quality_quality_cmd("flay",
171
+ args: "-t 99999 . 2>/dev/null",
172
+ emacs_format: true) { |line|
173
+ if line =~ /^[0-9]*\).* \(mass = ([0-9]*)\)$/
174
+ $1.to_i
175
+ else
176
+ 0
177
+ end
178
+ }
179
+ end
180
+
181
+ def quality
182
+ Dir.glob("*_high_water_mark").each { |filename|
183
+ puts "Processing #{filename}"
184
+ existing_violations = IO.read(filename).to_i
185
+ if existing_violations <= 0
186
+ raise "Problem with file #{filename}"
187
+ end
188
+ new_violations = existing_violations - 1
189
+ File.open(filename, 'w') {|f| f.write(new_violations.to_s) }
190
+ system("git commit -m 'tighten quality standard' #{filename}")
191
+ }
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,3 @@
1
+ module Quality
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.join(File.dirname(__FILE__), "lib")
3
+ require 'quality/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{quality}
7
+ s.version = Quality::VERSION
8
+
9
+ s.authors = ['Vince Broz']
10
+ #s.default_executable = %q{quality}
11
+ s.description = %q{Quality is a tool that runs quality checks on Ruby
12
+ code using cane, reek, flog and flay, and makes sure
13
+ your numbers don't get any worse over time.
14
+ }
15
+ s.email = ["vince@broz.cc"]
16
+ #s.executables = ["quality"]
17
+ #s.extra_rdoc_files = ["CHANGELOG", "License.txt"]
18
+ s.files = Dir["License.txt", "README.md",
19
+ "Rakefile",
20
+ #"bin/quality",
21
+ "{lib}/**/*",
22
+ "quality.gemspec" ] & `git ls-files -z`.split("\0")
23
+ #s.rdoc_options = ["--main", "README.md"]
24
+ s.require_paths = ["lib"]
25
+ #s.rubyforge_project = %q{quality}
26
+ s.rubygems_version = %q{1.3.6}
27
+ s.summary = %q{Code quality tools for Ruby}
28
+
29
+ s.add_runtime_dependency(%q<cane>, [">= 2.6"])
30
+ s.add_runtime_dependency(%q<reek>, [">= 1.3.1"])
31
+ s.add_runtime_dependency(%q<flog>, [">= 4.1.1"])
32
+ s.add_runtime_dependency(%q<flay>, [">= 2.4"])
33
+
34
+ s.add_development_dependency(%q<bundler>, [">= 1.1"])
35
+ s.add_development_dependency(%q<rake>)
36
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quality
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vince Broz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cane
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: reek
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: flog
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: flay
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '2.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: "Quality is a tool that runs quality checks on Ruby\ncode using cane,
98
+ reek, flog and flay, and makes sure \nyour numbers don't get any worse over time.\n"
99
+ email:
100
+ - vince@broz.cc
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - License.txt
106
+ - Rakefile
107
+ - lib/quality/rake/task.rb
108
+ - lib/quality/version.rb
109
+ - quality.gemspec
110
+ homepage:
111
+ licenses: []
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.0.6
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Code quality tools for Ruby
133
+ test_files: []