Merge pull request #15572 from razvanazamfirei/add-emoji-audit
rubocops: add emoji audit
This commit is contained in:
commit
1c081f379d
@ -74,6 +74,9 @@ module RuboCop
|
||||
desc_problem "Description shouldn't end with a full stop."
|
||||
end
|
||||
|
||||
# Check if the desc contains Unicode emojis or symbols (Unicode Other Symbols category).
|
||||
desc_problem "Description shouldn't contain Unicode emojis or symbols." if regex_match_group(desc, /\p{So}/)
|
||||
|
||||
# Check if the desc length exceeds maximum length.
|
||||
return if desc_length <= MAX_DESC_LENGTH
|
||||
|
||||
@ -103,6 +106,7 @@ module RuboCop
|
||||
|
||||
correction.gsub!(/(ommand ?line)/i, "ommand-line")
|
||||
correction.gsub!(/(^|[^a-z])#{@name}([^a-z]|$)/i, "\\1\\2")
|
||||
correction.gsub!(/\s?\p{So}/, "")
|
||||
correction.gsub!(/^\s+/, "")
|
||||
correction.gsub!(/\s+$/, "")
|
||||
correction.gsub!(/\.$/, "")
|
||||
|
||||
@ -110,6 +110,13 @@ describe RuboCop::Cop::Cask::Desc, :config do
|
||||
end
|
||||
RUBY
|
||||
|
||||
expect_offense <<~RUBY
|
||||
cask 'foo' do
|
||||
desc 'Description with a 🍺 symbol'
|
||||
^ Description shouldn't contain Unicode emojis or symbols.
|
||||
end
|
||||
RUBY
|
||||
|
||||
expect_no_offenses <<~RUBY
|
||||
cask 'foo' do
|
||||
desc 'MAC address changer'
|
||||
|
||||
@ -134,6 +134,23 @@ describe RuboCop::Cop::FormulaAudit::Desc do
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "reports and corrects an offense when the description contains Unicode So characters" do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
desc 'Description with a 🍺 symbol'
|
||||
^ FormulaAudit/Desc: Description shouldn't contain Unicode emojis or symbols.
|
||||
end
|
||||
RUBY
|
||||
|
||||
expect_correction(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
desc 'Description with a symbol'
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "does not report an offense when the description ends with 'etc.'" do
|
||||
expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user