Function: bazel-mode-flymake
bazel-mode-flymake is a natively compiled function defined in
bazel.el.
Signature
(bazel-mode-flymake REPORT-FN &rest KEYS)
Documentation
Flymake backend function for ‘bazel-mode’.
Use REPORT-FN to report linter warnings found by Buildifier. See
URL
‘https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md’
for how to install Buildifier. The function ‘bazel-mode’ adds
this function to ‘flymake-diagnostic-functions’. See Info node
(Flymake) Backend functions for details about Flymake
backends.
Source Code
;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
(defun bazel-mode-flymake (report-fn &rest _keys)
"Flymake backend function for ‘bazel-mode’.
Use REPORT-FN to report linter warnings found by Buildifier. See
URL
‘https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md’
for how to install Buildifier. The function ‘bazel-mode’ adds
this function to ‘flymake-diagnostic-functions’. See Info node
‘(Flymake) Backend functions’ for details about Flymake
backends."
(declare (ftype (function ((function (t &rest t) t) &rest t) null)))
(cl-check-type report-fn function)
(when-let* ((process bazel--flymake-process))
;; The order here is important: ‘delete-process’ will trigger the sentinel,
;; and then ‘bazel--flymake-process’ already has to be nil to avoid an
;; obsolete report.
(setq bazel--flymake-process nil)
(delete-process process))
(let* ((non-essential t)
(command `(,bazel-buildifier-command
,@(bazel--buildifier-file-flags bazel--buildifier-type
buffer-file-name)
"-mode=check" "-format=json" "-lint=warn"))
(input-buffer (current-buffer))
(output-buffer (generate-new-buffer
(format " *Buildifier output for %s*" (buffer-name))))
(error-buffer (generate-new-buffer
(format " *Buildifier errors for %s*" (buffer-name))))
(sentinel
(lambda (process event)
(let ((success (string-equal event "finished\n")))
;; First, make sure that the buffer to be linted is still alive.
(when (buffer-live-p input-buffer)
(with-current-buffer input-buffer
;; Don’t report anything if a new process has already been
;; started.
(when (eq bazel--flymake-process process)
;; Report even in case of failure so that Flymake doesn’t
;; treat the backend as continuously running.
(funcall report-fn
(and success
(bazel--make-diagnostics output-buffer)))
(setq bazel--flymake-process nil))))
(if success
(progn (kill-buffer output-buffer)
(kill-buffer error-buffer))
(flymake-log :warning
(concat "Buildifier process failed; "
"see buffers ‘%s’ and ‘%s’ for details")
output-buffer error-buffer)))))
;; We always start a local process, even if visiting a remote
;; filename. If Buildifier is installed locally, the reports should
;; match well enough. Starting a remote process via Tramp tends to be
;; way too slow to run interactively.
(process (make-process :name (format "Buildifier for %s" (buffer-name))
:buffer output-buffer
:command command
:coding '(utf-8-unix . utf-8-unix)
:connection-type 'pipe
:noquery t
:sentinel sentinel
:stderr error-buffer)))
(setq bazel--flymake-process process)
(without-restriction
(process-send-region process (point-min) (point-max)))
(process-send-eof process))
nil)