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

Integrated RuboCop as part of the build. #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AllCops:
Exclude:
- vendor/**/*

inherit_from: .rubocop_todo.yml

Style/AndOr:
EnforcedStyle: conditionals

Style/SignalException:
EnforcedStyle: only_raise

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/AlignHash:
EnforcedHashRocketStyle: table
87 changes: 87 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-11-18 09:55:16 -0500 using RuboCop version 0.35.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 3
Metrics/AbcSize:
Max: 24

# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 106
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 143

# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 20

# Offense count: 4
Metrics/PerceivedComplexity:
Max: 12

# Offense count: 2
Style/AccessorMethodName:
Exclude:
- 'lib/virtus/attribute/accessor.rb'
- 'lib/virtus/support/options.rb'

# Offense count: 2
Style/CaseEquality:
Exclude:
- 'lib/virtus.rb'
- 'lib/virtus/module_extensions.rb'

# Offense count: 15
# Configuration parameters: Exclude.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/virtus.rb'
- 'lib/virtus/attribute/lazy_default.rb'
- 'lib/virtus/class_inclusions.rb'
- 'lib/virtus/const_missing_extensions.rb'
- 'lib/virtus/extensions.rb'
- 'lib/virtus/instance_methods.rb'
- 'lib/virtus/model.rb'
- 'lib/virtus/value_object.rb'
- 'lib/virtus/version.rb'

# Offense count: 3
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/virtus/class_methods.rb'
- 'lib/virtus/instance_methods.rb'
- 'lib/virtus/support/type_lookup.rb'

# Offense count: 1
Style/ModuleFunction:
Exclude:
- 'spec/shared/constants_helpers.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'lib/virtus/module_extensions.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
Style/SpaceInsideHashLiteralBraces:
Enabled: false
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Virtus recently hit it's 1.0 release (2013-10-16). The focus now is on bug-fixes
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
* Run `rubocop -a` to fix any Ruby style issues and re-run `rubocop --auto-gen-config` for any acceptable exceptions.
* Commit, do not mess with Rakefile or version
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.
Expand Down
10 changes: 7 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ gem 'bogus', '~> 0.1'
gem 'inflecto', '~> 0.0.2'
gem 'rspec', '~> 3.1'

gem "codeclimate-test-reporter", group: :test, require: false
group :development, :test do
gem 'rubocop', '0.35.1'
end

group :test do
gem 'codeclimate-test-reporter', :require => false
end

group :tools do
gem 'guard'
gem 'guard-rspec'

gem 'rubocop'

platform :mri do
gem 'mutant'
gem 'mutant-rspec'
Expand Down
4 changes: 2 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
guard :rspec, spec_paths: 'spec/unit' do
#run all specs if configuration is modified
guard :rspec, :spec_paths => 'spec/unit' do
# run all specs if configuration is modified
watch('Guardfile') { 'spec' }
watch('Gemfile.lock') { 'spec' }
watch('spec/spec_helper.rb') { 'spec' }
Expand Down
16 changes: 6 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
require "rspec/core/rake_task"
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
task default: [:spec]
task :default => [:spec]

begin
require "rubocop/rake_task"
require 'rubocop/rake_task'
Rake::Task[:default].enhance [:rubocop]

Rake::Task[:default].enhance [:rubocop]

RuboCop::RakeTask.new do |task|
task.options << "--display-cop-names"
end
rescue LoadError
RuboCop::RakeTask.new do |task|
task.options << '--display-cop-names'
end
9 changes: 4 additions & 5 deletions lib/virtus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

# Base module which adds Attribute API to your classes
module Virtus

# Provides args for const_get and const_defined? to make them behave
# consistently across different versions of ruby
EXTRA_CONST_ARGS = (RUBY_VERSION < '1.9' ? [] : [ false ]).freeze
EXTRA_CONST_ARGS = (RUBY_VERSION < '1.9' ? [] : [false]).freeze

# Represents an undefined parameter used by auto-generated option methods
Undefined = Object.new.freeze
Expand All @@ -14,7 +13,8 @@ class CoercionError < StandardError
attr_reader :output, :attribute

def initialize(output, attribute)
@output, @attribute = output, attribute
@output = output
@attribute = attribute
super(build_message)
end

Expand Down Expand Up @@ -120,7 +120,7 @@ def self.coerce
# @return [Configuration]
#
# @api public
def self.config(&block)
def self.config
yield configuration if block_given?
configuration
end
Expand Down Expand Up @@ -237,7 +237,6 @@ def self.finalize
def self.warn(msg)
Kernel.warn(msg)
end

end # module Virtus

require 'descendants_tracker'
Expand Down
11 changes: 4 additions & 7 deletions lib/virtus/attribute.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Virtus

# Attribute objects handle coercion and provide interface to hook into an
# attribute set instance that's included into a class or object
#
Expand Down Expand Up @@ -140,7 +139,7 @@ def value_coerced?(value)
#
# @api public
def coercible?
kind_of?(Coercible)
is_a?(Coercible)
end

# Return if the attribute has lazy default value evaluation
Expand All @@ -157,7 +156,7 @@ def coercible?
#
# @api public
def lazy?
kind_of?(LazyDefault)
is_a?(LazyDefault)
end

# Return if the attribute is in the strict coercion mode
Expand All @@ -174,7 +173,7 @@ def lazy?
#
# @api public
def strict?
kind_of?(Strict)
is_a?(Strict)
end

# Return if the attribute is in the nullify blank coercion mode
Expand All @@ -191,7 +190,7 @@ def strict?
#
# @api public
def nullify_blank?
kind_of?(NullifyBlank)
is_a?(NullifyBlank)
end

# Return if the attribute is accepts nil values as valid coercion output
Expand Down Expand Up @@ -239,7 +238,5 @@ def finalize
freeze
self
end

end # class Attribute

end # module Virtus
4 changes: 0 additions & 4 deletions lib/virtus/attribute/accessor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Virtus
class Attribute

# Accessor extension provides methods to read and write attributes
#
# @example
Expand All @@ -13,7 +12,6 @@ class Attribute
# attribute.get(object) # => '[email protected]'
#
module Accessor

# Return name of this accessor attribute
#
# @return [Symbol]
Expand Down Expand Up @@ -96,8 +94,6 @@ def public_reader?
def public_writer?
options[:writer] == :public
end

end # Accessor

end # Attribute
end # Virtus
2 changes: 0 additions & 2 deletions lib/virtus/attribute/boolean.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Virtus
class Attribute

# Boolean attribute allows true or false values to be set
# Additionally it adds boolean reader method, like "admin?"
#
Expand Down Expand Up @@ -49,7 +48,6 @@ def define_accessor_methods(attribute_set)
super
attribute_set.define_reader_method(self, "#{name}?", options[:reader])
end

end # class Boolean
end # class Attribute
end # module Virtus
12 changes: 4 additions & 8 deletions lib/virtus/attribute/builder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Virtus

# Attribute placeholder used when type constant is passed as a string or symbol
#
# @private
Expand All @@ -8,7 +7,8 @@ class PendingAttribute

# @api private
def initialize(type, options)
@type, @options = type.to_s, options
@type = type.to_s
@options = options
@name = options[:name]
end

Expand Down Expand Up @@ -36,7 +36,6 @@ def determine_type
Object.const_get(type)
end
end

end # PendingAttribute

# Extracts the actual type primitive from input type
Expand Down Expand Up @@ -64,13 +63,13 @@ def initialize_primitive
if type.instance_of?(String) || type.instance_of?(Symbol)
if !type.to_s.include?('::') && Object.const_defined?(type)
Object.const_get(type)
elsif not Attribute::Builder.determine_type(type)
elsif !Attribute::Builder.determine_type(type)
@pending = true
type
else
type
end
elsif not type.is_a?(Class)
elsif !type.is_a?(Class)
type.class
else
type
Expand All @@ -79,7 +78,6 @@ def initialize_primitive
end

class Attribute

# Builder is used to set up an attribute instance based on input type and options
#
# @private
Expand Down Expand Up @@ -181,8 +179,6 @@ def determine_visibility
writer_visibility = options.fetch(:writer, default_accessor)
options.update(:reader => reader_visibility, :writer => writer_visibility)
end

end # class Builder

end # class Attribute
end # module Virtus
4 changes: 0 additions & 4 deletions lib/virtus/attribute/coercer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
module Virtus
class Attribute

# Coercer accessor wrapper
#
# @api private
class Coercer < Virtus::Coercer

# @api private
attr_reader :method, :coercers

Expand Down Expand Up @@ -38,8 +36,6 @@ def call(value)
def success?(primitive, value)
coercers[primitive].coerced?(value)
end

end # class Coercer

end # class Attribute
end # module Virtus
4 changes: 0 additions & 4 deletions lib/virtus/attribute/coercible.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module Virtus
class Attribute

# Attribute extension providing coercion when setting an attribute value
#
module Coercible

# Coerce value before setting
#
# @see Accessor#set
Expand All @@ -13,8 +11,6 @@ module Coercible
def set(instance, value)
super(instance, coerce(value))
end

end # Coercible

end # Attribute
end # Virtus
Loading