Skip to content

Commit

Permalink
Unify DirectiveComment specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Eres committed Jun 13, 2021
1 parent b7d75ac commit 5a7b8f5
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 180 deletions.
11 changes: 6 additions & 5 deletions lib/rubocop/directive_comment.rb
Expand Up @@ -25,10 +25,11 @@ def self.before_comment(line)
line.split(DIRECTIVE_COMMENT_REGEXP).first
end

attr_reader :comment, :mode, :cops
attr_reader :comment, :cop_registry, :mode, :cops

def initialize(comment)
def initialize(comment, cop_registry = Cop::Registry.global)
@comment = comment
@cop_registry = cop_registry
@mode, @cops = match_captures
end

Expand Down Expand Up @@ -123,15 +124,15 @@ def parsed_cop_names
end

def department?(name)
Cop::Registry.global.department?(name)
cop_registry.department?(name)
end

def all_cop_names
exclude_redundant_directive_cop(Cop::Registry.global.names)
exclude_redundant_directive_cop(cop_registry.names)
end

def cop_names_for_department(department)
names = Cop::Registry.global.names_for_department(department)
names = cop_registry.names_for_department(department)
has_redundant_directive_cop = department == REDUNDANT_DIRECTIVE_COP_DEPARTMENT
has_redundant_directive_cop ? exclude_redundant_directive_cop(names) : names
end
Expand Down

0 comments on commit 5a7b8f5

Please sign in to comment.