Skip to content

Commit ac7c678

Browse files
authored
Merge pull request #15 from ksss/EnforcedStylePrototypeName
Support EnforcedStylePrototypeName
2 parents 50a69b9 + 338ee84 commit ac7c678

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

config/default.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ YARD/MismatchName:
3030
Description: 'Check @param and @option name and method parameters'
3131
Enabled: true
3232
VersionAdded: '0.3.0'
33+
EnforcedStylePrototypeName: after
34+
SupportedStylesPrototypeName:
35+
- before
36+
- after
37+

lib/rubocop/cop/yard/mismatch_name.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,34 @@ def on_def(node)
102102
def tag_prototype(argument)
103103
case argument.type
104104
when :kwrestarg
105-
"@param [Hash{Symbol => Object}] #{argument.name}"
105+
case cop_config_prototype_name
106+
when "before"
107+
"@param #{argument.name} [Hash{Symbol => Object}]"
108+
when "after"
109+
"@param [Hash{Symbol => Object}] #{argument.name}"
110+
end
106111
when :restarg
107-
"@param [Array<Object>] #{argument.name}"
112+
case cop_config_prototype_name
113+
when "before"
114+
"@param #{argument.name} [Array<Object>]"
115+
when "after"
116+
"@param [Array<Object>] #{argument.name}"
117+
end
108118
else
109-
"@param [Object] #{argument.name}"
119+
case cop_config_prototype_name
120+
when "before"
121+
"@param #{argument.name} [Object]"
122+
when "after"
123+
"@param [Object] #{argument.name}"
124+
end
125+
end
126+
end
127+
128+
def cop_config_prototype_name
129+
@cop_config_prototype_name ||= cop_config["EnforcedStylePrototypeName"].tap do |c|
130+
unless cop_config["SupportedStylesPrototypeName"].include?(c)
131+
raise "unsupported style #{c}"
132+
end
110133
end
111134
end
112135

0 commit comments

Comments
 (0)