-
Notifications
You must be signed in to change notification settings - Fork 71
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
Have defaults settings depend on the Style (dispatch on Style) #296
Comments
This was also raised by @ericphanson in the context of |
Just wanted to +1 this and mention @ararslan also agreed that just specifying the One other comment is that option (1) can be done in a non-breaking way by also using a method like format(path; style=DefaultStyle(), kwargs...) = format(path, style; kwargs...) instead of format(path; kwargs...) = format(path, DefaultStyle(); kwargs...) |
Great suggestion! I've added that improvement to option (i) above 😺 I think option (i) is a pretty clear win (especially as it's non-breaking!). And we can always consider (ii) in future if/when we want style-specific keywords? |
@mzgubic just requested this over at invenia/NamedDims.jl#138 (comment) too |
I will work on a PR for this -- i don't think it'll need too much :) |
thanks for taking this on @nickrobinson251! I'm glad to see the feature :) |
I'm wondering about how to give styles ability to fully specific the format, while still exposing the full flexibility to users who want to tweak the style to their own preferences.
Right now, there's one
format
method and one of the keywords isstyle
e.g.style=YASStyle
, and then other keywords e.g.always_for_in=true
controlling other aspects of the formatting.We get the situation where to format code following a Style Guide (e.g. YAS Guide) you need to both set a
Style
(e.g.YASStyle
) and set the keywords to the ones that fulfil the style (e.g. passalways_for_in=true
).One small issue with this, is it leads to a slightly awkward API (in my opinion), where passing in a
Style
is not sufficient to have the code formatted in line with the corresponding style guide (since you need to set keywords too).A "work-around" for this is to use a config file. (Config files are a very useful feature, in my opinion, but for the use-case where you want to exactly follow a style guide, i think we may be able to get an even nicer API without requiring config files, which are still useful for other use-cases.)
A second small issue, since
style
is a keyword / there's oneformat
method, all the otherkeyword
are the same no matter thestyle
(i.e. same keywordsalways_for_in
, same defaultsalways_for_in=false
), which means we cannot have style-specific keywords (unclear yet if that's flexibility we'd want)A suggestion for how to improve this situation is to (i) dispatch on
Style
, and maybe (ii) haveStyle
constructors own the keywordse.g. with option (i)
then call like
e.g. with both option (i) and option (ii) as well
then call like
FWIW, while most of the benefit comes from doing (i), doing both options (i) and (ii) makes most sense to me (and while it's a breaking change to do (ii), it does also allow us to keep the one-arg
format(path; kwargs...)
method if we want, by passing kwargs toDefaultStyle
).(This issue is kinda related to #212)
As an aside: I think it's still a little undecided which settings are controlled by
Styles
e.g.YASStyle
, versus via keywords e.g.always_for_in=true
, but "what gets it's own keyword?" seems a different question to the one i'm raising here, which is aboutStyle
s being able to fully specify the format (without losing current flexibility)The text was updated successfully, but these errors were encountered: