lint: formatting: Detect sexp boundaries.
* guix/scripts/lint.scm (report-formatting-issues)[last-line]: Remove. [sexp-last-line]: New procedure. Use it.
This commit is contained in:
parent
269504a797
commit
9081a776ea
|
@ -878,24 +878,39 @@ move to the previous or next line")
|
||||||
#:key (reporters %formatting-reporters))
|
#:key (reporters %formatting-reporters))
|
||||||
"Report white-space issues in FILE starting from STARTING-LINE, and report
|
"Report white-space issues in FILE starting from STARTING-LINE, and report
|
||||||
them for PACKAGE."
|
them for PACKAGE."
|
||||||
(define last-line
|
(define (sexp-last-line port)
|
||||||
;; Number of the presumed last line.
|
;; Return the last line of the sexp read from PORT or an estimate thereof.
|
||||||
;; XXX: Ideally we'd stop at the boundaries of the surrounding sexp, but
|
(define &failure (list 'failure))
|
||||||
;; for now just use this simple heuristic.
|
|
||||||
(+ starting-line 60))
|
(let ((start (ftell port))
|
||||||
|
(start-line (port-line port))
|
||||||
|
(sexp (catch 'read-error
|
||||||
|
(lambda () (read port))
|
||||||
|
(const &failure))))
|
||||||
|
(let ((line (port-line port)))
|
||||||
|
(seek port start SEEK_SET)
|
||||||
|
(set-port-line! port start-line)
|
||||||
|
(if (eq? sexp &failure)
|
||||||
|
(+ start-line 60) ;conservative estimate
|
||||||
|
line))))
|
||||||
|
|
||||||
(call-with-input-file file
|
(call-with-input-file file
|
||||||
(lambda (port)
|
(lambda (port)
|
||||||
(let loop ((line-number 1))
|
(let loop ((line-number 1)
|
||||||
|
(last-line #f))
|
||||||
(let ((line (read-line port)))
|
(let ((line (read-line port)))
|
||||||
(or (eof-object? line)
|
(or (eof-object? line)
|
||||||
(> line-number last-line)
|
(and last-line (> line-number last-line))
|
||||||
|
(if (and (= line-number starting-line)
|
||||||
|
(not last-line))
|
||||||
|
(loop (+ 1 line-number)
|
||||||
|
(+ 1 (sexp-last-line port)))
|
||||||
(begin
|
(begin
|
||||||
(unless (< line-number starting-line)
|
(unless (< line-number starting-line)
|
||||||
(for-each (lambda (report)
|
(for-each (lambda (report)
|
||||||
(report package line line-number))
|
(report package line line-number))
|
||||||
reporters))
|
reporters))
|
||||||
(loop (+ 1 line-number)))))))))
|
(loop (+ 1 line-number) last-line)))))))))
|
||||||
|
|
||||||
(define (check-formatting package)
|
(define (check-formatting package)
|
||||||
"Check the formatting of the source code of PACKAGE."
|
"Check the formatting of the source code of PACKAGE."
|
||||||
|
|
Loading…
Reference in New Issue