Skip to content

Commit

Permalink
Add logic to ensure badge information (Department/Name) is in CamelCa…
Browse files Browse the repository at this point in the history
…se (#10271)
  • Loading branch information
timtoronto634 committed Mar 9, 2022
1 parent c59c090 commit bfc6bfb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rubocop/cop/badge.rb
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
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

0 comments on commit bfc6bfb

Please sign in to comment.