check-trailing-newline 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env guile
  2. -*- scheme -*-
  3. !#
  4. ;;; check-trailing-newline -- Find files lacking a trailing newline
  5. ;;; Use guile 2 (not 1.8)
  6. ;;; Copyright (C) 2015 Mark H Weaver <mhw@netris.org>
  7. ;;;
  8. ;;; This program is free software: you can redistribute it and/or modify
  9. ;;; it under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation, either version 3 of the License, or
  11. ;;; (at your option) any later version.
  12. ;;;
  13. ;;; This program is distributed in the hope that it will be useful,
  14. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. (use-modules (ice-9 match)
  21. (rnrs io ports))
  22. (define (check-file file-name)
  23. (let ((contents (call-with-input-file file-name get-string-all)))
  24. (unless (string-suffix? "\n" contents)
  25. (format (current-error-port)
  26. "~a: lacks trailing newline\n"
  27. file-name))))
  28. (match (command-line)
  29. ((_ file-names ...)
  30. (for-each check-file file-names)))