Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add department checking to Registry #9630

Merged
merged 2 commits into from Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/rubocop/cop/registry.rb
Expand Up @@ -64,6 +64,11 @@ def without_department(department)
with(without_department.values.flatten)
end

# @return [Boolean] Checks if given name is department
def department?(name)
departments.include? name.to_sym
end

def contains_cop_matching?(names)
cops.any? { |cop| cop.match?(names) }
end
Expand Down Expand Up @@ -179,6 +184,10 @@ def names
cops.map(&:cop_name)
end

def names_for_department(department)
cops.select { |cop| cop.department == department.to_sym }.map(&:cop_name)
end

def ==(other)
cops == other.cops
end
Expand Down
17 changes: 17 additions & 0 deletions spec/rubocop/cop/registry_spec.rb
Expand Up @@ -340,4 +340,21 @@
]
)
end

describe '#department?' do
it 'returns true for department name' do
expect(registry.department?('Lint')).to be true
end

it 'returns false for other names' do
expect(registry.department?('Foo')).to be false
end
end

describe 'names_for_department' do
it 'returns array of cops for specified department' do
expect(registry.names_for_department('Lint'))
.to eq %w[Lint/BooleanSymbol Lint/DuplicateMethods]
end
end
end