So I just committed a dsm() locally, and it made me think it'd be handy if we had a pre-commit hook that could warn people if their code contains any such common oopsies. It'd have to be in their local repos, of course, so it would have to be rolled out as part of whatever system we devise for getting drupally git tools into local repos.
Comments
Comment #1
Josh The Geek commentedHere: http://drupal.org/sandbox/JoshTheGeek/1143338
Right now it only checks for dsm() (really, only the first half: dsm( because of strstr).
Comment #2
Josh The Geek commentedAnd, move to that.
Comment #3
attiks commentedcan you add dpm and others as well?
Comment #4
buddamy vote for dpr(), db_queryd(), kpr() to be warned about.
Comment #5
Josh The Geek commentedI added the above, dprint_r() (long of dpr()) and kprint_r() (long of kpr()).
The functions to check for are now in an array at the beginning of the file.
Comment #6
attiks commentedIsn't it safer to check for a space before the function name as well?
Comment #7
attiks commentedI added the file to .giit/hooks and added +x permission, I get the following without being able to enter y/n
Comment #8
buddaAnother one to include would be var_dump()
Comment #9
budda@attiks What is the benefit of checking for a space in front of a function name? Sometimes there might not be a space before the use of a debug function.
Comment #10
attiks commentedyou're right, it should be a space or the beginning of the line. The reason I asked becuase otherwise it would complain my_dpm() function calls as well
BTW: if you follow drupal coding standards, there's always a space before the function name
Comment #11
attiks commenteddoes anybody else have the problem described in #7, or is it my install?
Comment #12
Josh The Geek commented@attiks #7: I think that Git is not allowing input and just runs the script. I'm going to remove the confirmation and just cancel the commit, because there are almost no possible reasons to commit any of these. To get around it, you just have to move/rename the hook temporarily.
@attiks #10: exit(dpm($blah)); is coding standards valid, right? (Just an example, I dunno what dpm returns.)
@budda #9: I agree.
I will update this later today.
Comment #13
agileware commentedAnother one is dd() and that one definitely has to have a preceding space or new line.
Comment #14
Josh The Geek commentedI fixed all of the above. It no longer prompts, and I added var_dump/dd/drupal_debug().
Comment #15
Josh The Geek commentedOnce someone RTBCs this, I'll promote the project.
Comment #16
attiks commentedit's working for me, but can't we make the check more restrictive, see exit(dpm($blah)), moving the pre-commit hook isn't that user friendly ;p
so change the strstr to preg_match like this (not tested)
Comment #17
Josh The Geek commentedattiks:
From http://us2.php.net/preg_match : https://skitch.com/joshthegeek/r6ns4/php-preg-match-manual
All this will do is slow the script down on big commits.
I had a prompt about whether or not to continue, but you reported that git wasn't waiting, and just moving on. Moving the script may not be intuitive, but there are very few times you would even need to commit one of these. It tells you what function, so you can just
grep $function(and get the whole line. Should I add the grep output?Comment #18
attiks commentedjosh i know it's slower, let's close this issue, i created a follow-up #1150016: Check for whitespace
Comment #19
attiks commentedComment #20
buddaWe've been using this for the past week at Ixis and it's been a great reminder.