mattlqx / pre-commit-search-and-replace

Plugin for pre-commit for arbitrary search and replace on committed files.
MIT License
12 stars 6 forks source link

Make replacing with regex matches work #22

Closed matthew-limbinar closed 1 month ago

matthew-limbinar commented 3 months ago

Following on #20, with a PR in #21, the replacement does not use regex substitution for its work. So while the test in #21 finds correctly, it does not replace correctly.

- search: /( *\/\/\/ +([@\\]param)) +(\w+) *(\[(in|out|in, *out)\])?/
  replacement: \1\4 \3

For an input of:

//////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Some brief desc
/// @param some_param_P1 [in] First param desc
/// @param  second  [out] Second param desc
/// \param  OTHER[out]  Yet another param desc! @param over [in] here too.
void foo(X some_param_P1, Y& second,  const Z OTHER);

/// @brief Returns the value of the variable multiplied by 3.
/// @param value The value of the variable.
/// @return The value of the variable multiplied by 3.
int multiplyByThree(int value) const;

Should yield:

//////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Some brief desc
/// @param[in] some_param_P1 First param desc
/// @param[out] second Second param desc
/// \param[out] OTHER  Yet another param desc! @param over [in] here too.
void foo(X some_param_P1, Y& second,  const Z OTHER);

but actually yields:

//////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Some brief desc
\1\4 \3First param desc
\1\4 \3Second param desc
\1\4 \3Yet another param desc! @param over [in] here too.
void foo(X some_param_P1, Y& second,  const Z OTHER);