File: lint.sh

package info (click to toggle)
hare 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,756 kB
  • sloc: asm: 1,180; sh: 119; makefile: 116; lisp: 99
file content (54 lines) | stat: -rwxr-xr-x 1,201 bytes parent folder | download | duplicates (2)
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
#!/bin/sh -eu

# XXX: technically doesn't work with paths that have newlines in them, but
# find -exec doesn't propagate the exit status
find . -name '*.ha' | while read -r f; do
	awk 'BEGIN { state = "start" }
		/./ { empty = 0 }
		/^$/ { empty = 1 }
		/[ \t]$/ {
			print "trailing whitespace in " FILENAME
			exit 1
		}
		state == "start" {
			if ($0 !~ /^\/\/ SPDX-License-Identifier: /) {
				print "missing copyright header in " FILENAME
				exit 1
			}
			state = "author"
			next
		}
		state == "author" {
			if ($0 != "// (c) Hare authors <https://harelang.org>") {
				print "invalid authorship information in " FILENAME
				exit 1
			}
			state = "comment"
			next
		}
		state == "comment" && $0 !~ /^\/\// {
			if ($0 != "") {
				print "missing empty line after copyright header in " FILENAME
				exit 1
			}
			state = "postheader"
			next
		}
		state == "postheader" {
			if ($0 == "") {
				print "extra empty line after copyright header in " FILENAME
				exit 1
			}
			state = "body"
		}
		END {
			if (state != "body") {
				print "incomplete copyright header in " FILENAME
				exit 1
			}
			if (empty) {
				print "trailing empty line in " FILENAME
				exit 1
			}
		}' "$f"
done