[llvm-commits] update of patch for simple style checker

Eric Christopher echristo at apple.com
Wed May 30 16:52:03 PDT 2012


Here's the one I use, it's a bit more portable:

#!/usr/bin/env python

import sys, fileinput, subprocess

err=0
cols=80

# Be careful to support Python 2.4, 2.6, and 3.x here!
config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ],
    stdout=subprocess.PIPE)
result=config_proc.communicate()[0]

true="true".encode('utf8')
autocrlf=result.strip() == true if result is not None else False

def report_err(s):
    global err
    print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s))
    err=1

for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")):
    if line.find('\t') != -1 and fileinput.filename().find("Makefile") == -1:
        report_err("tab character")

    if not autocrlf and line.find('\r') != -1:
        report_err("CR character")

    line_len = len(line)-2 if autocrlf else len(line)-1
    if line_len > cols:
        report_err("line longer than %d chars" % cols)


sys.exit(err)

example: tidy.py *
or
find . -type f -print | xargs tidy.py

-eric

On May 30, 2012, at 4:40 PM, reed kotler <rkotler at mips.com> wrote:

> Added check for whitespace at the end of a line.
> 
> File is new file for utils
> ubuntu-rkotler:~/llvm_conventions> python style_check.py --help
> Usage: style_check.py arg1 arg2 ... argn [options]
> 
> Options:
>  -h, --help            show this help message and exit
>  --no-check-for-tabs   don't check for tabs
>  --no-check-line-length
>                        don't check line length
>  --max-line-length=MAXLINELENGTH
>                        specify maximum line length [default 80]
>  --no-check-whitespace-at-eol
>                        don't check for whitespace at the end of a line
> 
> 
> 
> <style_check_patch2.txt>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list