Skip to content

Commit 5883c6d

Browse files
authored
Enable Cop in some Layout departments (#435)
* Enable Cop in some Layout departments Change to enable Cop to unify some Space, Indent and Line. * Auto-correct Layout/EmptyLines * Auto-correct Layout/IndentationWidth * Auto-correct Layout/LeadingCommentSpace * Auto-correct Layout/RedundantLineBreak * Auto-correct Layout/SpaceAfterColon * Auto-correct Layout/SpaceAfterComma * Auto-correct Layout/SpaceAroundEqualsInParameterDefault * Auto-correct Layout/SpaceAroundOperators * Auto-correct Layout/SpaceBeforeBlockBraces * Auto-correct Layout/SpaceInLambdaLiteral * Auto-correct Layout/SpaceInsideArrayLiteralBrackets * Auto-correct Layout/SpaceInsideBlockBraces * Auto-correct Layout/SpaceInsideHashLiteralBraces * Auto-correct Layout/TrailingEmptyLines * Auto-correct Layout/TrailingWhitespace
1 parent 02968af commit 5883c6d

Some content is hidden

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

52 files changed

+529
-712
lines changed

.rubocop.yml

+120
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,129 @@ AllCops:
1111
- 'examples/**/*'
1212
- 'vendor/**/*'
1313

14+
Layout/BlockEndNewline:
15+
Enabled: true
16+
17+
Layout/EmptyComment:
18+
Enabled: true
19+
20+
Layout/EmptyLines:
21+
Enabled: true
22+
23+
Layout/EndOfLine:
24+
Enabled: true
25+
1426
Layout/ExtraSpacing:
1527
Enabled: true
1628

29+
Layout/IndentationStyle:
30+
Enabled: true
31+
32+
Layout/IndentationWidth:
33+
Enabled: true
34+
35+
Layout/InitialIndentation:
36+
Enabled: true
37+
38+
Layout/LeadingCommentSpace:
39+
Enabled: true
40+
41+
Layout/LeadingEmptyLines:
42+
Enabled: true
43+
44+
Layout/LineContinuationLeadingSpace:
45+
Enabled: true
46+
47+
Layout/LineContinuationSpacing:
48+
Enabled: true
49+
50+
Layout/RedundantLineBreak:
51+
Enabled: true
52+
53+
Layout/SpaceAfterColon:
54+
Enabled: true
55+
56+
Layout/SpaceAfterComma:
57+
Enabled: true
58+
59+
Layout/SpaceAfterMethodName:
60+
Enabled: true
61+
62+
Layout/SpaceAfterNot:
63+
Enabled: true
64+
65+
Layout/SpaceAfterSemicolon:
66+
Enabled: true
67+
68+
Layout/SpaceAroundBlockParameters:
69+
Enabled: true
70+
71+
Layout/SpaceAroundEqualsInParameterDefault:
72+
Enabled: true
73+
74+
Layout/SpaceAroundKeyword:
75+
Enabled: true
76+
77+
Layout/SpaceAroundMethodCallOperator:
78+
Enabled: true
79+
80+
Layout/SpaceAroundOperators:
81+
Enabled: true
82+
83+
Layout/SpaceBeforeBlockBraces:
84+
Enabled: true
85+
86+
Layout/SpaceBeforeBrackets:
87+
Enabled: true
88+
89+
Layout/SpaceBeforeComma:
90+
Enabled: true
91+
92+
Layout/SpaceBeforeComment:
93+
Enabled: true
94+
95+
Layout/SpaceBeforeFirstArg:
96+
Enabled: true
97+
98+
Layout/SpaceBeforeSemicolon:
99+
Enabled: true
100+
101+
Layout/SpaceInLambdaLiteral:
102+
Enabled: true
103+
104+
Layout/SpaceInsideArrayLiteralBrackets:
105+
Enabled: true
106+
107+
Layout/SpaceInsideArrayPercentLiteral:
108+
Enabled: true
109+
110+
Layout/SpaceInsideBlockBraces:
111+
Enabled: true
112+
113+
SpaceInsideHashLiteralBraces:
114+
Enabled: true
115+
116+
Layout/SpaceInsideParens:
117+
Enabled: true
118+
119+
Layout/SpaceInsidePercentLiteralDelimiters:
120+
Enabled: true
121+
122+
Layout/SpaceInsideRangeLiteral:
123+
Enabled: true
124+
125+
Layout/SpaceInsideReferenceBrackets:
126+
Enabled: true
127+
128+
Layout/SpaceInsideStringInterpolation:
129+
Enabled: true
130+
131+
Layout/TrailingEmptyLines:
132+
Enabled: true
133+
134+
Layout/TrailingWhitespace:
135+
Enabled: true
136+
17137
Performance:
18138
Exclude:
19139
- 'test/**/*'

committee.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
1515
s.homepage = "https://github.com/interagent/committee"
1616
s.license = "MIT"
1717

18-
s.executables << "committee-stub"
19-
s.files = Dir["{bin,lib,test}/**/*.rb"]
18+
s.executables << "committee-stub"
19+
s.files = Dir["{bin,lib,test}/**/*.rb"]
2020

2121
s.required_ruby_version = ">= 2.7.0"
2222

lib/committee/bin/committee_stub.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ def get_app(schema, options)
3030

3131
# Gets an option parser for command line arguments.
3232
def get_options_parser
33-
options = {
34-
driver: nil,
35-
help: false,
36-
port: 9292,
37-
tolerant: false,
38-
}
33+
options = { driver: nil, help: false, port: 9292, tolerant: false, }
3934

4035
parser = OptionParser.new do |opts|
4136
opts.banner = "Usage: rackup [options] [JSON Schema file]"

lib/committee/drivers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def self.load_from_data(hash, schema_path = nil, parser_options: {})
6565
'from next version. Pass config `strict_reference_validation: true` (or false, if you must) ' +
6666
'to quiet this warning.')
6767
opts[:strict_reference_validation] ||= false
68-
68+
6969
openapi = OpenAPIParser.parse_with_filepath(hash, schema_path, opts)
7070
return Committee::Drivers::OpenAPI3::Driver.new.parse(openapi)
7171
end

lib/committee/drivers/open_api_2/driver.rb

+7-20
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,7 @@ def schema_class
8181

8282
# These are fields that the OpenAPI 2 spec considers mandatory to be
8383
# included in the document's top level.
84-
REQUIRED_FIELDS = [
85-
:consumes,
86-
:definitions,
87-
:paths,
88-
:produces,
89-
:swagger,
90-
].map(&:to_s).freeze
84+
REQUIRED_FIELDS = [:consumes, :definitions, :paths, :produces, :swagger,].map(&:to_s).freeze
9185

9286
def find_best_fit_response(link_data)
9387
if response_data = link_data["responses"]["200"] || response_data = link_data["responses"][200]
@@ -97,8 +91,7 @@ def find_best_fit_response(link_data)
9791
else
9892
# Sort responses so that we can try to prefer any 3-digit status code.
9993
# If there are none, we'll just take anything from the list.
100-
ordered_responses = link_data["responses"].
101-
select { |k, v| k.to_s =~ /[0-9]{3}/ }
94+
ordered_responses = link_data["responses"].select { |k, v| k.to_s =~ /[0-9]{3}/ }
10295
if first = ordered_responses.first
10396
[first[0].to_i, first[1]]
10497
else
@@ -117,9 +110,7 @@ def parse_definitions!(data)
117110
# that all references to it will still have correct paths (i.e. we can
118111
# still find a resource at '#/definitions/resource' instead of
119112
# '#/resource').
120-
schema = JsonSchema.parse!({
121-
"definitions" => data['definitions'],
122-
})
113+
schema = JsonSchema.parse!({ "definitions" => data['definitions'], })
123114
schema.expand_references!
124115
schema.uri = DEFINITIONS_PSEUDO_URI
125116

@@ -182,8 +173,7 @@ def parse_routes!(data, schema, store)
182173

183174
# A link need not necessarily specify a target schema.
184175
if response_data["schema"]
185-
target_schemas_data["properties"][href]["properties"][method] =
186-
response_data["schema"]
176+
target_schemas_data["properties"][href]["properties"][method] = response_data["schema"]
187177
end
188178
end
189179

@@ -199,10 +189,8 @@ def parse_routes!(data, schema, store)
199189
# #parse_definitions!, but what we're doing here is prefixing references
200190
# with a specialized internal URI so that they can reference definitions
201191
# from another document in the store.
202-
schemas =
203-
rewrite_references_and_parse(schemas_data, store)
204-
target_schemas =
205-
rewrite_references_and_parse(target_schemas_data, store)
192+
schemas = rewrite_references_and_parse(schemas_data, store)
193+
target_schemas = rewrite_references_and_parse(target_schemas_data, store)
206194

207195
# As noted above, now that we've parsed our aggregate response schema, go
208196
# back through each link and them their response schema.
@@ -218,8 +206,7 @@ def parse_routes!(data, schema, store)
218206
end
219207

220208
# response
221-
link.target_schema =
222-
target_schemas.properties[link.href].properties[method]
209+
link.target_schema = target_schemas.properties[link.href].properties[method]
223210
end
224211
end
225212

lib/committee/drivers/open_api_2/parameter_schema_builder.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def call
1717
check_required_fields!(body_param)
1818

1919
if link_data["parameters"].detect { |p| p["in"] == "form" } != nil
20-
raise ArgumentError, "Committee: can't mix body parameter " \
21-
"with form parameters."
20+
raise ArgumentError, "Committee: can't mix body parameter with form parameters."
2221
end
2322

2423
schema_data = body_param["schema"]

lib/committee/drivers/open_api_2/schema_builder.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ def initialize(link_data)
1010

1111
private
1212

13-
LINK_REQUIRED_FIELDS = [
14-
:name
15-
].map(&:to_s).freeze
13+
LINK_REQUIRED_FIELDS = [:name].map(&:to_s).freeze
1614

1715
attr_accessor :link_data
1816

1917
def check_required_fields!(param_data)
2018
LINK_REQUIRED_FIELDS.each do |field|
2119
if !param_data[field]
22-
raise ArgumentError,
23-
"Committee: no #{field} section in link data."
20+
raise ArgumentError, "Committee: no #{field} section in link data."
2421
end
2522
end
2623
end

lib/committee/errors.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BadRequest < Error
1010
class InvalidRequest < Error
1111
attr_reader :original_error
1212

13-
def initialize(error_message=nil, original_error: nil)
13+
def initialize(error_message = nil, original_error: nil)
1414
@original_error = original_error
1515
super(error_message)
1616
end
@@ -19,7 +19,7 @@ def initialize(error_message=nil, original_error: nil)
1919
class InvalidResponse < Error
2020
attr_reader :original_error
2121

22-
def initialize(error_message=nil, original_error: nil)
22+
def initialize(error_message = nil, original_error: nil)
2323
@original_error = original_error
2424
super(error_message)
2525
end

lib/committee/middleware/base.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Committee
44
module Middleware
55
class Base
6-
def initialize(app, options={})
6+
def initialize(app, options = {})
77
@app = app
88

99
@error_class = options.fetch(:error_class, Committee::ValidationError)
@@ -14,7 +14,7 @@ def initialize(app, options={})
1414
@schema = self.class.get_schema(options)
1515

1616
@router = @schema.build_router(options)
17-
@accept_request_filter = options[:accept_request_filter] || -> (_) { true }
17+
@accept_request_filter = options[:accept_request_filter] || ->(_) { true }
1818
end
1919

2020
def call(env)

lib/committee/middleware/request_validation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Committee
44
module Middleware
55
class RequestValidation < Base
6-
def initialize(app, options={})
6+
def initialize(app, options = {})
77
super
88

99
@strict = options[:strict]

lib/committee/middleware/stub.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module Committee
66
module Middleware
77
class Stub < Base
8-
def initialize(app, options={})
8+
def initialize(app, options = {})
99
super
1010

1111
# A bug in Committee's cache implementation meant that it wasn't working

lib/committee/request_unpacker.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def indifferent_params(object)
2020
end
2121
end
2222

23-
def initialize(options={})
23+
def initialize(options = {})
2424
@allow_form_params = options[:allow_form_params]
2525
@allow_get_body = options[:allow_get_body]
2626
@allow_query_params = options[:allow_query_params]
@@ -32,7 +32,7 @@ def unpack_request_params(request)
3232
# if Content-Type is empty or JSON, and there was a request body, try to
3333
# interpret it as JSON
3434
params = if !request.media_type || request.media_type =~ %r{application/(?:.*\+)?json}
35-
parse_json(request)
35+
parse_json(request)
3636
elsif @optimistic_json
3737
begin
3838
parse_json(request)
@@ -87,8 +87,7 @@ def parse_json(request)
8787
# We want a hash specifically. '42', 42, and [42] will all be
8888
# decoded properly, but we can't use them here.
8989
if !hash.is_a?(Hash)
90-
raise BadRequest,
91-
"Invalid JSON input. Require object with parameters as keys."
90+
raise BadRequest, "Invalid JSON input. Require object with parameters as keys."
9291
end
9392
self.class.indifferent_params(hash)
9493
end

0 commit comments

Comments
 (0)