[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/flycheck 1b74bc560a 1/2: Implement perl-perlimports checke
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/flycheck 1b74bc560a 1/2: Implement perl-perlimports checker (#2071) |
Date: |
Sat, 29 Jun 2024 00:59:34 -0400 (EDT) |
branch: elpa/flycheck
commit 1b74bc560a1840ce0a93078846b644a5926c0edc
Author: Peter Oliver <git@mavit.org.uk>
Commit: GitHub <noreply@github.com>
Implement perl-perlimports checker (#2071)
---
CHANGES.rst | 1 +
doc/languages.rst | 8 +++++++-
flycheck.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index ecc2a64942..52aea50fe4 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -12,6 +12,7 @@ New Features
- [#2059]: Enable checkers for new AUCTeX 14 modes.
- [#2067]: Handle correctly GHC 9.6 error output format.
- [#2070]: Add a new syntax checker ``r`` for R with the builtin ``parse``
function.
+- [#2071]: Add a new checker ``perl-perlimports``, for cleaning up Perl import
statements.
-----------
Bugs fixed
diff --git a/doc/languages.rst b/doc/languages.rst
index c7f92a23f8..56704da5e7 100644
--- a/doc/languages.rst
+++ b/doc/languages.rst
@@ -885,7 +885,7 @@ to view the docstring of the syntax checker. Likewise, you
may use
.. supported-language:: Perl
- Flycheck checks Perl with `perl` and `perl-perlcritic`.
+ Flycheck checks Perl with `perl`, `perl-perlcritic`, and `perl-perlimports`.
.. syntax-checker:: perl
@@ -915,6 +915,12 @@ to view the docstring of the syntax checker. Likewise,
you may use
.. syntax-checker-config-file:: flycheck-perlcriticrc
+ .. syntax-checker:: perl-perlimports
+
+ Clean up Perl import statements with `perlimports`_.
+
+ .. _perlimports:
https://metacpan.org/dist/App-perlimports/view/script/perlimports
+
.. supported-language:: PHP
Flycheck checks PHP with `php`, `php-phpmd`, `php-phpcs` and
`php-phpcs-changed`.
diff --git a/flycheck.el b/flycheck.el
index 74e99e851d..93004a7e81 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -186,6 +186,7 @@
opam
perl
perl-perlcritic
+ perl-perlimports
php
php-phpmd
php-phpcs
@@ -10240,6 +10241,7 @@ See URL `https://metacpan.org/pod/Perl::Critic'."
(id (one-or-more (not (any "/")))) "/" (message)
line-end))
:modes (cperl-mode perl-mode)
+ :next-checkers (perl-perlimports)
:error-explainer
(lambda (err)
@@ -10247,6 +10249,48 @@ See URL `https://metacpan.org/pod/Perl::Critic'."
(url "https://metacpan.org/pod/Perl::Critic::Policy::%s"))
(and error-code `(url . ,(format url error-code))))))
+(defun flycheck-perl-perlimports-parse-errors (output checker buffer)
+ "Parse perlimports json output errors from OUTPUT.
+
+CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
+the BUFFER that was checked respectively.
+
+See URL `https://metacpan.org/dist/App-perlimports/view/script/perlimports'
+for more information about perlimports."
+ (mapcar (lambda (err)
+ (let-alist err
+ (flycheck-error-new-at
+ .location.start.line
+ .location.start.column
+ 'info
+ (concat .module " " .reason ":"
+ (with-temp-buffer
+ (insert (substring .diff (string-match-p "\n" .diff)))
+ (diff-mode)
+ (font-lock-ensure)
+ (buffer-string)))
+ :end-line .location.end.line
+ :end-column .location.end.column
+ :checker checker
+ :buffer buffer)))
+ (flycheck-parse-json output)))
+
+(flycheck-define-checker perl-perlimports
+ "A checker for cleaning up Perl import statements.
+
+See URL `https://metacpan.org/dist/App-perlimports/view/script/perlimports'."
+ :command ("perlimports"
+ "--filename" source
+ "--json"
+ "--lint"
+ "--no-preserve-duplicates"
+ "--no-preserve-unused"
+ "--no-tidy-whitespace"
+ "--read-stdin")
+ :standard-input t
+ :error-parser flycheck-perl-perlimports-parse-errors
+ :modes (cperl-mode perl-mode))
+
(flycheck-define-checker php
"A PHP syntax checker using the PHP command line interpreter.