Skip to content

Commit c7600fc

Browse files
authored
eask analyze should exit with 1 on errors (#359)
1 parent a2b5554 commit c7600fc

File tree

14 files changed

+497
-37
lines changed

14 files changed

+497
-37
lines changed

lisp/core/analyze.el

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@
2929
(defvar eask-analyze--warnings nil)
3030
(defvar eask-analyze--errors nil)
3131

32+
;; Warning flag
33+
(defvar eask-analyze--warning-p nil)
34+
;; Error flag
35+
(defvar eask-analyze--error-p nil)
36+
3237
(defun eask-analyze--pretty-json (json)
3338
"Return pretty JSON."
3439
(with-temp-buffer (insert json) (json-pretty-print-buffer) (buffer-string)))
3540

3641
(defun eask-analyze--load-buffer ()
3742
"Return the current file loading session."
38-
(car (cl-remove-if-not
39-
(lambda (elm) (string-prefix-p " *load*-" (buffer-name elm))) (buffer-list))))
43+
(car (cl-remove-if-not (lambda (elm)
44+
(string-prefix-p " *load*-" (buffer-name elm)))
45+
(buffer-list))))
4046

4147
(defun eask-analyze--write-json-format (level msg)
4248
"Prepare log for JSON format.
@@ -87,6 +93,10 @@ information."
8793
8894
Argument LEVEL and MSG are data from the debug log signal."
8995
(unless (string= " *temp*" (buffer-name)) ; avoid error from `package-file' directive
96+
(when (eq 'error level)
97+
(setq eask-analyze--error-p t))
98+
(when (eq 'warn level)
99+
(setq eask-analyze--warning-p t))
90100
(with-current-buffer (or (eask-analyze--load-buffer) (buffer-name))
91101
(funcall
92102
(cond ((eask-json-p) #'eask-analyze--write-json-format)
@@ -100,19 +110,22 @@ Argument LEVEL and MSG are data from the debug log signal."
100110
(dolist (file files)
101111
(eask--silent-error
102112
(eask--save-load-eask-file file
113+
(push file checked-files)
114+
;; also count files with errors in the total count
103115
(push file checked-files))))
104116

105117
;; Print result
106118
(eask-msg "")
107-
(cond ((and (eask-json-p) ; JSON format
108-
(or eask-analyze--warnings eask-analyze--errors))
109-
(setq content
110-
(eask-analyze--pretty-json (json-encode
111-
`((warnings . ,eask-analyze--warnings)
112-
(errors . ,eask-analyze--errors)))))
119+
(cond ((eask-json-p) ; JSON format
120+
;; Fill content with result.
121+
(when (or eask-analyze--warnings eask-analyze--errors)
122+
(setq content
123+
(eask-analyze--pretty-json (json-encode
124+
`((warnings . ,eask-analyze--warnings)
125+
(errors . ,eask-analyze--errors))))))
113126
;; XXX: When printing the result, no color allow.
114127
(eask--with-no-color
115-
(eask-msg content)))
128+
(eask-msg (or content "{}"))))
116129
(eask-analyze--log ; Plain text
117130
(setq content
118131
(with-temp-buffer
@@ -121,11 +134,11 @@ Argument LEVEL and MSG are data from the debug log signal."
121134
(buffer-string)))
122135
;; XXX: When printing the result, no color allow.
123136
(eask--with-no-color
124-
(mapc #'eask-msg (reverse eask-analyze--log))))
125-
(t
126-
(eask-info "(Checked %s file%s)"
127-
(length checked-files)
128-
(eask--sinr checked-files "" "s"))))
137+
(mapc #'eask-msg (reverse eask-analyze--log)))))
138+
139+
(eask-info "(Checked %s file%s)"
140+
(length checked-files)
141+
(eask--sinr checked-files "" "s"))
129142

130143
;; Output file
131144
(when (and content (eask-output))
@@ -148,7 +161,11 @@ Argument LEVEL and MSG are data from the debug log signal."
148161
(cond
149162
;; Files found, do the action!
150163
(files
151-
(eask-analyze--file files))
164+
(eask-analyze--file files)
165+
(when (or eask-analyze--error-p
166+
;; strict flag turns warnings into errors
167+
(and eask-analyze--warning-p (eask-strict-p)))
168+
(eask--exit 'failure)))
152169
;; Pattern defined, but no file found!
153170
(patterns
154171
(eask-info "(No files match wildcard: %s)"

0 commit comments

Comments
 (0)