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 logic to ensure badge information (Department/Name) in CamelCase #10271

Merged
merged 4 commits into from
Mar 9, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/rubocop/cop/badge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ def self.for(class_name)
end

def self.parse(identifier)
new(identifier.split('/'))
new(identifier.split('/').map { |i| camel_case(i) })
end

def self.camel_case(name_part)
return 'RSpec' if name_part == 'rspec'

name_part.gsub(/^\w|_\w/) { |match| match[-1, 1].upcase }
end

def initialize(class_name_parts)
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
end
end

include_examples 'cop identifier parsing', 'bar', %w[Bar]
include_examples 'cop identifier parsing', 'Bar', %w[Bar]
include_examples 'cop identifier parsing', 'snake_case/example', %w[SnakeCase Example]
include_examples 'cop identifier parsing', 'Foo/Bar', %w[Foo Bar]
include_examples 'cop identifier parsing', 'Foo/Bar/Baz', %w[Foo Bar Baz]
include_examples 'cop identifier parsing', 'Foo/Bar/Baz/Qux', %w[Foo Bar Baz Qux]
Expand Down Expand Up @@ -79,4 +81,18 @@
expect(described_class.parse('Deep/Department/Bar').qualified?).to be(true)
end
end

describe '#camel_case' do
it 'converts "lint" to CamelCase' do
expect(described_class.camel_case('lint')).to eq('Lint')
end

it 'converts "foo_bar" to CamelCase' do
expect(described_class.camel_case('foo_bar')).to eq('FooBar')
end

it 'converts "rspec" to CamelCase' do
expect(described_class.camel_case('rspec')).to eq('RSpec')
end
end
end