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

support patches with comments #165

Open
ccoVeille opened this issue Jun 24, 2024 · 3 comments
Open

support patches with comments #165

ccoVeille opened this issue Jun 24, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@ccoVeille
Copy link

I'm trying to use patch to perform something like this

@@
var f identifier
@@
-func f(t *testing.T) {
+func f(t *testing.T) {
+   t.Helper() // my comment
+
+   t.Helper()
    ...
}

This code is part of a bigger patch and code reorganization. So this is a code to replicate the issue/question I want to talk about.

My issues right now are that:

  • the code adds the t.Helper() but not the comment
  • the new line is not added

I would like to know if I'm not missing something obvious

@ccoVeille
Copy link
Author

ccoVeille commented Jun 24, 2024

Please note that

@@
var f identifier
@@
-func f(t *testing.T) {
+func f(t *testing.T) {
+   t.Helper()
+
+   t.Helper()
    ...
}

will rewrite this

func myTestHelper(t *testing) {
   require.Fail(t)
}

to

func myTestHelper(t *testing) {
   t.Helper()
   t.Helper()
   require.Fail(t)
}

So no line feed

Once again, please note it's pseudo code

@abhinav
Copy link
Contributor

abhinav commented Jun 24, 2024

Hey @ccoVeille. gopatch is limited in that aspect: it only transforms significant AST nodes.
It could probably do something smarter about them, but the original design left out comments and newlines with more focus on just transforming code.

@ccoVeille
Copy link
Author

I was thinking about using the tool to add //nolint somelinter // reason on some pattern I have in my code base.

I would love if comment could be supported.

I would prefer if it was possible, but I can leave without new lines.

Comment is a bit more painful

@tchung1118 tchung1118 changed the title question about comments and new lines support patches with comments Jun 25, 2024
@tchung1118 tchung1118 added the enhancement New feature or request label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants