-
Notifications
You must be signed in to change notification settings - Fork 46
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
[Not Urgent, Stylistic] Format Julia source files by JuliaFormatter #157
Open
Paalon
wants to merge
2
commits into
JuliaData:master
Choose a base branch
from
Paalon:formatting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Formatting options for the default style supported in JuliaFormatter v1.0.56. | ||
# https://domluna.github.io/JuliaFormatter.jl/stable/ | ||
|
||
# style = "default" | ||
# indent = 4 | ||
# margin = 92 | ||
always_for_in = "nothing" # default false | ||
# for_in_replacement = "in" | ||
whitespace_typedefs = true # default false | ||
# whitespace_ops_in_indices = false | ||
remove_extra_newlines = true # default false | ||
# import_to_using = false | ||
# pipe_to_function_call = false | ||
# short_to_long_function_def = false | ||
# long_to_short_function_def = false | ||
# always_use_return = false | ||
whitespace_in_kwargs = false # default true | ||
annotate_untyped_fields_with_any = false # default true | ||
# format_docstrings = false | ||
# align_struct_field = false | ||
# align_assignment = false | ||
# align_conditional = false | ||
align_pair_arrow = true # default false | ||
# conditional_to_if = false | ||
# normalize_line_endings = "auto" | ||
# align_matrix = false | ||
# join_lines_based_on_source = false | ||
trailing_comma = true # default false | ||
# trailing_zero = true | ||
# indent_submodule = false | ||
# separate_kwargs_with_semicolon = false | ||
surround_whereop_typeparameters = false # default true | ||
# variable_call_indent = [] | ||
# short_circuit_to_if = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,35 +15,45 @@ include("constructor.jl") | |
include("writer.jl") # write Julia dictionaries to YAML files | ||
|
||
const _constructor = Union{Nothing, Dict} | ||
const _dicttype = Union{Type,Function} | ||
const _dicttype = Union{Type, Function} | ||
|
||
# add a dicttype-aware version of construct_mapping to the constructors | ||
function _patch_constructors(more_constructors::_constructor, dicttype::_dicttype) | ||
if more_constructors == nothing | ||
more_constructors = Dict{String,Function}() | ||
more_constructors = Dict{String, Function}() | ||
else | ||
more_constructors = copy(more_constructors) # do not change the outside world | ||
end | ||
if !haskey(more_constructors, "tag:yaml.org,2002:map") | ||
more_constructors["tag:yaml.org,2002:map"] = custom_mapping(dicttype) # map to the custom type | ||
elseif dicttype != Dict{Any,Any} # only warn if another type has explicitly been set | ||
elseif dicttype != Dict{Any, Any} # only warn if another type has explicitly been set | ||
@warn "dicttype=$dicttype has no effect because more_constructors has the key \"tag:yaml.org,2002:map\"" | ||
end | ||
return more_constructors | ||
end | ||
|
||
|
||
load(ts::TokenStream, constructor::Constructor) = | ||
construct_document(constructor, compose(EventStream(ts))) | ||
|
||
load(input::IO, constructor::Constructor) = | ||
load(TokenStream(input), constructor) | ||
|
||
load(ts::TokenStream, more_constructors::_constructor = nothing, multi_constructors::Dict = Dict(); dicttype::_dicttype = Dict{Any, Any}, constructorType::Function = SafeConstructor) = | ||
load(ts, constructorType(_patch_constructors(more_constructors, dicttype), multi_constructors)) | ||
|
||
load(input::IO, more_constructors::_constructor = nothing, multi_constructors::Dict = Dict(); kwargs...) = | ||
load(TokenStream(input), more_constructors, multi_constructors ; kwargs...) | ||
load(input::IO, constructor::Constructor) = load(TokenStream(input), constructor) | ||
|
||
load( | ||
ts::TokenStream, | ||
more_constructors::_constructor=nothing, | ||
multi_constructors::Dict=Dict(); | ||
dicttype::_dicttype=Dict{Any, Any}, | ||
constructorType::Function=SafeConstructor, | ||
) = load( | ||
ts, | ||
constructorType(_patch_constructors(more_constructors, dicttype), multi_constructors), | ||
) | ||
|
||
load( | ||
input::IO, | ||
more_constructors::_constructor=nothing, | ||
multi_constructors::Dict=Dict(); | ||
kwargs..., | ||
) = load(TokenStream(input), more_constructors, multi_constructors; kwargs...) | ||
|
||
mutable struct YAMLDocIterator | ||
input::IO | ||
|
@@ -58,7 +68,16 @@ mutable struct YAMLDocIterator | |
end | ||
end | ||
|
||
YAMLDocIterator(input::IO, more_constructors::_constructor=nothing, multi_constructors::Dict = Dict(); dicttype::_dicttype=Dict{Any, Any}, constructorType::Function = SafeConstructor) = YAMLDocIterator(input, constructorType(_patch_constructors(more_constructors, dicttype), multi_constructors)) | ||
YAMLDocIterator( | ||
input::IO, | ||
more_constructors::_constructor=nothing, | ||
multi_constructors::Dict=Dict(); | ||
dicttype::_dicttype=Dict{Any, Any}, | ||
constructorType::Function=SafeConstructor, | ||
) = YAMLDocIterator( | ||
input, | ||
constructorType(_patch_constructors(more_constructors, dicttype), multi_constructors), | ||
) | ||
|
||
# Old iteration protocol: | ||
start(it::YAMLDocIterator) = nothing | ||
|
@@ -80,11 +99,9 @@ done(it::YAMLDocIterator, state) = it.next_doc === nothing | |
iterate(it::YAMLDocIterator) = next(it, start(it)) | ||
iterate(it::YAMLDocIterator, s) = done(it, s) ? nothing : next(it, s) | ||
|
||
load_all(input::IO, args...; kwargs...) = | ||
YAMLDocIterator(input, args...; kwargs...) | ||
load_all(input::IO, args...; kwargs...) = YAMLDocIterator(input, args...; kwargs...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This I agree with |
||
|
||
load(input::AbstractString, args...; kwargs...) = | ||
load(IOBuffer(input), args...; kwargs...) | ||
load(input::AbstractString, args...; kwargs...) = load(IOBuffer(input), args...; kwargs...) | ||
|
||
load_all(input::AbstractString, args...; kwargs...) = | ||
load_all(IOBuffer(input), args...; kwargs...) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love this formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This is the kind of JuliaFormatter thing that makes me not want to touch a code base.
This particular definition shouldn't have been in short form at all though; there's way too many arguments to make that look good, regardless of formatting. Never mind, Juliaformatter makes long form definitions equally horrible.