-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
empty_metadata.rb
46 lines (39 loc) · 988 Bytes
/
empty_metadata.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Avoid empty metadata hash.
#
# @example EnforcedStyle: symbol (default)
# # bad
# describe 'Something', {}
#
# # good
# describe 'Something'
class EmptyMetadata < Base
extend AutoCorrector
include Metadata
include RangeHelp
MSG = 'Avoid empty metadata hash.'
def on_metadata(_symbols, hash)
return unless hash&.pairs&.empty?
add_offense(hash) do |corrector|
remove_empty_metadata(corrector, hash)
end
end
private
def remove_empty_metadata(corrector, node)
corrector.remove(
range_with_surrounding_comma(
range_with_surrounding_space(
node.source_range,
side: :left
),
:left
)
)
end
end
end
end
end