Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply JuliaFormatter on the codebase #2404

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
margin = 92
indent = 4
remove_extra_newlines = false
always_use_return = false
short_to_long_function_def = false
always_for_in = false
import_to_using = false
pipe_to_function_call = false
whitespace_ops_in_indices = false
whitespace_in_kwargs = false
whitespace_typedefs = false
annotate_untyped_fields_with_any = false
format_docstrings = false
conditional_to_if = true
normalize_line_endings = "unix"
align_assignment = true
align_struct_field = true
align_pair_arrow = true
align_matrix = true
trailing_comma = "nothing"
23 changes: 13 additions & 10 deletions docs/DocumenterShowcase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,20 @@ function hello(who)
end

struct SVGCircle
stroke :: String
fill :: String
stroke::String
fill::String
end
function Base.show(io, ::MIME"image/svg+xml", c::SVGCircle)
write(io, """
<svg width="50" height="50">
<g style="stroke-width: 3">
<circle cx="25" cy="25" r="24" stroke-width="2" style="stroke: #$(c.stroke); fill: #$(c.fill)" />
</g>
</svg>
""")
write(
io,
"""
<svg width="50" height="50">
<g style="stroke-width: 3">
<circle cx="25" cy="25" r="24" stroke-width="2" style="stroke: #$(c.stroke); fill: #$(c.fill)" />
</g>
</svg>
"""
)
end

"The type definition."
Expand All @@ -109,6 +112,6 @@ struct Foo{T,S} end
Foo() = Foo{Nothing,Nothing}()

"Constructor `Foo{T}()` with one parametric argument."
Foo{T}() where T = Foo{T,Nothing}()
Foo{T}() where {T} = Foo{T,Nothing}()

end # module
2 changes: 1 addition & 1 deletion docs/changelog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ using Changelog
Changelog.generate(
Changelog.CommonMark(),
joinpath(@__DIR__, "..", "CHANGELOG.md");
repo = "JuliaDocs/Documenter.jl",
repo="JuliaDocs/Documenter.jl",
)
8 changes: 5 additions & 3 deletions docs/instantiate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ cd(project_directory) do
@info "DocumenterTools already cloned to dev/DocumenterTools"
run(`git -C dev/DocumenterTools fetch origin`)
else
run(`git clone -n https://github.com/JuliaDocs/DocumenterTools.jl.git dev/DocumenterTools`)
run(
`git clone -n https://github.com/JuliaDocs/DocumenterTools.jl.git dev/DocumenterTools`
)
end
run(`git -C dev/DocumenterTools checkout documenter-v0.1.17+1.0.0`)
Pkg.develop([
PackageSpec(path = documenter_directory),
PackageSpec(path = "dev/DocumenterTools"),
PackageSpec(path=documenter_directory),
PackageSpec(path="dev/DocumenterTools"),
])
Pkg.instantiate()
end
88 changes: 47 additions & 41 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,63 @@ Changelog.generate(
Changelog.Documenter(),
joinpath(@__DIR__, "..", "CHANGELOG.md"),
joinpath(@__DIR__, "src", "release-notes.md");
repo = "JuliaDocs/Documenter.jl",
repo="JuliaDocs/Documenter.jl",
)

makedocs(
modules = [Documenter, DocumenterTools, DocumenterShowcase],
format = if "pdf" in ARGS
Documenter.LaTeX(platform = "docker")
modules=[Documenter, DocumenterTools, DocumenterShowcase],
format=if "pdf" in ARGS
Documenter.LaTeX(platform="docker")
else
Documenter.HTML(
# Use clean URLs, unless built as a "local" build
prettyurls = !("local" in ARGS),
canonical = "https://documenter.juliadocs.org/stable/",
assets = ["assets/favicon.ico"],
analytics = "UA-136089579-2",
highlights = ["yaml"],
ansicolor = true,
size_threshold_ignore = ["release-notes.md"],
prettyurls=!("local" in ARGS),
canonical="https://documenter.juliadocs.org/stable/",
assets=["assets/favicon.ico"],
analytics="UA-136089579-2",
highlights=["yaml"],
ansicolor=true,
size_threshold_ignore=["release-notes.md"],
)
end,
build = ("pdf" in ARGS) ? "build-pdf" : "build",
debug = ("pdf" in ARGS),
sitename = "Documenter.jl",
authors = "Michael Hatherly, Morten Piibeleht, and contributors.",
linkcheck = "linkcheck" in ARGS,
linkcheck_ignore = [
build=("pdf" in ARGS) ? "build-pdf" : "build",
debug=("pdf" in ARGS),
sitename="Documenter.jl",
authors="Michael Hatherly, Morten Piibeleht, and contributors.",
linkcheck="linkcheck" in ARGS,
linkcheck_ignore=[
# We'll ignore links that point to GitHub's edit pages, as they redirect to the
# login screen and cause a warning:
r"https://github.com/([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)/edit(.*)",
"https://nvd.nist.gov/vuln/detail/CVE-2018-16487",
] ∪ (get(ENV, "GITHUB_ACTIONS", nothing) == "true" ? [
# Extra ones we ignore only on CI.
#
# It seems that CTAN blocks GitHub Actions?
"https://ctan.org/pkg/minted",
] : []),
pages = [
] ∪ (
if get(ENV, "GITHUB_ACTIONS", nothing) == "true"
[
# Extra ones we ignore only on CI.
#
# It seems that CTAN blocks GitHub Actions?
"https://ctan.org/pkg/minted",
]
else
[]
end
),
pages=[
"Home" => "index.md",
"Manual" => Any[
"Guide" => "man/guide.md",
"Guide"=>"man/guide.md",
"man/examples.md",
"man/syntax.md",
"man/doctests.md",
"man/latex.md",
hide("man/hosting.md", [
"man/hosting/walkthrough.md"
]),
hide("man/hosting.md", ["man/hosting/walkthrough.md"]),
"man/other-formats.md",
],
"showcase.md",
"Reference" => Any[
"Public API" => "lib/public.md",
"Public API"=>"lib/public.md",
"lib/remote-links.md",
"Semantic versioning" => "lib/semver.md",
"Semantic versioning"=>"lib/semver.md",
],
"Developers" => [
"contributing.md",
Expand All @@ -79,8 +83,8 @@ makedocs(
],
"release-notes.md",
],
warnonly = ("strict=false" in ARGS),
doctest = ("doctest=only" in ARGS) ? :only : true,
warnonly=("strict=false" in ARGS),
doctest=("doctest=only" in ARGS) ? :only : true,
)

if "pdf" in ARGS
Expand All @@ -89,21 +93,23 @@ if "pdf" in ARGS
let files = readdir(joinpath(@__DIR__, "build-pdf"))
for f in files
if startswith(f, "Documenter.jl") && endswith(f, ".pdf")
mv(joinpath(@__DIR__, "build-pdf", f),
joinpath(@__DIR__, "build-pdf", "commit", f))
mv(
joinpath(@__DIR__, "build-pdf", f),
joinpath(@__DIR__, "build-pdf", "commit", f)
)
end
end
end
deploydocs(
repo = "github.com/JuliaDocs/Documenter.jl.git",
target = "pdf/build-pdf/commit",
branch = "gh-pages-pdf",
forcepush = true,
repo="github.com/JuliaDocs/Documenter.jl.git",
target="pdf/build-pdf/commit",
branch="gh-pages-pdf",
forcepush=true,
)
else
deploydocs(
repo = "github.com/JuliaDocs/Documenter.jl.git",
target = "build",
push_preview = true,
repo="github.com/JuliaDocs/Documenter.jl.git",
target="build",
push_preview=true,
)
end
12 changes: 10 additions & 2 deletions src/DocMeta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@
If `warn` is `true`, it prints a warning when `key` already exists and it gets rewritten.
"""
function setdocmeta!(m::Module, key::Symbol, value; warn=true, recursive=false)
key in keys(VALIDMETA) || throw(ArgumentError("Invalid metadata key\nValid keys are: $(join(keys(VALIDMETA), ", "))"))
isa(value, VALIDMETA[key]) || throw(ArgumentError("Bad value type ($(typeof(value))) for metadata key $(key). Must be <: $(VALIDMETA[key])"))
key in keys(VALIDMETA) || throw(

Check warning on line 71 in src/DocMeta.jl

View check run for this annotation

Codecov / codecov/patch

src/DocMeta.jl#L71

Added line #L71 was not covered by tests
ArgumentError(
"Invalid metadata key\nValid keys are: $(join(keys(VALIDMETA), ", "))"
)
)
isa(value, VALIDMETA[key]) || throw(

Check warning on line 76 in src/DocMeta.jl

View check run for this annotation

Codecov / codecov/patch

src/DocMeta.jl#L76

Added line #L76 was not covered by tests
ArgumentError(
"Bad value type ($(typeof(value))) for metadata key $(key). Must be <: $(VALIDMETA[key])"
)
)
if recursive
for mod in Documenter.submodules(m)
setdocmeta!(mod, key, value; warn=warn, recursive=false)
Expand Down
50 changes: 28 additions & 22 deletions src/DocSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
#
# Note that `IntrinsicFunction` is exported from `Base` in `0.4`, but not in `0.5`.
#
let INTRINSICS = Dict(map(s -> getfield(Core.Intrinsics, s) => s, names(Core.Intrinsics, all=true)))
global binding(i::Core.IntrinsicFunction) = binding(Core.Intrinsics, INTRINSICS[i]::Symbol)
let INTRINSICS =
Dict(map(s -> getfield(Core.Intrinsics, s) => s, names(Core.Intrinsics, all=true)))
global binding(i::Core.IntrinsicFunction) =

Check warning on line 47 in src/DocSystem.jl

View check run for this annotation

Codecov / codecov/patch

src/DocSystem.jl#L47

Added line #L47 was not covered by tests
binding(Core.Intrinsics, INTRINSICS[i]::Symbol)
end

#
Expand All @@ -59,11 +61,15 @@
#
# Pseudo-eval of `Expr`s to find their equivalent `Binding`.
#
binding(m::Module, x::Expr) =
Meta.isexpr(x, :.) ? binding(getmod(m, x.args[1]), x.args[2].value) :
Meta.isexpr(x, [:call, :macrocall, :curly]) ? binding(m, x.args[1]) :
Meta.isexpr(x, :where) ? binding(m, x.args[1].args[1]) :
error("`binding` cannot understand expression `$x`.")
binding(m::Module, x::Expr) = if Meta.isexpr(x, :.)
binding(getmod(m, x.args[1]), x.args[2].value)
elseif Meta.isexpr(x, [:call, :macrocall, :curly])
binding(m, x.args[1])
elseif Meta.isexpr(x, :where)
binding(m, x.args[1].args[1])

Check warning on line 69 in src/DocSystem.jl

View check run for this annotation

Codecov / codecov/patch

src/DocSystem.jl#L68-L69

Added lines #L68 - L69 were not covered by tests
else
error("`binding` cannot understand expression `$x`.")

Check warning on line 71 in src/DocSystem.jl

View check run for this annotation

Codecov / codecov/patch

src/DocSystem.jl#L71

Added line #L71 was not covered by tests
end

# Helper methods for the above `binding` method.
getmod(m::Module, x::Expr) = getfield(getmod(m, x.args[1]), x.args[2].value)
Expand Down Expand Up @@ -114,7 +120,7 @@
`.data` dictionary.
"""
function docstr(md::Markdown.MD; kws...)
data = Dict{Symbol, Any}(
data = Dict{Symbol,Any}(

Check warning on line 123 in src/DocSystem.jl

View check run for this annotation

Codecov / codecov/patch

src/DocSystem.jl#L123

Added line #L123 was not covered by tests
:path => md.meta[:path],
:module => md.meta[:module],
:linenumber => 0,
Expand Down Expand Up @@ -146,7 +152,7 @@
if !haskey(CACHED, meta)
docs = IdDict{Any,Any}()
for (k, v) in meta
if !isa(k, Union{Number, AbstractString, IdDict{Any,Any}})
if !isa(k, Union{Number,AbstractString,IdDict{Any,Any}})

Check warning on line 155 in src/DocSystem.jl

View check run for this annotation

Codecov / codecov/patch

src/DocSystem.jl#L155

Added line #L155 was not covered by tests
docs[binding(k)] = multidoc(v)
end
end
Expand All @@ -171,11 +177,11 @@
Return a `Vector{DocStr}` ordered by definition order.
"""
function getspecificdocs(
binding::Docs.Binding,
typesig::Type = Union{},
compare = (==),
modules = Docs.modules,
)
binding::Docs.Binding,
typesig::Type=Union{},
compare=(==),
modules=Docs.modules,
)
# Fall back to searching all modules if user provides no modules.
modules = isempty(modules) ? Docs.modules : modules
# Keywords are special-cased within the docsystem. Handle those first.
Expand Down Expand Up @@ -208,12 +214,12 @@
try getting docs for `<:`.
"""
function getdocs(
binding::Docs.Binding,
typesig::Type = Union{};
compare = (==),
modules = Docs.modules,
aliases = true,
)
binding::Docs.Binding,
typesig::Type=Union{};
compare=(==),
modules=Docs.modules,
aliases=true,
)
# First, we try to find the docs that _exactly_ match the binding. If you
# have aliases, you can have a separate docstring attached to the alias.
results = getspecificdocs(binding, typesig, compare, modules)
Expand Down Expand Up @@ -244,7 +250,7 @@

Note that when conversion fails this method returns an empty `Vector{DocStr}`.
"""
function getdocs(object::Any, typesig::Type = Union{}; kws...)
function getdocs(object::Any, typesig::Type=Union{}; kws...)

Check warning on line 253 in src/DocSystem.jl

View check run for this annotation

Codecov / codecov/patch

src/DocSystem.jl#L253

Added line #L253 was not covered by tests
binding = aliasof(object, object)
binding === object ? DocStr[] : getdocs(binding, typesig; kws...)
end
Expand Down Expand Up @@ -287,7 +293,7 @@
"""
function parsedoc(docstr::DocStr)
md = try
Base.Docs.parsedoc(docstr) :: Markdown.MD
Base.Docs.parsedoc(docstr)::Markdown.MD
catch exception
@error """
parsedoc failed to parse a docstring into Markdown. This indicates a problem with the docstring.
Expand Down
27 changes: 18 additions & 9 deletions src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,24 @@ const DOCUMENTER_VERSION = let
end

# Potentially sensitive variables to be removed from environment when not needed
const NO_KEY_ENV = Dict(
"DOCUMENTER_KEY" => nothing,
"DOCUMENTER_KEY_PREVIEWS" => nothing,
)
const NO_KEY_ENV = Dict("DOCUMENTER_KEY" => nothing, "DOCUMENTER_KEY_PREVIEWS" => nothing,)

# Names of possible internal errors
const ERROR_NAMES = [:autodocs_block, :cross_references, :docs_block, :doctest,
:eval_block, :example_block, :footnote, :linkcheck_remotes, :linkcheck,
:meta_block, :missing_docs, :parse_error, :setup_block]
const ERROR_NAMES = [
:autodocs_block,
:cross_references,
:docs_block,
:doctest,
:eval_block,
:example_block,
:footnote,
:linkcheck_remotes,
:linkcheck,
:meta_block,
:missing_docs,
:parse_error,
:setup_block
]

"""
abstract type Plugin end
Expand Down Expand Up @@ -97,8 +106,8 @@ import .LaTeXWriter: LaTeX

# User Interface.
# ---------------
export makedocs, deploydocs, hide, doctest, DocMeta, asset, Remotes,
KaTeX, MathJax, MathJax2, MathJax3
export makedocs,
deploydocs, hide, doctest, DocMeta, asset, Remotes, KaTeX, MathJax, MathJax2, MathJax3

include("makedocs.jl")
include("deployconfig.jl")
Expand Down
Loading
Loading