Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add devtools #10

Merged
merged 20 commits into from
May 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 2 additions & 61 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,7 @@ source 'https://rubygems.org'
gemspec

group :development do
gem 'rake', '~> 10.0.4'
gem 'rspec', '~> 1.3.2'
gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
end

group :yard do
gem 'kramdown', '~> 1.0.1'
end

group :guard do
gem 'guard', '~> 1.7.0'
gem 'guard-bundler', '~> 1.0.0'
gem 'guard-rspec', '~> 1.2.1'

# file system change event handling
gem 'listen', '~> 0.7.3'
gem 'rb-fchange', '~> 0.0.6', :require => false
gem 'rb-fsevent', '~> 0.9.3', :require => false
gem 'rb-inotify', '~> 0.9.0', :require => false

# notification handling
gem 'libnotify', '~> 0.8.0', :require => false
gem 'rb-notifu', '~> 0.0.4', :require => false
gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
end

group :metrics do
gem 'coveralls', '~> 0.6.5'
gem 'flay', '~> 1.4.3'
gem 'flog', '~> 2.5.3'
gem 'roodi', '~> 2.2.0'
gem 'simplecov', '~> 0.7.1'

platforms :ruby_19 do
gem 'yard-spellcheck', '~> 0.1.5'
end

platforms :mri_18 do
gem 'arrayfields', '~> 4.7.4' # for metric_fu
gem 'fattr', '~> 2.2.0' # for metric_fu
gem 'heckle', '~> 1.4.3'
gem 'json', '~> 1.7.7' # for metric_fu rake task
gem 'map', '~> 6.3.0' # for metric_fu
gem 'metric_fu', '~> 2.1.1'
gem 'mspec', '~> 1.5.17'
gem 'rails_best_practices', '= 1.13.3' # for metric_fu
gem 'rcov', '~> 1.0.0'
gem 'ruby2ruby', '= 1.2.2' # for heckle
end

platforms :rbx do
gem 'pelusa', '~> 0.2.2'
end
end

group :benchmarks do
gem 'rbench', '~> 0.2.3'
end

platform :jruby do
group :jruby do
gem 'jruby-openssl', '~> 0.8.5'
end
end
eval File.read('Gemfile.devtools')
59 changes: 59 additions & 0 deletions Gemfile.devtools
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# encoding: utf-8

group :development do
gem 'rake', '~> 10.0.4'
gem 'rspec', '~> 2.13.0'
gem 'yard', '~> 0.8.6.1'
end

group :yard do
gem 'kramdown', '~> 1.0.1'
end

group :guard do
gem 'guard', '~> 1.8.0'
gem 'guard-bundler', '~> 1.0.0'
gem 'guard-rspec', '~> 2.5.4'

# file system change event handling
gem 'listen', '~> 1.0.2'
gem 'rb-fchange', '~> 0.0.6', :require => false
gem 'rb-fsevent', '~> 0.9.3', :require => false
gem 'rb-inotify', '~> 0.9.0', :require => false

# notification handling
gem 'libnotify', '~> 0.8.0', :require => false
gem 'rb-notifu', '~> 0.0.4', :require => false
gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
end

group :metrics do
gem 'backports', '~> 3.3', '>= 3.3.0'
gem 'coveralls', '~> 0.6.6'
gem 'flay', '~> 2.2.0'
gem 'flog', '~> 4.0.0'
gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
gem 'simplecov', '~> 0.7.1'

platforms :ruby_19 do
gem 'yard-spellcheck', '~> 0.1.5'
end

platforms :mri_19, :rbx do
gem 'mutant', '~> 0.2.20'
end

platforms :rbx do
gem 'pelusa', '~> 0.2.2'
end
end

group :benchmarks do
gem 'rbench', '~> 0.2.3'
end

platform :jruby do
group :jruby do
gem 'jruby-openssl', '~> 0.8.5'
end
end
9 changes: 2 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# encoding: utf-8

require 'rake'

require File.expand_path('../lib/yardstick/version', __FILE__)

FileList['tasks/**/*.rake'].each { |task| import task }

task :default => :spec
require 'devtools'
Devtools.init_rake_tasks
2 changes: 2 additions & 0 deletions config/devtools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
unit_test_timeout: 0.3
4 changes: 2 additions & 2 deletions config/flay.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
threshold: 15
total_score: 246
threshold: 12
total_score: 155
2 changes: 1 addition & 1 deletion config/flog.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
threshold: 13.1
threshold: 11.4
3 changes: 3 additions & 0 deletions config/mutant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
name: yardstick
namespace: Yardstick
46 changes: 28 additions & 18 deletions config/site.reek → config/reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ Attribute:
exclude:
- Yardstick::Config
- Yardstick::Rule
- Yardstick::Document
BooleanParameter:
enabled: true
exclude: []
ClassVariable:
enabled: true
exclude: []
ControlCouple:
ControlParameter:
enabled: true
exclude: []
DataClump:
enabled: true
exclude: []
max_copies: 2
min_clump_size: 2
Duplication:
DuplicateMethodCall:
enabled: true
exclude: []
max_calls: 1
Expand All @@ -29,21 +30,6 @@ FeatureEnvy:
IrresponsibleModule:
enabled: true
exclude: []
LargeClass:
enabled: true
exclude:
- Yardstick::Document
- Yardstick::Config
max_instance_variables: 3
max_methods: 10
LongMethod:
enabled: true
exclude:
- Yardstick::CLI#self.option_parser
- Yardstick::CLI#self.parse_config
- Yardstick::Config#self.normalize_hash
- Yardstick::Config#set_defaults
max_statements: 3
LongParameterList:
enabled: true
exclude: []
Expand All @@ -60,10 +46,31 @@ NestedIterators:
exclude: []
max_allowed_nesting: 1
ignore_iterators: []
SimulatedPolymorphism:
NilCheck:
enabled: true
exclude: []
RepeatedConditional:
enabled: true
exclude: []
max_ifs: 1
TooManyInstanceVariables:
enabled: true
exclude:
- Yardstick::Config
max_instance_variables: 3
TooManyMethods:
enabled: true
exclude:
- Yardstick::Document
max_methods: 10
TooManyStatements:
enabled: true
exclude:
- Yardstick::CLI#self.option_parser
- Yardstick::CLI#self.parse_config
- Yardstick::Config#set_defaults
- Yardstick::Config#self.normalize_hash
max_statements: 3
UncommunicativeMethodName:
enabled: true
exclude: []
Expand Down Expand Up @@ -95,6 +102,9 @@ UncommunicativeVariableName:
- !ruby/regexp /[0-9]$/
- !ruby/regexp /[A-Z]/
accept: []
UnusedParameters:
enabled: true
exclude: []
UtilityFunction:
enabled: true
exclude: []
Expand Down
6 changes: 4 additions & 2 deletions lib/yardstick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
require 'yardstick/rules/return_tag'

require 'yardstick/measurement_set'
require 'yardstick/document_set'
require 'yardstick/processor'
require 'yardstick/parser'

require 'yardstick/yard_ext'

Expand All @@ -45,7 +47,7 @@ module Yardstick
#
# @api public
def self.measure(config = Config.new)
Processor.process_path(config)
Processor.new(config).process
end

# Measure a string of code and YARD documentation
Expand All @@ -65,7 +67,7 @@ def self.measure(config = Config.new)
#
# @api public
def self.measure_string(string, config = Config.new)
Processor.process_string(string, config)
Processor.new(config).process_string(string)
end

end # module Yardstick
4 changes: 2 additions & 2 deletions lib/yardstick/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def self.parse_config(args)

# Return an OptionParser instance for the command-line app
#
# @param [Hash] options
# @param [Hash] _options
# the options to set when parsing the command-line arguments
#
# @return [Yardstick::OptionParser]
# the option parser instance
#
# @api private
def self.option_parser(options)
def self.option_parser(_options)
opts = OptionParser.new
opts.on_tail('-v', '--version', 'print version information and exit') { display_exit("#{opts.program_name} #{Yardstick::VERSION}") }
opts.on_tail('-h', '--help', 'display this help and exit') { display_exit(opts.to_s) }
Expand Down
34 changes: 21 additions & 13 deletions lib/yardstick/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Yardstick
# Handles Yardstick configuration
#
class Config
InvalidRule = Class.new(StandardError)

NAMESPACE_PREFIX = 'Yardstick::Rules::'.freeze

# Set the threshold
Expand Down Expand Up @@ -76,10 +78,10 @@ def self.coerce(hash, &block)
#
# @api private
def self.normalize_hash(hash)
hash.each_with_object({}) { |(key, value), normalized_hash|
hash.each_with_object({}) do |(key, value), normalized_hash|
normalized_value = value.is_a?(Hash) ? normalize_hash(value) : value
normalized_hash[key.to_sym] = normalized_value
}
end
end

# Initializes new config
Expand All @@ -94,10 +96,7 @@ def self.normalize_hash(hash)
#
# @api private
def initialize(options = {}, &block)
@options = options
@rules = @options.fetch(:rules, {})

set_defaults
set_defaults(options)

yield(self) if block_given?
end
Expand All @@ -110,8 +109,13 @@ def initialize(options = {}, &block)
#
# @api private
def options(rule_class)
key = rule_class.to_s[NAMESPACE_PREFIX.length..-1].to_sym
@rules.fetch(key, {})
key = rule_class.to_s[NAMESPACE_PREFIX.length..-1]

if key
@rules.fetch(key.to_sym, {})
else
raise InvalidRule, "every rule must begin with #{NAMESPACE_PREFIX}"
end
end

# Specify if the coverage summary should be displayed
Expand Down Expand Up @@ -148,14 +152,18 @@ def output=(output)

# Sets default options
#
# @param [Hash] options
# optional configuration
#
# @return [undefined]
#
# @api private
def set_defaults
@threshold = @options[:threshold]
@verbose = true
@path = @options[:path] || 'lib/**/*.rb'
@require_exact_threshold = true
def set_defaults(options)
@threshold = options.fetch(:threshold, 100)
@verbose = options.fetch(:verbose, true)
@path = options.fetch(:path, 'lib/**/*.rb')
@require_exact_threshold = options.fetch(:require_exact_threshold, true)
@rules = options.fetch(:rules, {})
self.output = 'measurements/report.txt'
end

Expand Down
Loading