about summary refs log tree commit diff
path: root/src/etc/tidy.py
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-07 11:26:29 -0800
committerbors <bors@rust-lang.org>2014-02-07 11:26:29 -0800
commit56565eb129018a708445afcd6ea14f5b51cf27e5 (patch)
tree6ac3203e6798df65908f65ec403f99f19400bea3 /src/etc/tidy.py
parentca40da8b55a04394f1db11b6c7410e49b63c6e04 (diff)
parent730bdb6403dd47b98c1be6c4b3423edb28ca9477 (diff)
downloadrust-56565eb129018a708445afcd6ea14f5b51cf27e5.tar.gz
rust-56565eb129018a708445afcd6ea14f5b51cf27e5.zip
auto merge of #12055 : dguenther/rust/tidy_test, r=alexcrichton
This PR extends the tidy formatting check to rust files in the test folder. To facilitate this, a few flags were added to tidy:

* `xfail-tidy-cr` - Disables the check for CR characters for all following lines in the file
* `xfail-tidy-tab` - Disables the check for tab characters for all following lines in the file
* `xfail-tidy-linelength` - Disables the line length check for all following lines in the file

Checks should not have to be disabled often. I disabled line length checks in `debug-info` tests that use `debugger:` checks, but aside from that, there were relatively few exclusions. Running tidy on all the tests does slow down the formatting check, so it may be worth investigating further optimization.

cc #4534
Diffstat (limited to 'src/etc/tidy.py')
-rw-r--r--src/etc/tidy.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/etc/tidy.py b/src/etc/tidy.py
index b342b9602ae..9bab9a3d998 100644
--- a/src/etc/tidy.py
+++ b/src/etc/tidy.py
@@ -14,6 +14,9 @@ import snapshot
 
 err=0
 cols=100
+cr_flag="xfail-tidy-cr"
+tab_flag="xfail-tidy-tab"
+linelength_flag="xfail-tidy-linelength"
 
 # Be careful to support Python 2.4, 2.6, and 3.x here!
 config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ],
@@ -46,12 +49,22 @@ file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
 
 current_name = ""
 current_contents = ""
+check_tab = True
+check_cr = True
+check_linelength = True
+
 
 try:
     for line in fileinput.input(file_names,
                                 openhook=fileinput.hook_encoded("utf-8")):
 
         if fileinput.filename().find("tidy.py") == -1:
+            if line.find(cr_flag) != -1:
+                check_cr = False
+            if line.find(tab_flag) != -1:
+                check_tab = False
+            if line.find(linelength_flag) != -1:
+                check_linelength = False
             if line.find("// XXX") != -1:
                 report_err("XXX is no longer necessary, use FIXME")
             if line.find("TODO") != -1:
@@ -72,16 +85,16 @@ try:
                 if "SNAP" in line:
                     report_warn("unmatched SNAP line: " + line)
 
-        if (line.find('\t') != -1 and
+        if check_tab and (line.find('\t') != -1 and
             fileinput.filename().find("Makefile") == -1):
             report_err("tab character")
-        if not autocrlf and line.find('\r') != -1:
+        if check_cr and not autocrlf and line.find('\r') != -1:
             report_err("CR character")
         if line.endswith(" \n") or line.endswith("\t\n"):
             report_err("trailing whitespace")
         line_len = len(line)-2 if autocrlf else len(line)-1
 
-        if line_len > cols:
+        if check_linelength and line_len > cols:
             report_err("line longer than %d chars" % cols)
 
         if fileinput.isfirstline() and current_name != "":
@@ -90,6 +103,9 @@ try:
         if fileinput.isfirstline():
             current_name = fileinput.filename()
             current_contents = ""
+            check_cr = True
+            check_tab = True
+            check_linelength = True
 
         current_contents += line