Class: RuboCop::Cop::Netlify::RequireScopeDuplication

Inherits:
RequireScopeBase show all
Defined in:
lib/rubocop/cop/netlify/require_scope_duplication.rb

Overview

This cop checks OAuth scope definition duplication

Examples:

# bad
require_scope "all:read"
require_scope "public"

# good
require_scope "public", "all:read"

# bad
require_scope "all:read", only: :index
require_scope "all:read", only: [:index, :show]

# good
require_scope "all:read", only: [:index, :show]

# bad
require_scope "all:read"
require_scope "all:write"

# good
require_scope "??" # Be careful! 

Constant Summary

Constants inherited from RequireScopeBase

RuboCop::Cop::Netlify::RequireScopeBase::RESTRICT_ON_SEND

Instance Method Summary collapse

Methods inherited from RequireScopeBase

#on_class, #on_send

Instance Method Details

#on_def(node) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/cop/netlify/require_scope_duplication.rb', line 32

def on_def(node)
  return unless @is_controller
  return unless @method_protection == :public
      
  require_scopes = require_scopes_for_method(node.method_name)
  if require_scopes.size > 1
    add_offense(require_scopes.last[:node], message: "Multiple overlapping definitions: #{require_scopes.map { |rs| rs[:scopes].inspect }.join(" and ")}.")
  end
end