From 8031a45a7a578646bd9f29e24aa22fea6962e3d7 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 09:55:18 -0600 Subject: [PATCH 01/16] Fix CI typo --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 343704f..dc0e6a9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -44,7 +44,7 @@ jobs: - uses: julia-actions/setup-julia@v2 with: version: "1" - - name: ainstall dependencies + - name: Install dependencies shell: julia --color=yes --project=docs {0} run: | using Pkg From fdd66e8b260ebc26b085238f8ac97c85a05a467a Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 09:55:28 -0600 Subject: [PATCH 02/16] Set permissions for documentation --- .github/workflows/CI.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index dc0e6a9..cb74c88 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -36,8 +36,15 @@ jobs: with: files: lcov.info + # https://documenter.juliadocs.org/stable/man/hosting/#GitHub-Actions docs: name: Documentation + # These permissions are needed to: + # - Use deploy the documentation: https://documenter.juliadocs.org/stable/man/hosting/#Permissions + permissions: + contents: write + pull-requests: read + statuses: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 86c01b4921591979f571f32cdb65ac8ca9feebf1 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 09:56:03 -0600 Subject: [PATCH 03/16] Use julia-format action --- .JuliaFormatter.toml | 1 + .github/workflows/Format.yml | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .JuliaFormatter.toml create mode 100644 .github/workflows/Format.yml diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml new file mode 100644 index 0000000..323237b --- /dev/null +++ b/.JuliaFormatter.toml @@ -0,0 +1 @@ +style = "blue" diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml new file mode 100644 index 0000000..4d4782a --- /dev/null +++ b/.github/workflows/Format.yml @@ -0,0 +1,15 @@ +--- +name: Format +on: + pull_request: + types: [opened, reopened, synchronize, labeled, unlabeled] + paths: + - "**/*.jl" +jobs: + code-style: + runs-on: ubuntu-latest + steps: + - uses: julia-actions/julia-format@v3 + with: + version: "1" + suggestion-label: format-suggest From 6ee1011b07cc109adcf8e30910cd2e99ed7d1ad9 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 09:58:10 -0600 Subject: [PATCH 04/16] Enable self-test --- .github/workflows/Format.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index 4d4782a..cb3acf2 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -5,6 +5,7 @@ on: types: [opened, reopened, synchronize, labeled, unlabeled] paths: - "**/*.jl" + - ".github/workflows/Format.yml" jobs: code-style: runs-on: ubuntu-latest From d9905d9b77048cb83d4670579226369d0a61194d Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:09:30 -0600 Subject: [PATCH 05/16] Test suggestions --- .github/workflows/Format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index cb3acf2..3ab4cea 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -13,4 +13,4 @@ jobs: - uses: julia-actions/julia-format@v3 with: version: "1" - suggestion-label: format-suggest + suggestion-label: "" # format-suggest From 6119c93c43abeb80bdfdb6f9bf1e573bd926d3c9 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:19:30 -0600 Subject: [PATCH 06/16] Fix formatting --- docs/make.jl | 6 ++---- src/MultilineStrings.jl | 9 +++++++-- src/indent.jl | 6 +++--- test/runtests.jl | 27 ++++++++++++++------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 73c163c..7ead8c5 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,10 +5,8 @@ const IS_CI = get(ENV, "CI", nothing) == "true" makedocs(; modules=[MultilineStrings], - format=Documenter.HTML(prettyurls=IS_CI), - pages=[ - "Home" => "index.md", - ], + format=Documenter.HTML(; prettyurls=IS_CI), + pages=["Home" => "index.md"], sitename="MultilineStrings.jl", checkdocs=:exports, linkcheck=true, diff --git a/src/MultilineStrings.jl b/src/MultilineStrings.jl index 0f46f2a..72301ef 100644 --- a/src/MultilineStrings.jl +++ b/src/MultilineStrings.jl @@ -20,7 +20,7 @@ to YAML multiline strings (also known as block scalars). or keep all newlines from the end (`:keep`) """ function multiline(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP) - multiline(str, style, chomp) + return multiline(str, style, chomp) end """ @@ -173,7 +173,12 @@ function _process_indicators(indicators::AbstractString) '\0', '\0' end - if style_char != '\0' && chomp_char != '\0' && isletter(style_char) ⊻ isletter(chomp_char) + mixed_indicators = ( + style_char != '\0' && + chomp_char != '\0' && + isletter(style_char) ⊻ isletter(chomp_char) + ) + if mixed_indicators throw(ArgumentError("Can't mix YAML style block indicators with letter indicators")) end diff --git a/src/indent.jl b/src/indent.jl index 01b9aea..fdb3bd6 100644 --- a/src/indent.jl +++ b/src/indent.jl @@ -17,8 +17,8 @@ See also `Base.unindent` and `Base.indentation`. function indent(str::AbstractString, n::Int) n == 0 && return str # Note: this loses the type of the original string - buf = IOBuffer(sizehint=sizeof(str)) - indent_str = ' ' ^ n + buf = IOBuffer(; sizehint=sizeof(str)) + indent_str = ' '^n line_start = firstindex(str) blank_line = true @@ -38,5 +38,5 @@ function indent(str::AbstractString, n::Int) !blank_line && print(buf, indent_str) print(buf, SubString(str, line_start, lastindex(str))) - String(take!(buf)) + return String(take!(buf)) end diff --git a/test/runtests.jl b/test/runtests.jl index c822d37..daa9980 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using YAML: YAML function yaml_block(str, block_scalar) yaml = "example: $block_scalar\n$(indent(str, 2))" - YAML.load(yaml)["example"] + return YAML.load(yaml)["example"] end const TEST_STRINGS = [ @@ -51,9 +51,9 @@ end @test multiline(str, :literal, :clip) == expected_lc @test multiline(str, :literal, :strip) == expected_ls - @test multiline(str, style=:literal, chomp=:keep) == expected_lk - @test multiline(str, style=:literal, chomp=:clip) == expected_lc - @test multiline(str, style=:literal, chomp=:strip) == expected_ls + @test multiline(str; style=:literal, chomp=:keep) == expected_lk + @test multiline(str; style=:literal, chomp=:clip) == expected_lc + @test multiline(str; style=:literal, chomp=:strip) == expected_ls @test multiline(str, "lk") == expected_lk @test multiline(str, "lc") == expected_lc @@ -68,9 +68,9 @@ end @test multiline(str, :folded, :clip) == expected_fc @test multiline(str, :folded, :strip) == expected_fs - @test multiline(str, style=:folded, chomp=:keep) == expected_fk - @test multiline(str, style=:folded, chomp=:clip) == expected_fc - @test multiline(str, style=:folded, chomp=:strip) == expected_fs + @test multiline(str; style=:folded, chomp=:keep) == expected_fk + @test multiline(str; style=:folded, chomp=:clip) == expected_fc + @test multiline(str; style=:folded, chomp=:strip) == expected_fs @test multiline(str, "fk") == expected_fk @test multiline(str, "fc") == expected_fc @@ -81,8 +81,8 @@ end end @testset "default chomp" begin - @test multiline(str, style=:literal) == expected_ls - @test multiline(str, style=:folded) == expected_fs + @test multiline(str; style=:literal) == expected_ls + @test multiline(str; style=:folded) == expected_fs @test multiline(str, "l") == expected_ls @test multiline(str, "f") == expected_fs @@ -92,9 +92,9 @@ end end @testset "default style" begin - @test multiline(str, chomp=:keep) == expected_fk - @test multiline(str, chomp=:clip) == expected_fc - @test multiline(str, chomp=:strip) == expected_fs + @test multiline(str; chomp=:keep) == expected_fk + @test multiline(str; chomp=:clip) == expected_fc + @test multiline(str; chomp=:strip) == expected_fs @test multiline(str, "k") == expected_fk @test multiline(str, "c") == expected_fc @@ -131,7 +131,8 @@ end # The quoting in these examples can result in exceptions being raised during parsing # if handled incorrectly. @test interpolate("\"\\n\"") == "\"\\n\"" - @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", "))) + @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == + Expr(:string, :(join(["a", "b"], ", "))) end @testset "@m_str" begin From bc766497d0612954dc1e614c5d26e7689553aac5 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:20:23 -0600 Subject: [PATCH 07/16] Always show suggestions --- .github/workflows/Format.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index 3ab4cea..4f1a7b6 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -13,4 +13,3 @@ jobs: - uses: julia-actions/julia-format@v3 with: version: "1" - suggestion-label: "" # format-suggest From efea35b6ecb19c2671a99fa04d4ee5317163f26b Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:29:53 -0600 Subject: [PATCH 08/16] Roll our own --- .github/workflows/Format.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index 4f1a7b6..f088948 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -1,8 +1,8 @@ --- +# Ideally would use https://github.com/julia-actions/julia-format in the future name: Format on: pull_request: - types: [opened, reopened, synchronize, labeled, unlabeled] paths: - "**/*.jl" - ".github/workflows/Format.yml" @@ -10,6 +10,21 @@ jobs: code-style: runs-on: ubuntu-latest steps: - - uses: julia-actions/julia-format@v3 + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + - uses: julia-actions/cache@v2 + - name: Install JuliaFormatter + shell: julia --color=yes {0} + run: | + import Pkg + Pkg.add("JuliaFormatter@1") + - name: Check formatting + shell: julia --color=yes {0} + run: | + using JuliaFormatter + format(".") || exit(1) + # Add formatting suggestions to non-draft PRs even if when "Check formatting" fails + - uses: reviewdog/action-suggester@a3026c6020837c23b61a79d12db223a00df19e6a # v1.19.0 + if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.draft == false }} with: - version: "1" + tool_name: JuliaFormatter From ae729e9354c211b35f96b80c16013d3e9e9dc3bf Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:30:02 -0600 Subject: [PATCH 09/16] Revert "Fix formatting" This reverts commit 6119c93c43abeb80bdfdb6f9bf1e573bd926d3c9. --- docs/make.jl | 6 ++++-- src/MultilineStrings.jl | 9 ++------- src/indent.jl | 6 +++--- test/runtests.jl | 27 +++++++++++++-------------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 7ead8c5..73c163c 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,8 +5,10 @@ const IS_CI = get(ENV, "CI", nothing) == "true" makedocs(; modules=[MultilineStrings], - format=Documenter.HTML(; prettyurls=IS_CI), - pages=["Home" => "index.md"], + format=Documenter.HTML(prettyurls=IS_CI), + pages=[ + "Home" => "index.md", + ], sitename="MultilineStrings.jl", checkdocs=:exports, linkcheck=true, diff --git a/src/MultilineStrings.jl b/src/MultilineStrings.jl index 72301ef..0f46f2a 100644 --- a/src/MultilineStrings.jl +++ b/src/MultilineStrings.jl @@ -20,7 +20,7 @@ to YAML multiline strings (also known as block scalars). or keep all newlines from the end (`:keep`) """ function multiline(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP) - return multiline(str, style, chomp) + multiline(str, style, chomp) end """ @@ -173,12 +173,7 @@ function _process_indicators(indicators::AbstractString) '\0', '\0' end - mixed_indicators = ( - style_char != '\0' && - chomp_char != '\0' && - isletter(style_char) ⊻ isletter(chomp_char) - ) - if mixed_indicators + if style_char != '\0' && chomp_char != '\0' && isletter(style_char) ⊻ isletter(chomp_char) throw(ArgumentError("Can't mix YAML style block indicators with letter indicators")) end diff --git a/src/indent.jl b/src/indent.jl index fdb3bd6..01b9aea 100644 --- a/src/indent.jl +++ b/src/indent.jl @@ -17,8 +17,8 @@ See also `Base.unindent` and `Base.indentation`. function indent(str::AbstractString, n::Int) n == 0 && return str # Note: this loses the type of the original string - buf = IOBuffer(; sizehint=sizeof(str)) - indent_str = ' '^n + buf = IOBuffer(sizehint=sizeof(str)) + indent_str = ' ' ^ n line_start = firstindex(str) blank_line = true @@ -38,5 +38,5 @@ function indent(str::AbstractString, n::Int) !blank_line && print(buf, indent_str) print(buf, SubString(str, line_start, lastindex(str))) - return String(take!(buf)) + String(take!(buf)) end diff --git a/test/runtests.jl b/test/runtests.jl index daa9980..c822d37 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using YAML: YAML function yaml_block(str, block_scalar) yaml = "example: $block_scalar\n$(indent(str, 2))" - return YAML.load(yaml)["example"] + YAML.load(yaml)["example"] end const TEST_STRINGS = [ @@ -51,9 +51,9 @@ end @test multiline(str, :literal, :clip) == expected_lc @test multiline(str, :literal, :strip) == expected_ls - @test multiline(str; style=:literal, chomp=:keep) == expected_lk - @test multiline(str; style=:literal, chomp=:clip) == expected_lc - @test multiline(str; style=:literal, chomp=:strip) == expected_ls + @test multiline(str, style=:literal, chomp=:keep) == expected_lk + @test multiline(str, style=:literal, chomp=:clip) == expected_lc + @test multiline(str, style=:literal, chomp=:strip) == expected_ls @test multiline(str, "lk") == expected_lk @test multiline(str, "lc") == expected_lc @@ -68,9 +68,9 @@ end @test multiline(str, :folded, :clip) == expected_fc @test multiline(str, :folded, :strip) == expected_fs - @test multiline(str; style=:folded, chomp=:keep) == expected_fk - @test multiline(str; style=:folded, chomp=:clip) == expected_fc - @test multiline(str; style=:folded, chomp=:strip) == expected_fs + @test multiline(str, style=:folded, chomp=:keep) == expected_fk + @test multiline(str, style=:folded, chomp=:clip) == expected_fc + @test multiline(str, style=:folded, chomp=:strip) == expected_fs @test multiline(str, "fk") == expected_fk @test multiline(str, "fc") == expected_fc @@ -81,8 +81,8 @@ end end @testset "default chomp" begin - @test multiline(str; style=:literal) == expected_ls - @test multiline(str; style=:folded) == expected_fs + @test multiline(str, style=:literal) == expected_ls + @test multiline(str, style=:folded) == expected_fs @test multiline(str, "l") == expected_ls @test multiline(str, "f") == expected_fs @@ -92,9 +92,9 @@ end end @testset "default style" begin - @test multiline(str; chomp=:keep) == expected_fk - @test multiline(str; chomp=:clip) == expected_fc - @test multiline(str; chomp=:strip) == expected_fs + @test multiline(str, chomp=:keep) == expected_fk + @test multiline(str, chomp=:clip) == expected_fc + @test multiline(str, chomp=:strip) == expected_fs @test multiline(str, "k") == expected_fk @test multiline(str, "c") == expected_fc @@ -131,8 +131,7 @@ end # The quoting in these examples can result in exceptions being raised during parsing # if handled incorrectly. @test interpolate("\"\\n\"") == "\"\\n\"" - @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == - Expr(:string, :(join(["a", "b"], ", "))) + @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", "))) end @testset "@m_str" begin From a2df8310b7a6d98535c0a303d08d22f9cc541ca8 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:31:23 -0600 Subject: [PATCH 10/16] fixup! Roll our own --- .github/workflows/Format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index f088948..f45c1d7 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -17,7 +17,7 @@ jobs: shell: julia --color=yes {0} run: | import Pkg - Pkg.add("JuliaFormatter@1") + Pkg.add(PackageSpec(name="JuliaFormatter", version="1")) - name: Check formatting shell: julia --color=yes {0} run: | From 6cce44dbd4347b3cdf02a36349fd5fb97dd99e8a Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:32:39 -0600 Subject: [PATCH 11/16] fixup! Roll our own --- .github/workflows/Format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index f45c1d7..40488db 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -17,7 +17,7 @@ jobs: shell: julia --color=yes {0} run: | import Pkg - Pkg.add(PackageSpec(name="JuliaFormatter", version="1")) + Pkg.add(Pkg.PackageSpec(; name="JuliaFormatter", version="1")) - name: Check formatting shell: julia --color=yes {0} run: | From 538ea5f2a667f7eb5e8d12c290db1485443dcdff Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:34:25 -0600 Subject: [PATCH 12/16] fixup! Roll our own --- .github/workflows/Format.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index 40488db..2ffb7a2 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -3,6 +3,7 @@ name: Format on: pull_request: + types: [opened, synchronize, reopened, ready_for_review] paths: - "**/*.jl" - ".github/workflows/Format.yml" From 53b88d024f148ef06c91b8f4dc9a64f8629fc6e8 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:19:30 -0600 Subject: [PATCH 13/16] Fix formatting --- docs/make.jl | 6 ++---- src/MultilineStrings.jl | 9 +++++++-- src/indent.jl | 6 +++--- test/runtests.jl | 27 ++++++++++++++------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 73c163c..7ead8c5 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,10 +5,8 @@ const IS_CI = get(ENV, "CI", nothing) == "true" makedocs(; modules=[MultilineStrings], - format=Documenter.HTML(prettyurls=IS_CI), - pages=[ - "Home" => "index.md", - ], + format=Documenter.HTML(; prettyurls=IS_CI), + pages=["Home" => "index.md"], sitename="MultilineStrings.jl", checkdocs=:exports, linkcheck=true, diff --git a/src/MultilineStrings.jl b/src/MultilineStrings.jl index 0f46f2a..72301ef 100644 --- a/src/MultilineStrings.jl +++ b/src/MultilineStrings.jl @@ -20,7 +20,7 @@ to YAML multiline strings (also known as block scalars). or keep all newlines from the end (`:keep`) """ function multiline(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP) - multiline(str, style, chomp) + return multiline(str, style, chomp) end """ @@ -173,7 +173,12 @@ function _process_indicators(indicators::AbstractString) '\0', '\0' end - if style_char != '\0' && chomp_char != '\0' && isletter(style_char) ⊻ isletter(chomp_char) + mixed_indicators = ( + style_char != '\0' && + chomp_char != '\0' && + isletter(style_char) ⊻ isletter(chomp_char) + ) + if mixed_indicators throw(ArgumentError("Can't mix YAML style block indicators with letter indicators")) end diff --git a/src/indent.jl b/src/indent.jl index 01b9aea..fdb3bd6 100644 --- a/src/indent.jl +++ b/src/indent.jl @@ -17,8 +17,8 @@ See also `Base.unindent` and `Base.indentation`. function indent(str::AbstractString, n::Int) n == 0 && return str # Note: this loses the type of the original string - buf = IOBuffer(sizehint=sizeof(str)) - indent_str = ' ' ^ n + buf = IOBuffer(; sizehint=sizeof(str)) + indent_str = ' '^n line_start = firstindex(str) blank_line = true @@ -38,5 +38,5 @@ function indent(str::AbstractString, n::Int) !blank_line && print(buf, indent_str) print(buf, SubString(str, line_start, lastindex(str))) - String(take!(buf)) + return String(take!(buf)) end diff --git a/test/runtests.jl b/test/runtests.jl index c822d37..daa9980 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using YAML: YAML function yaml_block(str, block_scalar) yaml = "example: $block_scalar\n$(indent(str, 2))" - YAML.load(yaml)["example"] + return YAML.load(yaml)["example"] end const TEST_STRINGS = [ @@ -51,9 +51,9 @@ end @test multiline(str, :literal, :clip) == expected_lc @test multiline(str, :literal, :strip) == expected_ls - @test multiline(str, style=:literal, chomp=:keep) == expected_lk - @test multiline(str, style=:literal, chomp=:clip) == expected_lc - @test multiline(str, style=:literal, chomp=:strip) == expected_ls + @test multiline(str; style=:literal, chomp=:keep) == expected_lk + @test multiline(str; style=:literal, chomp=:clip) == expected_lc + @test multiline(str; style=:literal, chomp=:strip) == expected_ls @test multiline(str, "lk") == expected_lk @test multiline(str, "lc") == expected_lc @@ -68,9 +68,9 @@ end @test multiline(str, :folded, :clip) == expected_fc @test multiline(str, :folded, :strip) == expected_fs - @test multiline(str, style=:folded, chomp=:keep) == expected_fk - @test multiline(str, style=:folded, chomp=:clip) == expected_fc - @test multiline(str, style=:folded, chomp=:strip) == expected_fs + @test multiline(str; style=:folded, chomp=:keep) == expected_fk + @test multiline(str; style=:folded, chomp=:clip) == expected_fc + @test multiline(str; style=:folded, chomp=:strip) == expected_fs @test multiline(str, "fk") == expected_fk @test multiline(str, "fc") == expected_fc @@ -81,8 +81,8 @@ end end @testset "default chomp" begin - @test multiline(str, style=:literal) == expected_ls - @test multiline(str, style=:folded) == expected_fs + @test multiline(str; style=:literal) == expected_ls + @test multiline(str; style=:folded) == expected_fs @test multiline(str, "l") == expected_ls @test multiline(str, "f") == expected_fs @@ -92,9 +92,9 @@ end end @testset "default style" begin - @test multiline(str, chomp=:keep) == expected_fk - @test multiline(str, chomp=:clip) == expected_fc - @test multiline(str, chomp=:strip) == expected_fs + @test multiline(str; chomp=:keep) == expected_fk + @test multiline(str; chomp=:clip) == expected_fc + @test multiline(str; chomp=:strip) == expected_fs @test multiline(str, "k") == expected_fk @test multiline(str, "c") == expected_fc @@ -131,7 +131,8 @@ end # The quoting in these examples can result in exceptions being raised during parsing # if handled incorrectly. @test interpolate("\"\\n\"") == "\"\\n\"" - @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", "))) + @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == + Expr(:string, :(join(["a", "b"], ", "))) end @testset "@m_str" begin From 8d69a794d10a25534bd63315574d98e15fb1a351 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:45:43 -0600 Subject: [PATCH 14/16] Set filter mode --- .github/workflows/Format.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index 2ffb7a2..64ae3bb 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -29,3 +29,4 @@ jobs: if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.draft == false }} with: tool_name: JuliaFormatter + filter_mode: nofilter # Post results on all results and not just changed files: https://github.com/reviewdog/reviewdog#filter-mode From a0735d70b0fbd1c781018b91606e2c4da9b66e84 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:45:54 -0600 Subject: [PATCH 15/16] Revert "Fix formatting" This reverts commit 53b88d024f148ef06c91b8f4dc9a64f8629fc6e8. --- docs/make.jl | 6 ++++-- src/MultilineStrings.jl | 9 ++------- src/indent.jl | 6 +++--- test/runtests.jl | 27 +++++++++++++-------------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 7ead8c5..73c163c 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,8 +5,10 @@ const IS_CI = get(ENV, "CI", nothing) == "true" makedocs(; modules=[MultilineStrings], - format=Documenter.HTML(; prettyurls=IS_CI), - pages=["Home" => "index.md"], + format=Documenter.HTML(prettyurls=IS_CI), + pages=[ + "Home" => "index.md", + ], sitename="MultilineStrings.jl", checkdocs=:exports, linkcheck=true, diff --git a/src/MultilineStrings.jl b/src/MultilineStrings.jl index 72301ef..0f46f2a 100644 --- a/src/MultilineStrings.jl +++ b/src/MultilineStrings.jl @@ -20,7 +20,7 @@ to YAML multiline strings (also known as block scalars). or keep all newlines from the end (`:keep`) """ function multiline(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP) - return multiline(str, style, chomp) + multiline(str, style, chomp) end """ @@ -173,12 +173,7 @@ function _process_indicators(indicators::AbstractString) '\0', '\0' end - mixed_indicators = ( - style_char != '\0' && - chomp_char != '\0' && - isletter(style_char) ⊻ isletter(chomp_char) - ) - if mixed_indicators + if style_char != '\0' && chomp_char != '\0' && isletter(style_char) ⊻ isletter(chomp_char) throw(ArgumentError("Can't mix YAML style block indicators with letter indicators")) end diff --git a/src/indent.jl b/src/indent.jl index fdb3bd6..01b9aea 100644 --- a/src/indent.jl +++ b/src/indent.jl @@ -17,8 +17,8 @@ See also `Base.unindent` and `Base.indentation`. function indent(str::AbstractString, n::Int) n == 0 && return str # Note: this loses the type of the original string - buf = IOBuffer(; sizehint=sizeof(str)) - indent_str = ' '^n + buf = IOBuffer(sizehint=sizeof(str)) + indent_str = ' ' ^ n line_start = firstindex(str) blank_line = true @@ -38,5 +38,5 @@ function indent(str::AbstractString, n::Int) !blank_line && print(buf, indent_str) print(buf, SubString(str, line_start, lastindex(str))) - return String(take!(buf)) + String(take!(buf)) end diff --git a/test/runtests.jl b/test/runtests.jl index daa9980..c822d37 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using YAML: YAML function yaml_block(str, block_scalar) yaml = "example: $block_scalar\n$(indent(str, 2))" - return YAML.load(yaml)["example"] + YAML.load(yaml)["example"] end const TEST_STRINGS = [ @@ -51,9 +51,9 @@ end @test multiline(str, :literal, :clip) == expected_lc @test multiline(str, :literal, :strip) == expected_ls - @test multiline(str; style=:literal, chomp=:keep) == expected_lk - @test multiline(str; style=:literal, chomp=:clip) == expected_lc - @test multiline(str; style=:literal, chomp=:strip) == expected_ls + @test multiline(str, style=:literal, chomp=:keep) == expected_lk + @test multiline(str, style=:literal, chomp=:clip) == expected_lc + @test multiline(str, style=:literal, chomp=:strip) == expected_ls @test multiline(str, "lk") == expected_lk @test multiline(str, "lc") == expected_lc @@ -68,9 +68,9 @@ end @test multiline(str, :folded, :clip) == expected_fc @test multiline(str, :folded, :strip) == expected_fs - @test multiline(str; style=:folded, chomp=:keep) == expected_fk - @test multiline(str; style=:folded, chomp=:clip) == expected_fc - @test multiline(str; style=:folded, chomp=:strip) == expected_fs + @test multiline(str, style=:folded, chomp=:keep) == expected_fk + @test multiline(str, style=:folded, chomp=:clip) == expected_fc + @test multiline(str, style=:folded, chomp=:strip) == expected_fs @test multiline(str, "fk") == expected_fk @test multiline(str, "fc") == expected_fc @@ -81,8 +81,8 @@ end end @testset "default chomp" begin - @test multiline(str; style=:literal) == expected_ls - @test multiline(str; style=:folded) == expected_fs + @test multiline(str, style=:literal) == expected_ls + @test multiline(str, style=:folded) == expected_fs @test multiline(str, "l") == expected_ls @test multiline(str, "f") == expected_fs @@ -92,9 +92,9 @@ end end @testset "default style" begin - @test multiline(str; chomp=:keep) == expected_fk - @test multiline(str; chomp=:clip) == expected_fc - @test multiline(str; chomp=:strip) == expected_fs + @test multiline(str, chomp=:keep) == expected_fk + @test multiline(str, chomp=:clip) == expected_fc + @test multiline(str, chomp=:strip) == expected_fs @test multiline(str, "k") == expected_fk @test multiline(str, "c") == expected_fc @@ -131,8 +131,7 @@ end # The quoting in these examples can result in exceptions being raised during parsing # if handled incorrectly. @test interpolate("\"\\n\"") == "\"\\n\"" - @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == - Expr(:string, :(join(["a", "b"], ", "))) + @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", "))) end @testset "@m_str" begin From 7d40b025f8f28e8b00c6de3a9299025e6f127805 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Tue, 18 Feb 2025 10:19:30 -0600 Subject: [PATCH 16/16] Fix formatting --- docs/make.jl | 6 ++---- src/MultilineStrings.jl | 9 +++++++-- src/indent.jl | 6 +++--- test/runtests.jl | 27 ++++++++++++++------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 73c163c..7ead8c5 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,10 +5,8 @@ const IS_CI = get(ENV, "CI", nothing) == "true" makedocs(; modules=[MultilineStrings], - format=Documenter.HTML(prettyurls=IS_CI), - pages=[ - "Home" => "index.md", - ], + format=Documenter.HTML(; prettyurls=IS_CI), + pages=["Home" => "index.md"], sitename="MultilineStrings.jl", checkdocs=:exports, linkcheck=true, diff --git a/src/MultilineStrings.jl b/src/MultilineStrings.jl index 0f46f2a..72301ef 100644 --- a/src/MultilineStrings.jl +++ b/src/MultilineStrings.jl @@ -20,7 +20,7 @@ to YAML multiline strings (also known as block scalars). or keep all newlines from the end (`:keep`) """ function multiline(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP) - multiline(str, style, chomp) + return multiline(str, style, chomp) end """ @@ -173,7 +173,12 @@ function _process_indicators(indicators::AbstractString) '\0', '\0' end - if style_char != '\0' && chomp_char != '\0' && isletter(style_char) ⊻ isletter(chomp_char) + mixed_indicators = ( + style_char != '\0' && + chomp_char != '\0' && + isletter(style_char) ⊻ isletter(chomp_char) + ) + if mixed_indicators throw(ArgumentError("Can't mix YAML style block indicators with letter indicators")) end diff --git a/src/indent.jl b/src/indent.jl index 01b9aea..fdb3bd6 100644 --- a/src/indent.jl +++ b/src/indent.jl @@ -17,8 +17,8 @@ See also `Base.unindent` and `Base.indentation`. function indent(str::AbstractString, n::Int) n == 0 && return str # Note: this loses the type of the original string - buf = IOBuffer(sizehint=sizeof(str)) - indent_str = ' ' ^ n + buf = IOBuffer(; sizehint=sizeof(str)) + indent_str = ' '^n line_start = firstindex(str) blank_line = true @@ -38,5 +38,5 @@ function indent(str::AbstractString, n::Int) !blank_line && print(buf, indent_str) print(buf, SubString(str, line_start, lastindex(str))) - String(take!(buf)) + return String(take!(buf)) end diff --git a/test/runtests.jl b/test/runtests.jl index c822d37..daa9980 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using YAML: YAML function yaml_block(str, block_scalar) yaml = "example: $block_scalar\n$(indent(str, 2))" - YAML.load(yaml)["example"] + return YAML.load(yaml)["example"] end const TEST_STRINGS = [ @@ -51,9 +51,9 @@ end @test multiline(str, :literal, :clip) == expected_lc @test multiline(str, :literal, :strip) == expected_ls - @test multiline(str, style=:literal, chomp=:keep) == expected_lk - @test multiline(str, style=:literal, chomp=:clip) == expected_lc - @test multiline(str, style=:literal, chomp=:strip) == expected_ls + @test multiline(str; style=:literal, chomp=:keep) == expected_lk + @test multiline(str; style=:literal, chomp=:clip) == expected_lc + @test multiline(str; style=:literal, chomp=:strip) == expected_ls @test multiline(str, "lk") == expected_lk @test multiline(str, "lc") == expected_lc @@ -68,9 +68,9 @@ end @test multiline(str, :folded, :clip) == expected_fc @test multiline(str, :folded, :strip) == expected_fs - @test multiline(str, style=:folded, chomp=:keep) == expected_fk - @test multiline(str, style=:folded, chomp=:clip) == expected_fc - @test multiline(str, style=:folded, chomp=:strip) == expected_fs + @test multiline(str; style=:folded, chomp=:keep) == expected_fk + @test multiline(str; style=:folded, chomp=:clip) == expected_fc + @test multiline(str; style=:folded, chomp=:strip) == expected_fs @test multiline(str, "fk") == expected_fk @test multiline(str, "fc") == expected_fc @@ -81,8 +81,8 @@ end end @testset "default chomp" begin - @test multiline(str, style=:literal) == expected_ls - @test multiline(str, style=:folded) == expected_fs + @test multiline(str; style=:literal) == expected_ls + @test multiline(str; style=:folded) == expected_fs @test multiline(str, "l") == expected_ls @test multiline(str, "f") == expected_fs @@ -92,9 +92,9 @@ end end @testset "default style" begin - @test multiline(str, chomp=:keep) == expected_fk - @test multiline(str, chomp=:clip) == expected_fc - @test multiline(str, chomp=:strip) == expected_fs + @test multiline(str; chomp=:keep) == expected_fk + @test multiline(str; chomp=:clip) == expected_fc + @test multiline(str; chomp=:strip) == expected_fs @test multiline(str, "k") == expected_fk @test multiline(str, "c") == expected_fc @@ -131,7 +131,8 @@ end # The quoting in these examples can result in exceptions being raised during parsing # if handled incorrectly. @test interpolate("\"\\n\"") == "\"\\n\"" - @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", "))) + @test interpolate("\$(join([\"a\", \"b\"], \", \"))") == + Expr(:string, :(join(["a", "b"], ", "))) end @testset "@m_str" begin