Skip to content

Commit 5dabf63

Browse files
authored
Update rubocop to version 1.35.1 (#148)
* Update rubocop to version 1.35.1 * Fix renamed and moved rubocop style definitions * Ignore auto-generated gemfiles for rubocop * Fix changed rubocop department names * Update targeted Ruby version to 2.7 * Configure rubocop to automatically enable new cops as they come * Generate rubocop todo * Fix Gemspec/OrderedDependencies * Define that gem must be published with MFA * Explicitly disable Gemspec/RequiredRubyVersion cop * Fix Layout/EmptyLineAfterMagicComment * Fix Layout/EmptyLineAfterGuardClause * Remove most rubocop custom configurations * Disable all Metrics department cops * Disable Style/StringLiterals * Autofix Style/SymbolArray * Autofix Style/StructInheritance * Autofix Style/StringConcatenation * Autofix Layout/SpaceInsideHashLiteralBraces * Autofix Style/AccessorGrouping * Autofix Style/BlockDelimiters * Autofix Style/ExpandPathArguments * Autofix Style/RedundantFreeze * Autofix Style/IfUnlessModifier * Autofix Style/SignalException * Autofix Style/Encoding * Manually fix Lint/EmptyBlock * Manually fix Naming/HeredocDelimiterNaming * Autofix Style/CollectionCompact * Autofix Lint/NonDeterministicRequireOrder * Stop suggesting rubocop-rake and rubocop-rspec gems * Disable Style/Documentation * Autofix Style/FrozenStringLiteralComment * Manually fix Style/GuardClause * Manually fix Naming/MethodParameterName
1 parent af79b04 commit 5dabf63

Some content is hidden

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

53 files changed

+258
-219
lines changed

.rubocop.yml

Lines changed: 19 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,46 @@
1+
inherit_from: .rubocop_todo.yml
2+
13
AllCops:
2-
TargetRubyVersion: 2.1
4+
TargetRubyVersion: 2.7
5+
NewCops: enable
6+
SuggestExtensions: false
37
Exclude:
48
- 'bin/*'
9+
- 'gemfiles/*'
510
- 'spec/dummy/db/schema.rb'
611
- 'vendor/bundle/**/*'
712
- 'tmp/**/*'
813

9-
Style/FileName:
14+
# TODO: Define a spec.required_ruby_version when shipping a new version
15+
Gemspec/RequiredRubyVersion:
16+
Enabled: false
17+
18+
Naming/FileName:
1019
Exclude:
1120
- lib/jsonapi-authorization.rb
1221
- Appraisals
1322

14-
Metrics/LineLength:
23+
Layout/LineLength:
1524
Enabled: true
1625
Max: 100
1726
Exclude:
1827
- spec/requests/**/*.rb
1928
- jsonapi-authorization.gemspec
2029

21-
Style/MultilineOperationIndentation:
30+
Layout/MultilineOperationIndentation:
2231
EnforcedStyle: indented
2332

24-
Style/MultilineMethodCallIndentation:
33+
Layout/MultilineMethodCallIndentation:
2534
EnforcedStyle: indented
2635

27-
Metrics/ClassLength:
28-
Enabled: false
29-
30-
Style/Documentation:
31-
Enabled: false
32-
33-
Style/ExtraSpacing:
34-
AllowForAlignment: true
35-
36-
Metrics/MethodLength:
37-
Enabled: false
38-
39-
Style/Next:
40-
Enabled: false
41-
42-
Metrics/AbcSize:
43-
Enabled: false
44-
45-
Style/DoubleNegation:
46-
Enabled: false
47-
48-
Style/SignalException:
36+
# We don't want rubocop to enforce splitting methods and stuff like that.
37+
Metrics:
4938
Enabled: false
5039

40+
# We don't care what kind of quotes you use
5141
Style/StringLiterals:
5242
Enabled: false
5343

54-
Style/SpaceInsideHashLiteralBraces:
55-
Enabled: false
56-
EnforcedStyle: space
57-
58-
Style/IndentHash:
59-
EnforcedStyle: consistent
60-
61-
Style/IndentArray:
62-
EnforcedStyle: consistent
63-
64-
Style/ClassAndModuleChildren:
65-
Enabled: false
66-
67-
Style/PercentLiteralDelimiters:
68-
Enabled: false
69-
70-
Style/BlockDelimiters:
71-
Enabled: false
72-
73-
Style/GuardClause:
74-
Enabled: false
75-
76-
Style/ClosingParenthesisIndentation:
77-
Enabled: false
78-
79-
Style/IfUnlessModifier:
80-
Enabled: false
81-
82-
Style/NumericLiterals:
83-
Enabled: false
84-
85-
Style/AsciiComments:
86-
Enabled: false
87-
88-
Style/StructInheritance:
89-
Enabled: false
90-
91-
Style/MultilineBlockChain:
92-
Enabled: false
93-
94-
Metrics/ParameterLists:
95-
Enabled: false
96-
97-
Style/WordArray:
98-
MinSize: 2
99-
100-
Metrics/ModuleLength:
44+
# It's up to us how much we want to document the code
45+
Style/Documentation:
10146
Enabled: false
102-
103-
Style/SingleLineBlockParams:
104-
Methods:
105-
- reduce:
106-
- acc
107-
- obj
108-
- inject:
109-
- acc
110-
- obj
111-
112-
Style/Alias:
113-
EnforcedStyle: prefer_alias_method

.rubocop_todo.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2022-08-24 19:47:54 UTC using RuboCop version 1.35.1.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.

Appraisals

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
appraise 'rails-5-2 pundit-1' do
24
gem 'rails', '5.2.4.4'
35
gem 'jsonapi-resources', '~> 0.9.0'

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require "bundler/gem_tasks"
24
require "rspec/core/rake_task"
35

jsonapi-authorization.gemspec

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# coding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
1+
# frozen_string_literal: true
2+
3+
lib = File.expand_path('lib', __dir__)
34
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
45
require 'jsonapi/authorization/version'
56

@@ -22,14 +23,15 @@ Gem::Specification.new do |spec|
2223

2324
spec.add_development_dependency "appraisal"
2425
spec.add_development_dependency "bundler", ">= 1.11"
25-
spec.add_development_dependency "rake", "~> 13.0"
26-
spec.add_development_dependency "rspec", "~> 3.11"
27-
spec.add_development_dependency "rspec-rails", "~> 5.1"
26+
spec.add_development_dependency "phare", "~> 1.0.1"
2827
spec.add_development_dependency "pry"
2928
spec.add_development_dependency "pry-byebug"
3029
spec.add_development_dependency "pry-doc"
3130
spec.add_development_dependency "pry-rails"
32-
spec.add_development_dependency "rubocop", "~> 0.36.0"
33-
spec.add_development_dependency "phare", "~> 1.0.1"
31+
spec.add_development_dependency "rake", "~> 13.0"
32+
spec.add_development_dependency "rspec", "~> 3.11"
33+
spec.add_development_dependency "rspec-rails", "~> 5.1"
34+
spec.add_development_dependency "rubocop", "~> 1.35.1"
3435
spec.add_development_dependency "sqlite3", "~> 1.3"
36+
spec.metadata['rubygems_mfa_required'] = 'true'
3537
end

lib/jsonapi-authorization.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
require 'jsonapi/authorization'

lib/jsonapi/authorization.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
require "jsonapi-resources"
24
require "jsonapi/authorization/authorizing_processor"
35
require "jsonapi/authorization/configuration"

lib/jsonapi/authorization/authorizing_processor.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'pundit'
24

35
module JSONAPI
@@ -22,19 +24,20 @@ class AuthorizingProcessor < JSONAPI::Processor
2224
:authorize_replace_polymorphic_to_one_relationship
2325
)
2426

25-
[
26-
:find,
27-
:show,
28-
:show_related_resource,
29-
:show_related_resources,
30-
:create_resource,
31-
:replace_fields
27+
%i[
28+
find
29+
show
30+
show_related_resource
31+
show_related_resources
32+
create_resource
33+
replace_fields
3234
].each do |op_name|
3335
set_callback op_name, :after, :authorize_include_directive
3436
end
3537

3638
def authorize_include_directive
3739
return if result.is_a?(::JSONAPI::ErrorsOperationResult)
40+
3841
resources = Array.wrap(
3942
if result.respond_to?(:resources)
4043
result.resources
@@ -220,7 +223,7 @@ def authorize_remove_to_many_relationships
220223
related_records = related_resources.map(&:_model)
221224

222225
if related_records.size != params[:associated_keys].uniq.size
223-
fail JSONAPI::Exceptions::RecordNotFound, params[:associated_keys]
226+
raise JSONAPI::Exceptions::RecordNotFound, params[:associated_keys]
224227
end
225228

226229
authorizer.remove_to_many_relationship(
@@ -306,7 +309,7 @@ def related_models_with_context
306309
data = params[:data]
307310
return { relationship: nil, relation_name: nil, records: nil } if data.nil?
308311

309-
[:to_one, :to_many].flat_map do |rel_type|
312+
%i[to_one to_many].flat_map do |rel_type|
310313
data[rel_type].flat_map do |assoc_name, assoc_value|
311314
related_models =
312315
case assoc_value
@@ -321,7 +324,7 @@ def related_models_with_context
321324
resources.map(&:_model).tap do |scoped_records|
322325
related_ids = Array.wrap(assoc_value).uniq
323326
if scoped_records.count != related_ids.count
324-
fail JSONAPI::Exceptions::RecordNotFound, related_ids
327+
raise JSONAPI::Exceptions::RecordNotFound, related_ids
325328
end
326329
end
327330
else
@@ -339,10 +342,10 @@ def related_models_with_context
339342
end
340343

341344
def authorize_model_includes(source_record)
342-
if params[:include_directives]
343-
params[:include_directives].model_includes.each do |include_item|
344-
authorize_include_item(@resource_klass, source_record, include_item)
345-
end
345+
return unless params[:include_directives]
346+
347+
params[:include_directives].model_includes.each do |include_item|
348+
authorize_include_item(@resource_klass, source_record, include_item)
346349
end
347350
end
348351

@@ -376,6 +379,7 @@ def authorize_include_item(resource_klass, source_record, include_item)
376379
relationship.relation_name(context: context)
377380
)
378381
return if related_record.nil?
382+
379383
authorizer.include_has_one_resource(
380384
source_record: source_record, related_record: related_record
381385
)

lib/jsonapi/authorization/configuration.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
# frozen_string_literal: true
2+
13
require 'jsonapi/authorization/default_pundit_authorizer'
24

35
module JSONAPI
46
module Authorization
57
class Configuration
6-
attr_accessor :authorizer
7-
attr_accessor :pundit_user
8+
attr_accessor :authorizer, :pundit_user
89

910
def initialize
1011
self.authorizer = ::JSONAPI::Authorization::DefaultPunditAuthorizer

0 commit comments

Comments
 (0)