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

utils/inreplace: allow non-global substitution #18614

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Conversation

cho-m
Copy link
Member

@cho-m cho-m commented Oct 23, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Can replace some occurrences of:

inreplace <file> do |s|
  s.sub! before, after
end

Also increase test coverage.

@cho-m cho-m force-pushed the inreplace-non-global branch 2 times, most recently from 9a5e68e to 63a78f4 Compare October 23, 2024 22:38
@Bo98
Copy link
Member

Bo98 commented Oct 24, 2024

Do you have examples of formulae that intentionally do this and produce wrong results under gsub? Makes the regex sound somewhat fragile.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

This makes sense to me as an API. If we're using sub! already in 3+ formulae and this can simplify things there: we should do it.

@cho-m
Copy link
Member Author

cho-m commented Oct 25, 2024

Do you have examples of formulae that intentionally do this and produce wrong results under gsub? Makes the regex sound somewhat fragile.

There should be ways to change regex to work under gsub, but if we know that there is and only ever will be one substitution, then it makes sense to use sub.

Though we won't get full advantage of single sub unless we provide an option to disable multiline matches and do line-by-line scan of file. However, modified files usually aren't large enough that this matters.

@cho-m cho-m merged commit f18e1ea into master Oct 31, 2024
33 checks passed
@cho-m cho-m deleted the inreplace-non-global branch October 31, 2024 18:05
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.

3 participants