You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New builtin hook for simple search and replace
#2927
- search: /Something [bB]ad/replacement: Something Good
- search: foobarinsensitive: truereplacement: FOOBAR
- search: JustFailIfThisStringIsFound # This won't do any replacement but fail if the pattern matches
The only downside of this hook is that it requires a system Ruby and given that it is Ruby its is rather slow. There were already issues raised about deploying prebuilt binaries or a complete rewrite in Rust.
However, I could imagine this might be a nice fit for a builtin hook.
How
With the existing https://prek.j178.dev/reference/built-in-hooks/?h=deny-pa#deny-pattern, prek already supports the "search only" usecase. So the only part that is missing is the search-and-replace part. And the benefit of a dedicated hook that only defines one pattern compared to a config file for everything is that the user can define language/files/excludes on a per pattern basis.
So similar to the deny pattern usecase, a user would pass a search pattern and a replace pattern which the hook does.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Proposal
I wanted to drop the idea of adding a simple builtin hook called
search-and-replace. This idea is inspired by https://github.com/mattlqx/pre-commit-search-and-replace. This hook provides a simple yaml based config likeThe only downside of this hook is that it requires a system Ruby and given that it is Ruby its is rather slow. There were already issues raised about deploying prebuilt binaries or a complete rewrite in Rust.
However, I could imagine this might be a nice fit for a builtin hook.
How
With the existing https://prek.j178.dev/reference/built-in-hooks/?h=deny-pa#deny-pattern, prek already supports the "search only" usecase. So the only part that is missing is the
search-and-replacepart. And the benefit of a dedicated hook that only defines one pattern compared to a config file for everything is that the user can define language/files/excludes on a per pattern basis.So similar to the deny pattern usecase, a user would pass a search pattern and a replace pattern which the hook does.
All reactions