guillaumeaubert / App-GitHooks

Plugin-based system to run specific actions and checks when git hooks are triggered.
https://metacpan.org/pod/App::GitHooks
Other
6 stars 3 forks source link

Feature request: Code::TidyAll support #39

Open sjn opened 8 years ago

sjn commented 8 years ago

Hei!

Would it be possible to add support for Code::TidyAll to App::GitHooks? (e.g. as a plugin?)

guillaumeaubert commented 8 years ago

There are two potential parts to your request:

1) Checking that files don't report any issues with Code::TidyAll and preventing the user from committing when they do.

Conceptually, this is very similar to App::GitHooks::Plugin::PerlCritic, and the behavior would be the same as Code::TidyAll::Git::Precommit.

The only potential problem here is the level of detail bubbled up by Code::TidyAll::Result for the line number of issues detected. Several App::GitHooks plugins (for example: App::GitHooks::Plugin::PerlCritic) review the line number(s) of issues, to detect if the issues are in changes you're committing or in changes that predated your current edit. This avoids forcing the user to clean up / fix an entire file if they're just trying to make a one line fix, but it looks like implementing line-level matching would be difficult for Code::TidyAll. The plugin could try to parse the output, but as the output may change over time, the maintenance cost would likely be high.

This doesn't prevent a Code::TidyAll plugin, but it's a trade-off vs implementing specific App::GitHooks plugins for each tool that Code::TidyAll supports.

2) Automatically running Code::TidyAll to clean up the files before they're committed.

This is a difficult problem, in particular because:

  1. This causes automatic modifications to local user changes that haven't been committed yet. If the code cleaning tools do something that is unexpected, reverting the automatic changes is going to be complicated and potentially confusing for the user.
  2. This would need to handle partial staged edits (with git add -p), and how to stage the corresponding parts of the automatic cleanup.

TidyAll::Git::Precommit does not offer this either, possibly for similar reasons.