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

x/tools/cmd/eg: allow multiple refactorings in a single template #10143

Open
josharian opened this issue Mar 12, 2015 · 1 comment
Open

x/tools/cmd/eg: allow multiple refactorings in a single template #10143

josharian opened this issue Mar 12, 2015 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@josharian
Copy link
Contributor

josharian commented Mar 12, 2015

While working on Node refactoring leading up to CL 7360, I found myself applying 8 different templates (one per relevant field) sequentially. It would be nicer to use--and I think faster to execute--to apply them all in a single pass.

The template could look like a sequence of alternating pairs of before and after:

package P

func before(s string) error { return fmt.Errorf("%s", s) }
func after(s string)  error { return errors.New(s) }

func before(msg string) { log.Fatalf("%s", msg) }
func after(msg string)  { log.Fatal(msg) }

The semantics would be that the output would be equivalent to applying each of the pairs sequentially as a template.

Thoughts? I'm happy to help with implementation.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/eg: allow multiple refactorings in a single template x/tools/cmd/eg: allow multiple refactorings in a single template Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-tools label Apr 14, 2015
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 13, 2024
@jbduncan
Copy link

jbduncan commented Jan 2, 2025

This issue is of interest to me, as I'm probably the only person on the planet crazy enough to run eg templates as part of lint checks (./x.sh --check) and fixes (./x.sh --fix) in my personal project.

./x.sh --check runs multiple eg processes, one per template, in parallel on every Go file.

Then when a fix needs to be made, I run ./x.sh --fix to run the templates sequentially with the -w flag. I do things sequentially to avoid data races, like if two or more templates are writing to the same file.

I feel like eg could be faster if it allowed multiple templates to be run in parallel in a single pass, whilst also avoiding the aforementioned data races.

Furthermore, if eg had a command-like flag to print out which templates were going to fix which files in JSON, then I could script ./x.sh --fix to only run some templates on some files, making things much faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants