Skip to content

Instantly share code, notes, and snippets.

@ysimonson
Created April 20, 2017 00:39
Show Gist options
  • Save ysimonson/c68ce68cb08d676694c0afaef38a036c to your computer and use it in GitHub Desktop.
Save ysimonson/c68ce68cb08d676694c0afaef38a036c to your computer and use it in GitHub Desktop.
Search for mixed tabs/spaces in files
#!/usr/bin/env python3
# Uses python3. Example: `python3 mixed_tabs_spaces.py '**/*.py'`
import glob
import sys
def has_mixed_tabs_spaces(f):
has_spaces = False
has_tabs = False
for line in f:
if line.startswith(" "):
if has_tabs:
return True
has_spaces = True
if line.startswith("\t"):
if has_spaces:
return True
has_tabs = True
return False
def main():
pattern = sys.argv[1] if len(sys.argv) > 1 else "*"
for filepath in glob.iglob(pattern, recursive=True):
with open(filepath, "r") as f:
if has_mixed_tabs_spaces(f):
print(filepath)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment