Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/birkenfeld/gitcodesmell

Git hook checking for "smelly" changes in files (debugging leftovers, merge markers etc.) before committing
https://github.com/birkenfeld/gitcodesmell

Last synced: 3 days ago
JSON representation

Git hook checking for "smelly" changes in files (debugging leftovers, merge markers etc.) before committing

Awesome Lists containing this project

README

        

Git codesmell hook
==================

This hook should be used as/during ``pre-commit``. It checks added lines
for common "smelly" changes. If it finds any, it will show them and prompt
whether to continue committing.

Smelly patterns that are currently recognized are:

* vim "quit" commands that leak into the file because of wrong mode
* merge conflict markers (``<<<<<<<`` and ``>>>>>>>``)
* Windows newlines (only on non-Windows platforms)

Language-specific (Python):

* ``pdb.set_trace()``
* ``1/0``
* ``print`` statements
(This is going to produce false positives, but print statements
are also the debugging tool #1 for Python)
* bare ``raise`` statements
* ``traceback.print_*`` calls

Language-specific (JavaScript):

* ``debugger;`` statements inside of Javascript files

You can add more of them by editing gitcodesmell.py's ``SMELLY_STUFF``
dictionary.

Example output::

git-[master] gbr@georg ~/devel/gitcodesmell> git commit
Smelly change (set_trace):

diff --git a/gitcodesmell.py b/gitcodesmell.py
index b40559d..8629850 100755
--- a/gitcodesmell.py
@@ -64,6 +64,7 @@ def write_colored(diff):
def main():
smelly_count = 0
chunklines = os.popen('git diff --staged').readlines()
+ import pdb; pdb.set_trace()

indexline = 0
hunkstart = 0

Found 1 smelly change. Continue (y/N)?

This hook is copyright 2015 by Georg Brandl, and can be
distributed under the GNU GPL version 2 or later.