Re: [PATCH 1/3] checkpatch: add --drx option and drx_print() helper
From: Joe Perches
Date: Sat Oct 25 2025 - 19:24:35 EST
On Sat, 2025-10-25 at 15:15 -0600, Jim Cromie wrote:
> checkpatch has ~235 heuristic s/$patt// statements which strip
> code-snippets that are "OK", leaving the remainder for further
> heuristics to apply further "cleanups".
>
> Many of these have obvious purpose, but surely some are inscrutable.
> For those cases, add drx_print($reason) helper, which is designed to
> be called from a s/// or s///g statement (in the 'replacement' side),
> to "explain" what it is doing.
>
> You can use it to instrument the code to "explain" itself, then
> validate that explanation by experiment and exersize:
>
> s/$patt/drx_print("why")/e;
> s/$patt/drx_print("whys")/ge;
>
> To activate the "debug" output, pass --drx or --drx=why to enable all
> (or just matching) cleanup heuristics to validate the "whys".
>
> Here it is in action, on a patch which triggered enough noise that I
> wanted this visibility into what it was doing.
>
> $ scripts/checkpatch.pl --strict --drx=builtins ../linux.git/pt-1
> drx_print: -builtins-
> >> Matched (`$&`): <__builtin_constant_p(cls>
> >> Capture 1 (`$1`): <__builtin_constant_p>
I'd prefer you extend the existing --debug KEY=[0|1] mechanism.