Skip to content

Commit

Permalink
Rubocop cleanup (#264)
Browse files Browse the repository at this point in the history
* Ignore some project files.

* Add .rubocop.yml.

* Autofix some Rubocop errors.

* Autogenerate .rubocop_todo.yml.

* Add CHANGELOG entry for Rubocop.

* Updated gemspec to rubocop ~> 0.48 and rubocop Target to 2.4.

* Frozen string literals.
  • Loading branch information
james2m authored and LeFnord committed Apr 5, 2017
1 parent 17b0c6c commit 0930f60
Show file tree
Hide file tree
Showing 41 changed files with 143 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ dist
Gemfile.lock
tmp
coverage/
.byebug_history
.ruby-version
.ruby-gemset

## Rubinius
.rbx
Expand Down
24 changes: 24 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
AllCops:
TargetRubyVersion: 2.4
Include:
- Dangerfile

Exclude:
- vendor/**/*
- bin/**/*
- Guardfile

inherit_from: .rubocop_todo.yml

Style/FileName:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'grape-entity.gemspec'
- 'lib/grape-entity.rb'

Style/Documentation:
Enabled: false

Style/MultilineIfModifier:
Enabled: false

Style/RaiseArgs:
Enabled: false

Lint/UnneededDisable:
Enabled: false
28 changes: 14 additions & 14 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-11-20 10:04:42 -0500 using RuboCop version 0.45.0.
# on 2017-04-05 10:30:29 +0700 using RuboCop version 0.48.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
Lint/AmbiguousBlockAssociation:
Exclude:
- 'spec/grape_entity/exposure/represent_exposure_spec.rb'

# Offense count: 6
Metrics/AbcSize:
Max: 32

# Offense count: 35
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 1499

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Expand All @@ -19,27 +29,17 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 237
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
# Offense count: 238
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 146

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

# Offense count: 2
Metrics/PerceivedComplexity:
Max: 13

# Offense count: 33
Style/Documentation:
Enabled: false

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
Style/FileName:
Exclude:
- 'lib/grape-entity.rb'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Features

* [#264](https://github.com/ruby-grape/grape-entity/pull/264): Adds Rubocop config and todo list - [@james2m](https://github.com/james2m).
* [#255](https://github.com/ruby-grape/grape-entity/pull/255): Adds code coverage w/ coveralls - [@LeFnord](https://github.com/LeFnord).

* Your contribution here.
Expand Down
2 changes: 2 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

danger.import_dangerfile(gem: 'ruby-grape-danger')
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'http://rubygems.org'

gemspec
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true

require 'rubygems'
require 'bundler'
Expand All @@ -17,4 +18,4 @@ RSpec::Core::RakeTask.new(:spec)
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)

task default: [:spec, :rubocop]
task default: %i[spec rubocop]
2 changes: 2 additions & 0 deletions bench/serializing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'grape-entity'
require 'benchmark'
Expand Down
4 changes: 3 additions & 1 deletion grape-entity.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'grape_entity/version'

Expand All @@ -21,7 +23,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'bundler'
s.add_development_dependency 'rake'
s.add_development_dependency 'rubocop', '~> 0.40'
s.add_development_dependency 'rubocop', '~> 0.48'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'maruku'
Expand Down
2 changes: 2 additions & 0 deletions lib/grape-entity.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'grape_entity'
2 changes: 2 additions & 0 deletions lib/grape_entity.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/version'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/hash/reverse_merge'
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/condition.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'grape_entity/condition/base'
require 'grape_entity/condition/block_condition'
require 'grape_entity/condition/hash_condition'
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/condition/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Condition
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/condition/block_condition.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Condition
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/condition/hash_condition.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Condition
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/condition/symbol_condition.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Condition
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/delegator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'grape_entity/delegator/base'
require 'grape_entity/delegator/hash_object'
require 'grape_entity/delegator/openstruct_object'
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/delegator/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Delegator
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/delegator/fetchable_object.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Delegator
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/delegator/hash_object.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Delegator
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/delegator/openstruct_object.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Delegator
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/delegator/plain_object.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Delegator
Expand Down
8 changes: 5 additions & 3 deletions lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'multi_json'
require 'set'

Expand Down Expand Up @@ -506,8 +508,8 @@ def to_xml(options = {})
end

# All supported options.
OPTIONS = [
:rewrite, :as, :if, :unless, :using, :with, :proc, :documentation, :format_with, :safe, :attr_path, :if_extras, :unless_extras, :merge
OPTIONS = %i[
rewrite as if unless using with proc documentation format_with safe attr_path if_extras unless_extras merge
].to_set.freeze

# Merges the given options with current block options.
Expand All @@ -517,7 +519,7 @@ def self.merge_options(options)
opts = {}

merge_logic = proc do |key, existing_val, new_val|
if [:if, :unless].include?(key)
if %i[if unless].include?(key)
if existing_val.is_a?(Hash) && new_val.is_a?(Hash)
existing_val.merge(new_val)
elsif new_val.is_a?(Hash)
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'grape_entity/exposure/base'
require 'grape_entity/exposure/represent_exposure'
require 'grape_entity/exposure/block_exposure'
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/block_exposure.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/delegator_exposure.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/formatter_block_exposure.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/formatter_exposure.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/nesting_exposure.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
26 changes: 14 additions & 12 deletions lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down Expand Up @@ -30,18 +32,18 @@ def clear
@exposures.clear
end

[
:each,
:to_ary, :to_a,
:all?,
:select,
:each_with_object,
:[],
:==,
:size,
:count,
:length,
:empty?
%i[
each
to_ary to_a
all?
select
each_with_object
\[\]
==
size
count
length
empty?
].each do |name|
class_eval <<-RUBY, __FILE__, __LINE__
def #{name}(*args, &block)
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/nesting_exposure/output_builder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/exposure/represent_exposure.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
module Exposure
Expand Down
2 changes: 2 additions & 0 deletions lib/grape_entity/options.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Grape
class Entity
class Options
Expand Down
4 changes: 3 additions & 1 deletion lib/grape_entity/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GrapeEntity
VERSION = '0.6.1'.freeze
VERSION = '0.6.1'
end
Loading

0 comments on commit 0930f60

Please sign in to comment.