hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

lint.sh (1201B)


      1 #!/bin/sh -eu
      2 
      3 # XXX: technically doesn't work with paths that have newlines in them, but
      4 # find -exec doesn't propagate the exit status
      5 find . -name '*.ha' | while read -r f; do
      6 	awk 'BEGIN { state = "start" }
      7 		/./ { empty = 0 }
      8 		/^$/ { empty = 1 }
      9 		/[ \t]$/ {
     10 			print "trailing whitespace in " FILENAME
     11 			exit 1
     12 		}
     13 		state == "start" {
     14 			if ($0 !~ /^\/\/ SPDX-License-Identifier: /) {
     15 				print "missing copyright header in " FILENAME
     16 				exit 1
     17 			}
     18 			state = "author"
     19 			next
     20 		}
     21 		state == "author" {
     22 			if ($0 != "// (c) Hare authors <https://harelang.org>") {
     23 				print "invalid authorship information in " FILENAME
     24 				exit 1
     25 			}
     26 			state = "comment"
     27 			next
     28 		}
     29 		state == "comment" && $0 !~ /^\/\// {
     30 			if ($0 != "") {
     31 				print "missing empty line after copyright header in " FILENAME
     32 				exit 1
     33 			}
     34 			state = "postheader"
     35 			next
     36 		}
     37 		state == "postheader" {
     38 			if ($0 == "") {
     39 				print "extra empty line after copyright header in " FILENAME
     40 				exit 1
     41 			}
     42 			state = "body"
     43 		}
     44 		END {
     45 			if (state != "body") {
     46 				print "incomplete copyright header in " FILENAME
     47 				exit 1
     48 			}
     49 			if (empty) {
     50 				print "trailing empty line in " FILENAME
     51 				exit 1
     52 			}
     53 		}' "$f"
     54 done