Skip to content

Commit f87db42

Browse files
committed
Guard with enforce_triplequote_docstring option.
1 parent 56ea001 commit f87db42

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

docs/src/formatting_options.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ If you absolutely must enable them, you may need to run the formatter multiple t
6464
| [`annotate_untyped_fields_with_any`](@ref options-annotate-untyped-fields-with-any) | ⚠️ | `true` | `true` | **`false`** | `true` | **`false`** |
6565
| [`conditional_to_if`](@ref options-conditional-to-if) | 🪃 ♻️ | `false` | `false` | **`true`** | `false` | `false` |
6666
| [`disallow_single_arg_nesting`](@ref options-disallow-single-arg-nesting) | 📐 | `false` | `false` | `false` | **`true`** | `false` |
67+
| [`enforce_triplequote_docstring`](@ref options-enforce-triplequote-docstring) | ⚠️ | `true` | `true` | `true` | `true` | `true` |
6768
| [`for_in_replacement`](@ref options-for-in-replacement) | ♻️ | `"in"` | `"in"` | `"in"` | `"in"` | `"in"` |
6869
| [`force_long_function_def`](@ref options-force-long-function-def) | ⚠️ | `false` | `false` | `false` | `false` | `false` |
6970
| [`format_docstrings`](@ref options-format-docstrings) | ⚠️ | `false` | `false` | `false` | `false` | `false` |
@@ -330,6 +331,14 @@ function_call("String argument")
330331
{key => value("String value")}
331332
```
332333

334+
## [`enforce_triplequote_docstring`](@id options-enforce-triplequote-docstring)
335+
336+
Default: `true`
337+
338+
Ensure that docstrings always use triple `"""` quoting marks.
339+
340+
Only useful if [`format_docstrings`](@ref options-format-docstrings) is on.
341+
333342
## [`for_in_replacement`](@id options-for-in-replacement)
334343

335344
Can be used when [`always_for_in`](@ref options-always-for-in) is `true` to replace the default `in` with `` (`\\in`),

src/format_docstring.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ end
5151
function format_docstring(style::AbstractStyle, state::State, text::AbstractString)
5252
state_indent = state.indent
5353
start_boundary = findfirst(!=('"'), text)
54-
is_triple_quoted = let
54+
is_triple_quoted = state.opts.enforce_triplequote_docstring || let
5555
# Assuming well-formedness, the string is triple-quoted iif
5656
# the chars after/before (o)pening/(c)losing quotes are also quotes.
5757
o, c = map(f -> f(==('"'), text), (findfirst, findlast))

src/options.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Base.@kwdef struct Options{T<:_Unset}
3737
annotate_untyped_fields_with_any::Union{T,Bool} = true
3838
conditional_to_if::Union{T,Bool} = false
3939
disallow_single_arg_nesting::Union{T,Bool} = false
40+
enforce_triplequote_docstring::Union{T,Bool} = true
4041
for_in_replacement::Union{T,String} = "in"
4142
force_long_function_def::Union{T,Bool} = false
4243
format_docstrings::Union{T,Bool} = false

test/argparse.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ using JuliaFormatter: DefaultStyle, YASStyle, BlueStyle, SciMLStyle, MinimalStyl
268268
@test parse_args(["--conditional-to-if=false"]).config.options.conditional_to_if == false
269269
@test parse_args(["--disallow-single-arg-nesting=true"]).config.options.disallow_single_arg_nesting == true
270270
@test parse_args(["--disallow-single-arg-nesting=false"]).config.options.disallow_single_arg_nesting == false
271+
@test parse_args(["--enforce-triplequote-docstring=true"]).config.options.enforce_triplequote_docstring == true
272+
@test parse_args(["--enforce-triplequote-docstring=false"]).config.options.enforce_triplequote_docstring == false
271273
@test parse_args(["--force-long-function-def=true"]).config.options.force_long_function_def == true
272274
@test parse_args(["--force-long-function-def=false"]).config.options.force_long_function_def == false
273275
@test parse_args(["--format-docstrings=true"]).config.options.format_docstrings == true

test/options.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ end
714714

715715
@testset "issue 1203" begin
716716

717-
# Use let blocks to check indentation.
717+
opts = (; format_docstrings = true)
718+
719+
# (use begin blocks to check indentation)
718720
triple = """
719721
begin
720722
\"""
@@ -731,9 +733,13 @@ end
731733
end
732734
"""
733735

734-
test_format(triple, triple; format_docstrings=true)
735-
test_format(single, triple; format_docstrings=true)
736-
test_format(single, single; format_docstrings=true)
736+
# Normalize to triple by default.
737+
test_format(triple, triple; opts...)
738+
test_format(single, triple; opts...)
739+
740+
# Unless we opt out.
741+
opts = (; enforce_triplequote_docstring = false, opts...)
742+
test_format(single, single; opts...)
737743

738744
# Not exactly good taste, but the option leaves it alone as promised.
739745
single_multiline = """
@@ -743,7 +749,7 @@ end
743749
f() = 0
744750
end
745751
"""
746-
test_format(single_multiline, single_multiline; format_docstrings=true)
752+
test_format(single_multiline, single_multiline; opts...)
747753

748754
# Still drop trailing whitespace on the first line (#667).
749755
test_format(
@@ -761,7 +767,7 @@ end
761767
f() = 0 # Can somebody help explain why newlines are being inserted here?
762768
end
763769
""",
764-
; format_docstrings=true)
770+
; opts...)
765771

766772
end
767773

0 commit comments

Comments
 (0)