forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-whitespace.jl
executable file
·56 lines (50 loc) · 1.31 KB
/
check-whitespace.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env julia
const patterns = split("""
*.1
*.c
*.cpp
*.h
*.inc
*.jl
*.lsp
*.make
*.md
*.mk
*.rst
*.scm
*.sh
*.yml
*Makefile
""")
const errors = Set{Tuple{String,Int,String}}()
for path in eachline(`git ls-files -- $patterns`)
lineno = 0
non_blank = 0
file_err(msg) = push!(errors, (path, 0, msg))
line_err(msg) = push!(errors, (path, lineno, msg))
isfile(path) || continue
for line in eachline(path, keep=true)
lineno += 1
contains(line, '\r') && file_err("non-UNIX line endings")
contains(line, '\ua0') && line_err("non-breaking space")
endswith(line, '\n') || line_err("no trailing newline")
line = chomp(line)
endswith(line, r"\s") && line_err("trailing whitespace")
contains(line, r"\S") && (non_blank = lineno)
end
non_blank < lineno && line_err("trailing blank lines")
end
if isempty(errors)
println(stderr, "Whitespace check found no issues.")
exit(0)
else
println(stderr, "Whitespace check found $(length(errors)) issues:")
for (path, lineno, msg) in sort!(collect(errors))
if lineno == 0
println(stderr, "$path -- $msg")
else
println(stderr, "$path:$lineno -- $msg")
end
end
exit(1)
end