Skip to content

Commit ed6941f

Browse files
committed
Rubocop fixes
1 parent 667c436 commit ed6941f

21 files changed

+265
-38
lines changed
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
require:
2+
- rubocop-performance
3+
- rubocop-rails
4+
5+
AllCops:
6+
TargetRubyVersion: 2.6
7+
DisabledByDefault: true
8+
Exclude:
9+
- "**/spec/**/*"
10+
11+
Bundler:
12+
Enabled: true
13+
14+
Gemspec:
15+
Enabled: true
16+
17+
Lint:
18+
Enabled: true
19+
20+
Naming:
21+
Enabled: true
22+
23+
Rails:
24+
Enabled: True
25+
26+
Performance:
27+
Enabled: True
28+
29+
Security:
30+
Enabled: True
31+
32+
Layout/CaseIndentation:
33+
Enabled: true
34+
35+
# Align comments with method definitions.
36+
Layout/CommentIndentation:
37+
Enabled: true
38+
39+
Layout/ElseAlignment:
40+
Enabled: true
41+
42+
# Align `end` with the matching keyword or starting expression except for
43+
# assignments, where it should be aligned with the LHS.
44+
Layout/EndAlignment:
45+
Enabled: true
46+
EnforcedStyleAlignWith: variable
47+
AutoCorrect: true
48+
49+
Layout/EmptyLineAfterMagicComment:
50+
Enabled: true
51+
52+
Layout/EmptyLinesAroundBlockBody:
53+
Enabled: true
54+
55+
# In a regular class definition, no empty lines around the body.
56+
Layout/EmptyLinesAroundClassBody:
57+
Enabled: true
58+
59+
# In a regular method definition, no empty lines around the body.
60+
Layout/EmptyLinesAroundMethodBody:
61+
Enabled: true
62+
63+
# In a regular module definition, no empty lines around the body.
64+
Layout/EmptyLinesAroundModuleBody:
65+
Enabled: true
66+
67+
Layout/IndentFirstArgument:
68+
Enabled: true
69+
70+
Layout/IndentationConsistency:
71+
Enabled: true
72+
73+
# Two spaces, no tabs (for indentation).
74+
Layout/IndentationWidth:
75+
Enabled: true
76+
77+
Layout/LeadingCommentSpace:
78+
Enabled: true
79+
80+
Layout/SpaceAfterColon:
81+
Enabled: true
82+
83+
Layout/SpaceAfterComma:
84+
Enabled: true
85+
86+
Layout/SpaceAfterSemicolon:
87+
Enabled: true
88+
89+
Layout/SpaceAroundEqualsInParameterDefault:
90+
Enabled: true
91+
92+
Layout/SpaceAroundKeyword:
93+
Enabled: true
94+
95+
Layout/SpaceAroundOperators:
96+
Enabled: true
97+
98+
Layout/SpaceBeforeComma:
99+
Enabled: true
100+
101+
Layout/SpaceBeforeComment:
102+
Enabled: true
103+
104+
Layout/SpaceBeforeFirstArg:
105+
Enabled: true
106+
107+
# Use `foo {}` not `foo{}`.
108+
Layout/SpaceBeforeBlockBraces:
109+
Enabled: true
110+
111+
# Use `foo { bar }` not `foo {bar}`.
112+
Layout/SpaceInsideBlockBraces:
113+
Enabled: true
114+
EnforcedStyleForEmptyBraces: space
115+
116+
# Use `{ a: 1 }` not `{a:1}`.
117+
Layout/SpaceInsideHashLiteralBraces:
118+
Enabled: true
119+
120+
Layout/SpaceInsideParens:
121+
Enabled: true
122+
123+
# Detect hard tabs, no hard tabs.
124+
Layout/Tab:
125+
Enabled: true
126+
127+
# Blank lines should not have any spaces.
128+
Layout/TrailingBlankLines:
129+
Enabled: true
130+
131+
# No trailing whitespace.
132+
Layout/TrailingWhitespace:
133+
Enabled: true
134+
135+
Naming/PredicateName:
136+
Enabled: false
137+
138+
Naming/UncommunicativeMethodParamName:
139+
Enabled: false
140+
141+
Rails/Output:
142+
Enabled: false
143+
144+
# Prefer &&/|| over and/or.
145+
Style/AndOr:
146+
Enabled: true
147+
148+
# Do not use braces for hash literals when they are the last argument of a
149+
# method call.
150+
Style/BracesAroundHashParameters:
151+
Enabled: true
152+
EnforcedStyle: context_dependent
153+
154+
# Prefer Foo.method over Foo::method
155+
Style/ColonMethodCall:
156+
Enabled: true
157+
158+
Style/DefWithParentheses:
159+
Enabled: true
160+
161+
Style/BlockDelimiters:
162+
Enabled: true
163+
164+
Style/FrozenStringLiteralComment:
165+
Enabled: true
166+
EnforcedStyle: always
167+
168+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
169+
Style/HashSyntax:
170+
Enabled: true
171+
172+
# Defining a method with parameters needs parentheses.
173+
Style/MethodDefParentheses:
174+
Enabled: true
175+
176+
Style/ParenthesesAroundCondition:
177+
Enabled: true
178+
179+
Style/RedundantBegin:
180+
Enabled: true
181+
182+
Style/RedundantFreeze:
183+
Enabled: true
184+
185+
Style/RedundantReturn:
186+
Enabled: true
187+
AllowMultipleReturnValues: true
188+
189+
Style/Semicolon:
190+
Enabled: true
191+
AllowAsExpressionSeparator: true
192+
193+
Style/StringLiterals:
194+
Enabled: true
195+
EnforcedStyle: double_quotes
196+
197+
Style/TrivialAccessors:
198+
Enabled: true
199+
200+
# Use quotes for string literals when they are enough.
201+
Style/UnneededPercentQ:
202+
Enabled: true

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inherit_from:
2+
- https://onehq.com/rubocop.yml

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source "https://rubygems.org"
24

35
gemspec

Rakefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
# frozen_string_literal: true
2+
13
begin
2-
require 'bundler/setup'
4+
require "bundler/setup"
35
rescue LoadError
4-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
57
end
68

7-
require 'rdoc/task'
9+
require "rdoc/task"
810

911
RDoc::Task.new(:rdoc) do |rdoc|
10-
rdoc.rdoc_dir = 'rdoc'
11-
rdoc.title = 'HQ::GraphQL'
12-
rdoc.options << '--line-numbers'
13-
rdoc.rdoc_files.include('README.rdoc')
14-
rdoc.rdoc_files.include('lib/**/*.rb')
12+
rdoc.rdoc_dir = "rdoc"
13+
rdoc.title = "HQ::GraphQL"
14+
rdoc.options << "--line-numbers"
15+
rdoc.rdoc_files.include("README.rdoc")
16+
rdoc.rdoc_files.include("lib/**/*.rb")
1517
end
1618

17-
require 'bundler/gem_tasks'
19+
require "bundler/gem_tasks"

hq-graphql.gemspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ Gem::Specification.new do |s|
2929

3030
s.add_development_dependency "rspec", "~> 3.8"
3131
s.add_development_dependency "rspec-rails", ">= 4.0.0beta2"
32+
s.add_development_dependency "rubocop", "~> 0.7"
33+
s.add_development_dependency "rubocop-performance", "~> 1.4"
34+
s.add_development_dependency "rubocop-rails", "~> 2.3"
3235
end

lib/hq-graphql.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
# rubocop:disable Naming/FileName
2+
# rubocop:enable Naming/FileName
3+
# frozen_string_literal: true
4+
15
require "hq/graphql"

lib/hq/graphql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# frozen_string_literal: true
2+
13
require "rails"
24
require "graphql"
35

46
module HQ
57
module GraphQL
6-
78
def self.config
89
@config ||= ::ActiveSupport::OrderedOptions.new
910
end
@@ -30,7 +31,6 @@ def self.root_queries
3031
def self.types
3132
@types ||= Set.new
3233
end
33-
3434
end
3535
end
3636

lib/hq/graphql/active_record_extensions.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
module HQ
24
module GraphQL
35
module ActiveRecordExtensions
46
class Error < StandardError
5-
MISSING_MODEL_MSG = "Your GraphQL object must be connected to a model: `::HQ::GraphQL::Object.with_model 'User'`".freeze
6-
MISSING_ATTR_MSG = "Can't find attr %{model}.%{attr}'`".freeze
7-
MISSING_ASSOC_MSG = "Can't find association %{model}.%{assoc}'`".freeze
7+
MISSING_MODEL_MSG = "Your GraphQL object must be connected to a model: `::HQ::GraphQL::Object.with_model 'User'`"
8+
MISSING_ATTR_MSG = "Can't find attr %{model}.%{attr}'`"
9+
MISSING_ASSOC_MSG = "Can't find association %{model}.%{assoc}'`"
810
end
911

1012
def self.included(base)
@@ -118,7 +120,6 @@ def validate_model!
118120
model_name || raise(Error, Error::MISSING_MODEL_MSG)
119121
end
120122
end
121-
122123
end
123124
end
124125
end

lib/hq/graphql/engine.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module HQ
24
module GraphQL
35
class Engine < ::Rails::Engine

lib/hq/graphql/input_object.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module HQ
24
module GraphQL
35
class InputObject < ::GraphQL::Schema::InputObject
@@ -25,9 +27,7 @@ def format_nested_attributes
2527
end
2628
end
2729

28-
def with_indifferent_access
29-
to_h.with_indifferent_access
30-
end
30+
delegate :with_indifferent_access, to: :to_h
3131

3232
#### Class Methods ####
3333

@@ -72,7 +72,7 @@ def argument_from_association(association)
7272
argument name, input, required: false
7373
end
7474

75-
if !model_klass.nested_attributes_options.keys.include?(name.to_sym)
75+
if !model_klass.nested_attributes_options.key?(name.to_sym)
7676
model_klass.accepts_nested_attributes_for name, allow_destroy: true
7777
end
7878

@@ -85,7 +85,6 @@ def argument_from_column(column)
8585
argument column.name, ::HQ::GraphQL::Types.type_from_column(column), required: false
8686
end
8787
end
88-
8988
end
9089
end
9190
end

lib/hq/graphql/inputs.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
module HQ
24
module GraphQL
35
module Inputs
46
class Error < StandardError
5-
MISSING_TYPE_MSG = "The GraphQL type for `%{klass}` is missing.".freeze
7+
MISSING_TYPE_MSG = "The GraphQL type for `%{klass}` is missing."
68
end
79

810
def self.[](key)
@@ -26,7 +28,6 @@ def klass_for(klass_or_string)
2628
raise(Error, Error::MISSING_TYPE_MSG % { klass: klass.name })
2729
end
2830
end
29-
3031
end
3132
end
3233
end

lib/hq/graphql/mutation.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module HQ
24
module GraphQL
35
class Mutation < ::GraphQL::Schema::Mutation
@@ -8,7 +10,6 @@ def self.generate_payload_type
810
lazy_load!
911
super
1012
end
11-
1213
end
1314
end
1415
end

lib/hq/graphql/object.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module HQ
24
module GraphQL
35
class Object < ::GraphQL::Schema::Object
@@ -45,7 +47,6 @@ def field_from_column(column)
4547
field column.name, ::HQ::GraphQL::Types.type_from_column(column), null: true
4648
end
4749
end
48-
4950
end
5051
end
5152
end

0 commit comments

Comments
 (0)