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
golang: add support for passthrough args for gofmt #18409
golang: add support for passthrough args for gofmt #18409
Conversation
pass | ||
|
||
|
||
SupportedGoFmtArgs = FrozenOrderedSet(("-e", "-r", "-s")) |
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.
Why only support some args? Can you add a comment explaining?
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.
Some options like -w
are not style related and are used by the rule code to change how gofmt
operates. This type of option should not be passed through or else it may interfere with the rule.
@@ -11,3 +11,4 @@ class GofmtSubsystem(Subsystem): | |||
help = "Gofmt-specific options." | |||
|
|||
skip = SkipOption("fmt", "lint") | |||
args = ArgsListOption(example="-s") |
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.
Can we incorporate the list of supported args in this help-string?
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.
Excellent idea, thank you! This is now done :)
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.
Looks generally fine.
Side note: Not a big deal but since I wrote this code and am still a maintainer, please do add me as a reviewer next time.
pass | ||
|
||
|
||
SupportedGoFmtArgs = FrozenOrderedSet(("-e", "-r", "-s")) |
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.
Style: Identifiers for constants should be in all capitals.
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.
Done!
pass | ||
|
||
|
||
SupportedGoFmtArgs = FrozenOrderedSet(("-e", "-r", "-s")) |
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.
Some options like -w
are not style related and are used by the rule code to change how gofmt
operates. This type of option should not be passed through or else it may interfere with the rule.
Thank you for taking a look! I was sure I've tagged you along. Very sorry that wasn't the case and of course I intend to ask you for Go related reviews :) |
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.
Approving with two minor comments.
from pants.option.subsystem import Subsystem | ||
from pants.util.ordered_set import FrozenOrderedSet | ||
|
||
SUPPORTED_GOFMT_ARGS = FrozenOrderedSet(("-e", "-r", "-s")) |
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.
Python's frozenset
should be sufficient here.
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.
Sorry, I should have mentioned that. The reason I've used an ordered one is to be able to confirm that this thing appears in the exception message when running a test with invalid arguments passed.
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.
👍
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 also wanted the help message to be consistent and output the arguments in the same order all the time.
@@ -11,3 +14,7 @@ class GofmtSubsystem(Subsystem): | |||
help = "Gofmt-specific options." | |||
|
|||
skip = SkipOption("fmt", "lint") | |||
args = ArgsListOption( | |||
example="-s -e", | |||
extra_help=f"Only the following style related options are supported: {tuple(SUPPORTED_GOFMT_ARGS)}.", |
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.
Maybe the following would look nicer than the tuple?
", ".join([f"`{x}`" for x in xs])
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.
Sure, this looks great to me!
--gofmt-args="[<shell_str>, <shell_str>, ...]"
PANTS_GOFMT_ARGS
args
default: []
current value: []
Arguments to pass directly to gofmt, e.g. `--gofmt-args='-s -e'`.
Only the following style related options are supported: `-e`, `-r`, `-s`.
Closes #12822
This PR makes it possible to pass (some) arguments to the
gofmt
program to be able to use the flags thatgofmt
provides.E.g. running
gofmt -s
onwould result in simplified (
-s
) code:The interface:
or with the
pants.toml
: