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

Empty style for strictly opt-in functionality #561

Open
fredrikekre opened this issue Mar 23, 2022 · 14 comments
Open

Empty style for strictly opt-in functionality #561

fredrikekre opened this issue Mar 23, 2022 · 14 comments
Labels
enhancement New feature or request style request

Comments

@fredrikekre
Copy link

Is there a way to configure JuliaFormatter to only do things I specify? I am thinking of something like an "empty" style which makes every change opt-in. Example config

style = "nothing"
always_for_in = true

which would only change = to in, but nothing else.

@domluna
Copy link
Owner

domluna commented Mar 24, 2022

it's possible to have a style that does this seems similar to #559 (comment) but maybe even more extreme?

@domluna domluna added enhancement New feature or request style request labels Mar 24, 2022
@fredrikekre
Copy link
Author

Yea I guess that is similar. Something that only does things that are not contriversial at all, perhaps just remove trailing whitespace etc.

@domluna domluna mentioned this issue May 19, 2022
9 tasks
@Moelf
Copy link

Moelf commented Oct 7, 2022

minimal still does something:

@@ -619,8 +623,8 @@ NamedTuple{names}(args::Tuple) where {names} = NamedTuple{names,typeof(args)}(ar
 
 using .Intrinsics: sle_int, add_int
 
-eval(Core, :(NamedTuple{names,T}(args::T) where {names, T <: Tuple} =
-             $(Expr(:splatnew, :(NamedTuple{names,T}), :args))))
+eval(Core, :(NamedTuple{names,T}(args::T) where {names,T<:Tuple} =
+    $(Expr(:splatnew, :(NamedTuple{names,T}), :args))))

@@ -660,157 +664,157 @@ function checked_trunc_uint(::Type{To}, x::From) where {To,From}
     y
 end
 
-toInt8(x::Int8)       = x
-toInt8(x::Int16)      = checked_trunc_sint(Int8, x)
-toInt8(x::Int32)      = checked_trunc_sint(Int8, x)
-toInt8(x::Int64)      = checked_trunc_sint(Int8, x)
-toInt8(x::Int128)     = checked_trunc_sint(Int8, x)
-toInt8(x::UInt8)      = bitcast(Int8, check_top_bit(Int8, x))
-toInt8(x::UInt16)     = checked_trunc_sint(Int8, check_top_bit(Int8, x))
-toInt8(x::UInt32)     = checked_trunc_sint(Int8, check_top_bit(Int8, x))
-toInt8(x::UInt64)     = checked_trunc_sint(Int8, check_top_bit(Int8, x))
-toInt8(x::UInt128)    = checked_trunc_sint(Int8, check_top_bit(Int8, x))
+toInt8(x::Int8) = x
+toInt8(x::Int16) = checked_trunc_sint(Int8, x)
+toInt8(x::Int32) = checked_trunc_sint(Int8, x)
+toInt8(x::Int64) = checked_trunc_sint(Int8, x)
+toInt8(x::Int128) = checked_trunc_sint(Int8, x)
+toInt8(x::UInt8) = bitcast(Int8, check_top_bit(Int8, x))
+toInt8(x::UInt16) = checked_trunc_sint(Int8, check_top_bit(Int8, x))
+toInt8(x::UInt32) = checked_trunc_sint(Int8, check_top_bit(Int8, x))
+toInt8(x::UInt64) = checked_trunc_sint(Int8, check_top_bit(Int8, x))
+toInt8(x::UInt128) = checked_trunc_sint(Int8, check_top_bit(Int8, x))
+toInt8(x::Bool) = and_int(bitcast(Int8, x), Int8(1))

@domluna
Copy link
Owner

domluna commented Oct 7, 2022

MinimalStyle currently uses the indentation style of one of the other styles. So it will cause different indentation than the source in a few settings. The second example you linked could be fixed with setting align_assignment to true

@Moelf
Copy link

Moelf commented Oct 7, 2022

The second example you linked could be fixed with setting align_assignment to true

then that will align assignments that were originally not aligned, we need a align_assignment = nothing option.

the motivation here is in order to adopt formatting as part of the Julia repo's CI, we need a "do nothing" state, and gradually enable things as people see fit

@Moelf
Copy link

Moelf commented Oct 7, 2022

another thing I can't seem to turn off:

diff --git a/base/Base.jl b/base/Base.jl
index 63728fdba3..ed7a09627d 100644
--- a/base/Base.jl
+++ b/base/Base.jl
@@ -22,8 +22,12 @@ ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Base, is_primary_base_module)
 
 # The @inline/@noinline macros that can be applied to a function declaration are not available
 # until after array.jl, and so we will mark them within a function body instead.
-macro inline()   Expr(:meta, :inline)   end
-macro noinline() Expr(:meta, :noinline) end
+macro inline()
+    Expr(:meta, :inline)
+end
+macro noinline()
+    Expr(:meta, :noinline)
+end

@Moelf
Copy link

Moelf commented Oct 13, 2022

more cases of can't stop formatter from doing something

 ## Concatenation ##
 eltypeof(x) = typeof(x)
@@ -1595,15 +1565,15 @@ typed_vcat(::Type{T}) where {T} = Vector{T}()
 typed_hcat(::Type{T}) where {T} = Vector{T}()
 
 ## cat: special cases
-vcat(X::T...) where {T}         = T[ X[i] for i=1:length(X) ]
-vcat(X::T...) where {T<:Number} = T[ X[i] for i=1:length(X) ]
-hcat(X::T...) where {T}         = T[ X[j] for i=1:1, j=1:length(X) ]
-hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=1:length(X) ]
+vcat(X::T...) where {T} = T[X[i] for i = 1:length(X)]
+vcat(X::T...) where {T<:Number} = T[X[i] for i = 1:length(X)]
+hcat(X::T...) where {T} = T[X[j] for i = 1:1, j = 1:length(X)]
+hcat(X::T...) where {T<:Number} = T[X[j] for i = 1:1, j = 1:length(X)]

@domluna
Copy link
Owner

domluna commented Oct 13, 2022

it should align that s

another thing I can't seem to turn off:

diff --git a/base/Base.jl b/base/Base.jl
index 63728fdba3..ed7a09627d 100644
--- a/base/Base.jl
+++ b/base/Base.jl
@@ -22,8 +22,12 @@ ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Base, is_primary_base_module)
 
 # The @inline/@noinline macros that can be applied to a function declaration are not available
 # until after array.jl, and so we will mark them within a function body instead.
-macro inline()   Expr(:meta, :inline)   end
-macro noinline() Expr(:meta, :noinline) end
+macro inline()
+    Expr(:meta, :inline)
+end
+macro noinline()
+    Expr(:meta, :noinline)
+end

no way to turn that off atm

@domluna
Copy link
Owner

domluna commented Oct 13, 2022

more cases of can't stop formatter from doing something

 ## Concatenation ##
 eltypeof(x) = typeof(x)
@@ -1595,15 +1565,15 @@ typed_vcat(::Type{T}) where {T} = Vector{T}()
 typed_hcat(::Type{T}) where {T} = Vector{T}()
 
 ## cat: special cases
-vcat(X::T...) where {T}         = T[ X[i] for i=1:length(X) ]
-vcat(X::T...) where {T<:Number} = T[ X[i] for i=1:length(X) ]
-hcat(X::T...) where {T}         = T[ X[j] for i=1:1, j=1:length(X) ]
-hcat(X::T...) where {T<:Number} = T[ X[j] for i=1:1, j=1:length(X) ]
+vcat(X::T...) where {T} = T[X[i] for i = 1:length(X)]
+vcat(X::T...) where {T<:Number} = T[X[i] for i = 1:length(X)]
+hcat(X::T...) where {T} = T[X[j] for i = 1:1, j = 1:length(X)]
+hcat(X::T...) where {T<:Number} = T[X[j] for i = 1:1, j = 1:length(X)]

this one should work with align_assignment = true

https://github.com/domluna/JuliaFormatter.jl/blob/master/test/options.jl#L1180-L1187

@Moelf
Copy link

Moelf commented Oct 13, 2022

there are codes that were not aligned, the point is I think we want to automate the pipeline that does literally nothing (or almost), then we can turn one thing on at a time

@domluna
Copy link
Owner

domluna commented Oct 13, 2022

yeah ic, right now there's no mode which does nothing. It should be doable since we keep track of the positioning of everything in the original source but hasn't been a large priority (at least for me). It might be pretty involved as well.

@mortenpi
Copy link

Just chiming in: I think that having a way to start from a no-op mode and then enable features one-by-one would be great to have in my opinion. For a larger project it can be a little scary to reformat everything in one go, so having control over it could help with the adoption of JuliaFormatter for existing packages and projects.

@Moelf
Copy link

Moelf commented Jan 11, 2023

Yeah exactly, I think I read something a while back about start automation by writing an automatic (but runnable) no-op script/CI, which is what I'm going after here

@domluna
Copy link
Owner

domluna commented Jan 11, 2023

So I think as it stands the FST as enough information to be able to do nothing - since it tracks the line offset of every "token". What might be easier, at least from the perspective of gradual formatting is to leverage the no format block feature already present so that only the git diff sections are formatted and the rest is printed out as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request style request
Projects
None yet
Development

No branches or pull requests

4 participants