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

Allow expanding all short function definitions #861

Merged
merged 7 commits into from
Aug 22, 2024

Conversation

jw3126
Copy link
Contributor

@jw3126 jw3126 commented Aug 6, 2024

I would like to have a way to banish all short function definitions from a code base. This PR implements one way to make that possible, by setting the max length of short function definitions to zero. But I would be happy to implement a different mechanism if desired.
I will add docs once it is clear whether we want an option like this.

@domluna
Copy link
Owner

domluna commented Aug 6, 2024

I generally like this since it's backwards compatible. The downside that comes to mind is that it opens up the door for doing this in all sorts of circumstances for other parts of the code.

@jw3126
Copy link
Contributor Author

jw3126 commented Aug 7, 2024

So what should I do:

  • Polish this PR so it can be merged?
  • Implement a different approach to banish all short functions?
  • Close this PR?

Copy link
Owner

@domluna domluna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a bit more thought I think what would make more sense to is to have this be a boolean option rather than something determined by line margin, after all, the use case you have requires it be set to 0. And from the API perspective a boolean it easier to reason about than an arbitrary number, especially when I don't think anyone is setting that number to anything that's not 0 or margin.

@@ -1,7 +1,7 @@
name = "JuliaFormatter"
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
authors = ["Dominique Luna <[email protected]>"]
version = "1.0.59"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be 1.0.60 since it's not a breaking change of any kind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it. Although personally, I would interpret this PR as a feature that should increase the minor version instead of a bugfix that should increase the patch version.

@jw3126
Copy link
Contributor Author

jw3126 commented Aug 8, 2024

Any suggestion for a name for the new boolean option? Right now we have:

short_to_long_function_def
long_to_short_function_def 

I assume we want to be backward compatible and not touch these but add another option that is false by default.
Some ideas:

always_long_function_def
force_long_function_def

@domluna
Copy link
Owner

domluna commented Aug 17, 2024

i like force_long_function_def. sorry I didn't reply sooner totally forgot about this

@jw3126
Copy link
Contributor Author

jw3126 commented Aug 18, 2024

@domluna can you approve CI?

@domluna
Copy link
Owner

domluna commented Aug 19, 2024

failure seems unrelated? maybe something to do with the GH action

Comment on lines +39 to +49
function Options(args...)
opts = new(args...)
if (opts.force_long_function_def === true) &&
(opts.short_to_long_function_def === false)
msg = """
The combination `force_long_function_def = true` and `short_to_long_function_def = false` is invalid.
"""
throw(ArgumentError(msg))
end
return opts
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is causing failures on Julia < v1.6

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: LoadError: LoadError: syntax: ... is not supported inside "new"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jw3126 update this when you get the chance and it should be g2g

@domluna domluna merged commit dda8c31 into domluna:master Aug 22, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants