Skip to content

Commit

Permalink
Ensure cop names are valid with backticks in future changelog entries
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Feb 17, 2023
1 parent 7af46ba commit 1358bb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

### Changes

* [#880](https://github.com/rubocop/rubocop-rails/pull/880): Add Rails/I18nLocaleTexts match for redirect_back. ([@bensheldon][])
* [#880](https://github.com/rubocop/rubocop-rails/pull/880): Add `Rails/I18nLocaleTexts` match for redirect_back. ([@bensheldon][])

## 2.17.3 (2022-11-20)

Expand Down
27 changes: 23 additions & 4 deletions spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,25 @@
File.read(path)
end

let(:path) do
File.join(File.dirname(__FILE__), '..', 'CHANGELOG.md')
end
let(:path) { File.expand_path('../CHANGELOG.md', __dir__) }
let(:entries) { lines.grep(/^\*/).map(&:chomp) }

include_examples 'has Changelog format'

context 'future entries' do
dir = File.join(File.dirname(__FILE__), '..', 'changelog')
let(:allowed_cop_names) do
existing_cop_names.to_set.union(legacy_cop_names)
end

let(:existing_cop_names) do
RuboCop::Cop::Cop.registry.without_department(:Test).without_department(:Test2).cops.map(&:cop_name).to_set
end

let(:legacy_cop_names) do
RuboCop::ConfigObsoletion.legacy_cop_names
end

dir = File.expand_path('../changelog', __dir__)

Dir["#{dir}/*.md"].each do |path|
context "For #{path}" do
Expand All @@ -233,6 +243,15 @@
it 'starts with `new_`, `fix_`, or `change_`' do
expect(File.basename(path)).to(match(/\A(new|fix|change)_.+/))
end

it 'has valid cop name with backticks', :aggregate_failures do
entries.each do |entry|
entry.scan(%r{\b[A-Z]\w+(?:/[A-Z]\w+)+\b}) do |cop_name|
expect(allowed_cop_names.include?(cop_name)).to be(true), "Invalid cop name #{cop_name}."
expect(entry.include?("`#{cop_name}`")).to be(true), "Missing backticks for #{cop_name}."
end
end
end
end
end
end
Expand Down

0 comments on commit 1358bb0

Please sign in to comment.