mlawren / githook-perltidy

Run perltidy as a Git pre-commit hook
41 stars 10 forks source link

Adds support for Perl::Tidy::Sweet #9

Closed mvgrimes closed 6 years ago

mvgrimes commented 8 years ago

Perl::Tidy::Sweet uses Perl::Tidy's prefilter and postfilter hooks to support syntax added by a number of modules (p5-mop, Method::Signatures::Simple, MooseX::Method::Signatures, MooseX::Declare, etc). This includes method and func keywords, including the (possibly multi-line) parameter lists.

This patch adds a --sweet/-s flag to both the install and pre-commit commands. When specified, code is tied with Perl::Tidy::Sweet instead of Perl::Tidy.

Perl::Tidy::Sweet is added as a prereq in the Makefile.PL, as "recommends" doesn't seem to do anything (I'm not that familiar with Module::Install).

A new test has been added that optionally runs all the tests with the --sweet flag. This might be overkill. It would probably be sufficient to just test the tidying of code with the method keyword.

This is my contribution to May's PRC. I just happen to be the author of Perl::Tidy::Sweet.

mlawren commented 6 years ago

Many thanks for the suggestion and the patch. I'm sorry I didn't respond - probably meant you didn't succeed with the PRC challenge for that month :-(

I have just implemented Sweetened support which you can see in action in the latest development release. It uses a slightly different mechanism than the one you proposed here. A --sweet flag would mean that Sweetened tidying would depend on each commiter installing githook-perltidy the correct way.

What I've done instead is require a .perltidyrc.sweetend file to be committed in place of the .perltidyrc file. That enforces the same behaviour across all committers. I'll let the CPAN testers do their thing for a while before I make a stable release. If you have any comments I'd be pleased to hear them.