Skip to content

Commit c6f3618

Browse files
authored
[1.2.1] Allow disabling default method and param placeholder text (#16)
1 parent d0251d8 commit c6f3618

File tree

5 files changed

+100
-12
lines changed

5 files changed

+100
-12
lines changed

.rubocop_todo.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2026-03-27 10:42:03 UTC using RuboCop version 1.84.0.
3+
# on 2026-03-28 07:58:29 UTC using RuboCop version 1.84.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -16,7 +16,7 @@ Gemspec/DevelopmentDependencies:
1616
# Offense count: 36
1717
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1818
Metrics/AbcSize:
19-
Max: 97
19+
Max: 99
2020

2121
# Offense count: 4
2222
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
@@ -37,17 +37,17 @@ Metrics/ClassLength:
3737
# Offense count: 30
3838
# Configuration parameters: AllowedMethods, AllowedPatterns.
3939
Metrics/CyclomaticComplexity:
40-
Max: 41
40+
Max: 42
4141

4242
# Offense count: 65
4343
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
4444
Metrics/MethodLength:
45-
Max: 105
45+
Max: 110
4646

4747
# Offense count: 6
4848
# Configuration parameters: CountComments, CountAsOne.
4949
Metrics/ModuleLength:
50-
Max: 396
50+
Max: 403
5151

5252
# Offense count: 9
5353
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
@@ -82,21 +82,22 @@ Naming/PredicateMethod:
8282
RSpec/DescribeClass:
8383
Enabled: false
8484

85-
# Offense count: 136
85+
# Offense count: 139
8686
# Configuration parameters: CountAsOne.
8787
RSpec/ExampleLength:
8888
Max: 33
8989

90-
# Offense count: 122
90+
# Offense count: 125
9191
RSpec/MultipleExpectations:
9292
Max: 7
9393

94-
# Offense count: 13
94+
# Offense count: 14
9595
# Configuration parameters: AllowedConstants.
9696
Style/Documentation:
9797
Exclude:
9898
- 'spec/**/*'
9999
- 'test/**/*'
100+
- 'abc.rb'
100101
- 'lib/docscribe/cli.rb'
101102
- 'lib/docscribe/cli/config_builder.rb'
102103
- 'lib/docscribe/cli/init.rb'

lib/docscribe/config/emit.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,21 @@ def param_tag_style
122122
def param_documentation
123123
raw.dig('doc', 'param_documentation') || DEFAULT.dig('doc', 'param_documentation')
124124
end
125+
126+
# Whether to include the default placeholder line:
127+
# # Method documentation.
128+
#
129+
# @return [Boolean]
130+
def include_default_message?
131+
fetch_bool(%w[emit include_default_message], true)
132+
end
133+
134+
# Whether to append placeholder text to generated @param tags:
135+
# # @param [String] name Param documentation.
136+
#
137+
# @return [Boolean]
138+
def include_param_documentation?
139+
fetch_bool(%w[emit include_param_documentation], true)
140+
end
125141
end
126142
end

lib/docscribe/config/template.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ def self.default_yaml
2828
# Emit the header line:
2929
#
3030
# +MyClass#my_method+ -> ReturnType
31-
header: true
31+
header: false
32+
33+
# Whether to include the default placeholder line:
34+
# # Method documentation.
35+
include_default_message: true
36+
37+
# Whether to append placeholder text to generated @param tags:
38+
# # @param [String] name Param documentation.
39+
include_param_documentation: true
3240
3341
# Emit @param tags.
3442
param_tags: true

lib/docscribe/inline_rewriter/doc_builder.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ def build(insertion, config:, signature_provider: nil)
6868
lines << "#{indent}#"
6969
end
7070

71-
lines << "#{indent}# #{config.default_message(scope, visibility)}"
72-
lines << "#{indent}#"
71+
if config.include_default_message?
72+
lines << "#{indent}# #{config.default_message(scope, visibility)}"
73+
lines << "#{indent}#"
74+
end
7375

7476
if config.emit_visibility_tags?
7577
case visibility
@@ -380,7 +382,7 @@ def build_params_lines(node, indent, external_sig:, config:)
380382
fallback_type = config.fallback_type
381383
treat_options_keyword_as_hash = config.treat_options_keyword_as_hash?
382384
param_tag_style = config.param_tag_style
383-
param_documentation = config.param_documentation
385+
param_documentation = config.include_param_documentation? ? config.param_documentation : ''
384386

385387
args =
386388
case node.type

spec/docscribe/inline_rewriter/doc_builder_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,65 @@ def foo(x = 1); x; end
1313
out = inline(code)
1414
expect(out).to include(param_tag('x', 'Integer'))
1515
end
16+
17+
it 'omits the default method message when doc.include_default_message is false' do
18+
conf = Docscribe::Config.new(
19+
'emit' => { 'include_default_message' => false }
20+
)
21+
22+
code = <<~RUBY
23+
class Demo
24+
def bump(foo)
25+
:ok
26+
end
27+
end
28+
RUBY
29+
30+
out = inline(code, config: conf)
31+
32+
expect(out).not_to include('Method documentation.')
33+
expect(out).to include('# @param [Object] foo Param documentation.')
34+
end
35+
36+
it 'omits param placeholder text when doc.include_param_documentation is false' do
37+
conf = Docscribe::Config.new(
38+
'emit' => { 'include_param_documentation' => false }
39+
)
40+
41+
code = <<~RUBY
42+
class Demo
43+
def bump(foo)
44+
:ok
45+
end
46+
end
47+
RUBY
48+
49+
out = inline(code, config: conf)
50+
51+
expect(out).to include('# @param [Object] foo')
52+
expect(out).not_to include('Param documentation.')
53+
end
54+
55+
it 'omits both method and param placeholder text when both flags are false' do
56+
conf = Docscribe::Config.new(
57+
'emit' => {
58+
'include_default_message' => false,
59+
'include_param_documentation' => false
60+
}
61+
)
62+
63+
code = <<~RUBY
64+
class Demo
65+
def bump(foo)
66+
:ok
67+
end
68+
end
69+
RUBY
70+
71+
out = inline(code, config: conf)
72+
73+
expect(out).not_to include('Method documentation.')
74+
expect(out).not_to include('Param documentation.')
75+
expect(out).to include('# @param [Object] foo')
76+
end
1677
end

0 commit comments

Comments
 (0)