Last active
December 17, 2015 17:19
-
-
Save v6ak/5645070 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Copyright © 2013 Vít Šesták <http://contact.v6ak.com> | |
| # This work is free. It comes without any warranty, to the extent | |
| # permitted by applicable law. You can redistribute it and/or modify it | |
| # under the terms of the Do What The Fuck You Want To Public License, | |
| # Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for | |
| # more details. | |
| ######################################################################## | |
| # Looks for bad usage of tab characters. | |
| # | |
| # It is OK when you use tabs for indentation, e.g.: | |
| # GOOD tab practice: | |
| # <TAB>appendDup_X1(OBJECT, OBJECT) | |
| # <TAB>appendSwap(OBJECT, OBJECT) | |
| # | |
| # However, if you use a tab after a non-tab characted, it smells. It may break when you change tab size in your editor. For example: | |
| # BAD tab practice: | |
| # <TAB>appendDup_X1(OBJECT, OBJECT)<TAB><TAB><TAB><TAB><TAB><TAB>// OS: r hu wv hu | |
| # <TAB>appendSwap(OBJECT, OBJECT)<TAB><TAB><TAB><TAB><TAB><TAB><TAB>// OS: r hu hu wv | |
| # While this will look OK for tab size = 4, it can break for other tab sizes. So you should use spaces rather than tabs there. | |
| # | |
| # This script also detects bad tab and spaces mixing. It is expected that you use tabs for indentation. | |
| # Any space used for indentation is considered as bad. For example: | |
| # BAD tab practice: | |
| # <TAB>appendDup_X1(OBJECT, OBJECT) | |
| # <SPACE><SPACE>appendSwap(OBJECT, OBJECT) | |
| # This works well if and only if tab size is exactly 2. | |
| # | |
| # All tabs on the output are replaced by red "<TAB>" text. | |
| # Line numbers are added to the output. | |
| # When you add multiple files, they all are checked. File names are also added to the output in such case. | |
| ######################################################################## | |
| grep -n -E $'([^\t]\t)|(^(\t*) )' "$@" | sed 's/\t/'`printf "\033[31m<TAB>\033[0m"`'/g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment