From fb4ce2e9b9f7703bd38a2acc2595a02f3822cac7 Mon Sep 17 00:00:00 2001 From: mgmarlow Date: Sun, 30 Jul 2023 12:24:17 -0700 Subject: Rename to flymake-clippy for MELPA release --- Makefile | 6 +-- README.md | 22 ++++----- clippy-flymake-test.el | 29 ------------ clippy-flymake.el | 121 ------------------------------------------------- flymake-clippy-test.el | 29 ++++++++++++ flymake-clippy.el | 121 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 164 insertions(+), 164 deletions(-) delete mode 100644 clippy-flymake-test.el delete mode 100644 clippy-flymake.el create mode 100644 flymake-clippy-test.el create mode 100644 flymake-clippy.el diff --git a/Makefile b/Makefile index 8045ed2..e060d64 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ .PHONY: build test clean test: build - emacs -batch -l ert -L . -l clippy-flymake-test.el -f ert-run-tests-batch-and-exit + emacs -batch -l ert -L . -l flymake-clippy-test.el -f ert-run-tests-batch-and-exit build: clean - emacs -batch -L . -f batch-byte-compile clippy-flymake.el + emacs -batch -L . -f batch-byte-compile flymake-clippy.el clean: - rm -f clippy-flymake.elc + rm -f flymake-clippy.elc diff --git a/README.md b/README.md index 02854a8..b937488 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# clippy-flymake +# flymake-clippy A Flymake backend for [Clippy](https://doc.rust-lang.org/stable/clippy/index.html), the Rust linter. @@ -9,20 +9,20 @@ You probably want to install [rust-mode](https://github.com/rust-lang/rust-mode) With Emacs 30: ``` elisp -(use-package clippy-flymake - :vc (:url "https://git.sr.ht/~mgmarlow/clippy-flymake" :branch main) - :hook (rust-mode . clippy-flymake-setup-backend)) +(use-package flymake-clippy + :vc (:url "https://git.sr.ht/~mgmarlow/flymake-clippy" :branch main) + :hook (rust-mode . flymake-clippy-setup-backend)) ``` Alternatively, clone the repo and update your load path: ``` -git clone https://git.sr.ht/~mgmarlow/clippy-flymake /path/to/clippy-flymake +git clone https://git.sr.ht/~mgmarlow/flymake-clippy /path/to/flymake-clippy ``` ```elisp -(add-to-list 'load-path "/path/to/clippy-flymake") -(require 'clippy-flymake) +(add-to-list 'load-path "/path/to/flymake-clippy") +(require 'flymake-clippy) ``` Emacs versions prior to 30 can also install [use-package](https://github.com/jwiegley/use-package) and [vc-use-package](https://github.com/slotThe/vc-use-package) for an easier setup. @@ -50,7 +50,7 @@ You can confirm that Flymake is running correctly by opening up a Rust buffer an ``` M-x flymake-running-backends -Running backends: clippy-flymake-backend, eglot-flymake-backend +Running backends: flymake-clippy-backend, eglot-flymake-backend ``` ### Complete eglot + rust-mode + use-package example @@ -61,9 +61,9 @@ Emacs 30, eglot 1.6+: (use-package rust-mode :ensure t) -(use-package clippy-flymake - :vc (:url "https://git.sr.ht/~mgmarlow/clippy-flymake" :branch main) - :hook (rust-mode . clippy-flymake-setup-backend)) +(use-package flymake-clippy + :vc (:url "https://git.sr.ht/~mgmarlow/flymake-clippy" :branch main) + :hook (rust-mode . flymake-clippy-setup-backend)) (defun manually-activate-flymake () (add-hook 'flymake-diagnostic-functions #'eglot-flymake-backend nil t) diff --git a/clippy-flymake-test.el b/clippy-flymake-test.el deleted file mode 100644 index 6039824..0000000 --- a/clippy-flymake-test.el +++ /dev/null @@ -1,29 +0,0 @@ -;;; clippy-flymake-test.el -*- lexical-binding: t; -*- - -(require 'clippy-flymake) -(require 'ert) - -(defun run-regexp () - (set-match-data nil) - (search-forward-regexp (clippy-flymake--build-regexp) nil t) - (list (match-string 1) - (match-string 2) - (match-string 3))) - -(ert-deftest clippy-test-regexp () - "Tests regexp matches diagnostic information." - (should (equal (with-temp-buffer - (insert-file-contents "./test/fixture.txt") - (run-regexp)) - '("warning: unused variable: `user`" "src/database/foo.rs" "42"))) - (should (equal (with-temp-buffer - (insert-file-contents "./test/fixture.txt") - (run-regexp) - (run-regexp)) - '("warning: using `clone` on type `Status` which implements the `Copy` trait" "src/foo.rs" "31"))) - (should (equal (with-temp-buffer - (insert-file-contents "./test/fixture.txt") - (run-regexp) - (run-regexp) - (run-regexp)) - '("warning: unused variable: `user`" "src/foobar/user.rs" "42")))) diff --git a/clippy-flymake.el b/clippy-flymake.el deleted file mode 100644 index 205f5a1..0000000 --- a/clippy-flymake.el +++ /dev/null @@ -1,121 +0,0 @@ -;;; clippy-flymake.el --- Flymake backend for Clippy -*- lexical-binding: t; -*- - -;; Copyright (C) 2023 Graham Marlow - -;; Author: Graham Marlow -;; Keywords: tools -;; URL: https://sr.ht/~mgmarlow/clippy-flymake/ -;; Version: 1.0.0 -;; Package-Requires: ((emacs "26.1")) - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; Flymake backend for Clippy, the Rust linter. -;; https://doc.rust-lang.org/stable/clippy/index.html - -;;; Code: - -(require 'cl-lib) - -;; Capture group source example: -;; "warning: ..." -;; --> src/filename.rs -;; 98 | ... -(defun clippy-flymake--build-regexp () - "Create a regular expression to search Clippy warnings for FILENAME." - (rx (seq line-start - ;; Message - (group (or "warning:" "error:") - (zero-or-more nonl)) - "\n" - (zero-or-more nonl) - "--> " - ;; File - (group - (zero-or-more nonl)) - ":" - ;; Line - (group - (one-or-more - (any "0-9"))) - ":" - ;; Col - (group - (one-or-more - (any "0-9"))) - line-end))) - -(defvar-local clippy-flymake--proc nil - "Clippy subprocess object, used to ensure obsolete processes aren't reused.") - -(defun clippy-flymake-backend (report-fn &rest _args) - "Flymake backend for Clippy, the Rust linter. - -Calls REPORT-FN with a list of Flymake diagnostics for the -current buffer. - -Use `clippy-flymake-setup-backend' to register the backend -with the appropriate Flymake hook." - (unless (executable-find "cargo") - (error "Cannot find cargo")) - - (let* ((source (current-buffer)) - (filename (buffer-file-name source))) - (save-restriction - (widen) - (setq clippy-flymake--proc - (make-process - :name "clippy-flymake" :noquery t :connection-type 'pipe - :buffer (generate-new-buffer "*clippy-flymake*") - :command '("cargo" "clippy") - :sentinel - (lambda (proc _event) - (when (memq (process-status proc) '(exit signal)) - (unwind-protect - (if (with-current-buffer source (eq proc clippy-flymake--proc)) - (with-current-buffer (process-buffer proc) - (goto-char (point-min)) - ;; Collect output buffer into diagnostic messages/locations, - ;; exposing them via `report-fn'. - (cl-loop - while (search-forward-regexp - (clippy-flymake--build-regexp) - nil t) - for msg = (match-string 1) - for sourcefile = (match-string 2) - for (beg . end) = (flymake-diag-region - source - (string-to-number (match-string 3))) - for type = (if (string-match "^warning" msg) - :warning - :error) - when (and sourcefile (string-match-p sourcefile filename)) - collect (flymake-make-diagnostic source beg end type msg) - into diags - finally (funcall report-fn diags))) - (flymake-log :warning "Canceling obsolete check %s" proc)) - ;; Cleanup temp buffer. - (kill-buffer (process-buffer proc))))))) - (process-send-region clippy-flymake--proc (point-min) (point-max)) - (process-send-eof clippy-flymake--proc)))) - -(defun clippy-flymake-setup-backend () - "Add `clippy-flymake' to `flymake-diagnostic-functions' hook." - (add-hook 'flymake-diagnostic-functions #'clippy-flymake-backend nil t)) - -(provide 'clippy-flymake) - -;;; clippy-flymake.el ends here diff --git a/flymake-clippy-test.el b/flymake-clippy-test.el new file mode 100644 index 0000000..0cc3018 --- /dev/null +++ b/flymake-clippy-test.el @@ -0,0 +1,29 @@ +;;; flymake-clippy-test.el -*- lexical-binding: t; -*- + +(require 'flymake-clippy) +(require 'ert) + +(defun run-regexp () + (set-match-data nil) + (search-forward-regexp (flymake-clippy--build-regexp) nil t) + (list (match-string 1) + (match-string 2) + (match-string 3))) + +(ert-deftest clippy-test-regexp () + "Tests regexp matches diagnostic information." + (should (equal (with-temp-buffer + (insert-file-contents "./test/fixture.txt") + (run-regexp)) + '("warning: unused variable: `user`" "src/database/foo.rs" "42"))) + (should (equal (with-temp-buffer + (insert-file-contents "./test/fixture.txt") + (run-regexp) + (run-regexp)) + '("warning: using `clone` on type `Status` which implements the `Copy` trait" "src/foo.rs" "31"))) + (should (equal (with-temp-buffer + (insert-file-contents "./test/fixture.txt") + (run-regexp) + (run-regexp) + (run-regexp)) + '("warning: unused variable: `user`" "src/foobar/user.rs" "42")))) diff --git a/flymake-clippy.el b/flymake-clippy.el new file mode 100644 index 0000000..2ecf61e --- /dev/null +++ b/flymake-clippy.el @@ -0,0 +1,121 @@ +;;; flymake-clippy.el --- Flymake backend for Clippy -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 Graham Marlow + +;; Author: Graham Marlow +;; Keywords: tools +;; URL: https://sr.ht/~mgmarlow/flymake-clippy/ +;; Version: 1.0.0 +;; Package-Requires: ((emacs "26.1")) + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Flymake backend for Clippy, the Rust linter. +;; https://doc.rust-lang.org/stable/clippy/index.html + +;;; Code: + +(require 'cl-lib) + +;; Capture group source example: +;; "warning: ..." +;; --> src/filename.rs +;; 98 | ... +(defun flymake-clippy--build-regexp () + "Regexp for Clippy output." + (rx (seq line-start + ;; Message + (group (or "warning:" "error:") + (zero-or-more nonl)) + "\n" + (zero-or-more nonl) + "--> " + ;; File + (group + (zero-or-more nonl)) + ":" + ;; Line + (group + (one-or-more + (any "0-9"))) + ":" + ;; Col + (group + (one-or-more + (any "0-9"))) + line-end))) + +(defvar-local flymake-clippy--proc nil + "Clippy subprocess object, used to ensure obsolete processes aren't reused.") + +(defun flymake-clippy-backend (report-fn &rest _args) + "Flymake backend for Clippy, the Rust linter. + +Calls REPORT-FN with a list of Flymake diagnostics for the +current buffer. + +Use `flymake-clippy-setup-backend' to register the backend +with the appropriate Flymake hook." + (unless (executable-find "cargo") + (error "Cannot find cargo")) + + (let* ((source (current-buffer)) + (filename (buffer-file-name source))) + (save-restriction + (widen) + (setq flymake-clippy--proc + (make-process + :name "flymake-clippy" :noquery t :connection-type 'pipe + :buffer (generate-new-buffer "*flymake-clippy*") + :command '("cargo" "clippy") + :sentinel + (lambda (proc _event) + (when (memq (process-status proc) '(exit signal)) + (unwind-protect + (if (with-current-buffer source (eq proc flymake-clippy--proc)) + (with-current-buffer (process-buffer proc) + (goto-char (point-min)) + ;; Collect output buffer into diagnostic messages/locations, + ;; exposing them via `report-fn'. + (cl-loop + while (search-forward-regexp + (flymake-clippy--build-regexp) + nil t) + for msg = (match-string 1) + for sourcefile = (match-string 2) + for (beg . end) = (flymake-diag-region + source + (string-to-number (match-string 3))) + for type = (if (string-match "^warning" msg) + :warning + :error) + when (and sourcefile (string-match-p sourcefile filename)) + collect (flymake-make-diagnostic source beg end type msg) + into diags + finally (funcall report-fn diags))) + (flymake-log :warning "Canceling obsolete check %s" proc)) + ;; Cleanup temp buffer. + (kill-buffer (process-buffer proc))))))) + (process-send-region flymake-clippy--proc (point-min) (point-max)) + (process-send-eof flymake-clippy--proc)))) + +(defun flymake-clippy-setup-backend () + "Add `flymake-clippy' to `flymake-diagnostic-functions' hook." + (add-hook 'flymake-diagnostic-functions #'flymake-clippy-backend nil t)) + +(provide 'flymake-clippy) + +;;; flymake-clippy.el ends here -- cgit v1.2.3