[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/02: lint: Report lonely parentheses.
From: |
Ludovic Courtès |
Subject: |
02/02: lint: Report lonely parentheses. |
Date: |
Fri, 18 Sep 2015 19:54:55 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit e0566f12f8b57f3311c9aba1737e791763e89544
Author: Ludovic Courtès <address@hidden>
Date: Fri Sep 18 21:49:51 2015 +0200
lint: Report lonely parentheses.
* guix/scripts/lint.scm (%hanging-paren-rx): New variable.
(report-lone-parentheses): New procedure.
(%formatting-reporters): Use it.
* tests/lint.scm ("formatting: lonely parentheses"): New test.
---
guix/scripts/lint.scm | 15 ++++++++++++++-
tests/lint.scm | 10 ++++++++++
2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index 26b4018..8224f54 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -594,12 +594,25 @@ descriptions maintained upstream."
(format #f (_ "line ~a is way too long (~a characters)")
line-number (string-length line)))))
+(define %hanging-paren-rx
+ (make-regexp "^[[:blank:]]*[()]+[[:blank:]]*$"))
+
+(define (report-lone-parentheses package line line-number)
+ "Emit a warning if LINE contains hanging parentheses."
+ (when (regexp-exec %hanging-paren-rx line)
+ (emit-warning package
+ (format #f
+ (_ "line ~a: parentheses feel lonely, \
+move to the previous or next line")
+ line-number))))
+
(define %formatting-reporters
;; List of procedures that report formatting issues. These are not separate
;; checkers because they would need to re-read the file.
(list report-tabulations
report-trailing-white-space
- report-long-line))
+ report-long-line
+ report-lone-parentheses))
(define* (report-formatting-issues package file starting-line
#:key (reporters %formatting-reporters))
diff --git a/tests/lint.scm b/tests/lint.scm
index 9634fb6..3f14956 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -512,6 +512,16 @@ requests."
(check-source pkg))))
"not reachable: 404")))
+(test-assert "formatting: lonely parentheses"
+ (string-contains
+ (with-warnings
+ (check-formatting
+ (
+ dummy-package "ugly as hell!"
+ )
+ ))
+ "lonely"))
+
(test-assert "formatting: tabulation"
(string-contains
(with-warnings