Skip to content

Commit 0930f60

Browse files
james2mLeFnord
authored andcommitted
Rubocop cleanup (ruby-grape#264)
* 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.
1 parent 17b0c6c commit 0930f60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+143
-42
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ dist
3232
Gemfile.lock
3333
tmp
3434
coverage/
35+
.byebug_history
36+
.ruby-version
37+
.ruby-gemset
3538

3639
## Rubinius
3740
.rbx

.rubocop.yml

+24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
AllCops:
2+
TargetRubyVersion: 2.4
3+
Include:
4+
- Dangerfile
5+
26
Exclude:
37
- vendor/**/*
8+
- bin/**/*
49
- Guardfile
510

611
inherit_from: .rubocop_todo.yml
12+
13+
Style/FileName:
14+
Exclude:
15+
- 'Gemfile'
16+
- 'Rakefile'
17+
- 'grape-entity.gemspec'
18+
- 'lib/grape-entity.rb'
19+
20+
Style/Documentation:
21+
Enabled: false
22+
23+
Style/MultilineIfModifier:
24+
Enabled: false
25+
26+
Style/RaiseArgs:
27+
Enabled: false
28+
29+
Lint/UnneededDisable:
30+
Enabled: false

.rubocop_todo.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-11-20 10:04:42 -0500 using RuboCop version 0.45.0.
3+
# on 2017-04-05 10:30:29 +0700 using RuboCop version 0.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Offense count: 1
10+
Lint/AmbiguousBlockAssociation:
11+
Exclude:
12+
- 'spec/grape_entity/exposure/represent_exposure_spec.rb'
13+
914
# Offense count: 6
1015
Metrics/AbcSize:
1116
Max: 32
1217

18+
# Offense count: 35
19+
# Configuration parameters: CountComments, ExcludedMethods.
20+
Metrics/BlockLength:
21+
Max: 1499
22+
1323
# Offense count: 2
1424
# Configuration parameters: CountComments.
1525
Metrics/ClassLength:
@@ -19,27 +29,17 @@ Metrics/ClassLength:
1929
Metrics/CyclomaticComplexity:
2030
Max: 11
2131

22-
# Offense count: 237
23-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
32+
# Offense count: 238
33+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
2434
# URISchemes: http, https
2535
Metrics/LineLength:
2636
Max: 146
2737

28-
# Offense count: 6
38+
# Offense count: 7
2939
# Configuration parameters: CountComments.
3040
Metrics/MethodLength:
3141
Max: 28
3242

3343
# Offense count: 2
3444
Metrics/PerceivedComplexity:
3545
Max: 13
36-
37-
# Offense count: 33
38-
Style/Documentation:
39-
Enabled: false
40-
41-
# Offense count: 1
42-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
43-
Style/FileName:
44-
Exclude:
45-
- 'lib/grape-entity.rb'

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### Features
44

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

78
* Your contribution here.

Dangerfile

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
danger.import_dangerfile(gem: 'ruby-grape-danger')

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'http://rubygems.org'
24

35
gemspec

Rakefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
# frozen_string_literal: true
23

34
require 'rubygems'
45
require 'bundler'
@@ -17,4 +18,4 @@ RSpec::Core::RakeTask.new(:spec)
1718
require 'rubocop/rake_task'
1819
RuboCop::RakeTask.new(:rubocop)
1920

20-
task default: [:spec, :rubocop]
21+
task default: %i[spec rubocop]

bench/serializing.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
24
require 'grape-entity'
35
require 'benchmark'

grape-entity.gemspec

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
24
require 'grape_entity/version'
35

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

2224
s.add_development_dependency 'bundler'
2325
s.add_development_dependency 'rake'
24-
s.add_development_dependency 'rubocop', '~> 0.40'
26+
s.add_development_dependency 'rubocop', '~> 0.48'
2527
s.add_development_dependency 'rspec', '~> 3.0'
2628
s.add_development_dependency 'rack-test'
2729
s.add_development_dependency 'maruku'

lib/grape-entity.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
require 'grape_entity'

lib/grape_entity.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'active_support/version'
24
require 'active_support/core_ext/string/inflections'
35
require 'active_support/core_ext/hash/reverse_merge'

lib/grape_entity/condition.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'grape_entity/condition/base'
24
require 'grape_entity/condition/block_condition'
35
require 'grape_entity/condition/hash_condition'

lib/grape_entity/condition/base.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Condition

lib/grape_entity/condition/block_condition.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Condition

lib/grape_entity/condition/hash_condition.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Condition

lib/grape_entity/condition/symbol_condition.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Condition

lib/grape_entity/delegator.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'grape_entity/delegator/base'
24
require 'grape_entity/delegator/hash_object'
35
require 'grape_entity/delegator/openstruct_object'

lib/grape_entity/delegator/base.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Delegator

lib/grape_entity/delegator/fetchable_object.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Delegator

lib/grape_entity/delegator/hash_object.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Delegator

lib/grape_entity/delegator/openstruct_object.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Delegator

lib/grape_entity/delegator/plain_object.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Delegator

lib/grape_entity/entity.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'multi_json'
24
require 'set'
35

@@ -506,8 +508,8 @@ def to_xml(options = {})
506508
end
507509

508510
# All supported options.
509-
OPTIONS = [
510-
:rewrite, :as, :if, :unless, :using, :with, :proc, :documentation, :format_with, :safe, :attr_path, :if_extras, :unless_extras, :merge
511+
OPTIONS = %i[
512+
rewrite as if unless using with proc documentation format_with safe attr_path if_extras unless_extras merge
511513
].to_set.freeze
512514

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

519521
merge_logic = proc do |key, existing_val, new_val|
520-
if [:if, :unless].include?(key)
522+
if %i[if unless].include?(key)
521523
if existing_val.is_a?(Hash) && new_val.is_a?(Hash)
522524
existing_val.merge(new_val)
523525
elsif new_val.is_a?(Hash)

lib/grape_entity/exposure.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'grape_entity/exposure/base'
24
require 'grape_entity/exposure/represent_exposure'
35
require 'grape_entity/exposure/block_exposure'

lib/grape_entity/exposure/base.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/exposure/block_exposure.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/exposure/delegator_exposure.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/exposure/formatter_block_exposure.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/exposure/formatter_exposure.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/exposure/nesting_exposure.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure
@@ -30,18 +32,18 @@ def clear
3032
@exposures.clear
3133
end
3234

33-
[
34-
:each,
35-
:to_ary, :to_a,
36-
:all?,
37-
:select,
38-
:each_with_object,
39-
:[],
40-
:==,
41-
:size,
42-
:count,
43-
:length,
44-
:empty?
35+
%i[
36+
each
37+
to_ary to_a
38+
all?
39+
select
40+
each_with_object
41+
\[\]
42+
==
43+
size
44+
count
45+
length
46+
empty?
4547
].each do |name|
4648
class_eval <<-RUBY, __FILE__, __LINE__
4749
def #{name}(*args, &block)

lib/grape_entity/exposure/nesting_exposure/output_builder.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/exposure/represent_exposure.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
module Exposure

lib/grape_entity/options.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Grape
24
class Entity
35
class Options

lib/grape_entity/version.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module GrapeEntity
2-
VERSION = '0.6.1'.freeze
4+
VERSION = '0.6.1'
35
end

0 commit comments

Comments
 (0)