Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New checker, perl-perlimports #2071

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion doc/languages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`.
Expand Down
44 changes: 44 additions & 0 deletions flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
opam
perl
perl-perlcritic
perl-perlimports
php
php-phpmd
php-phpcs
Expand Down Expand Up @@ -10240,13 +10241,56 @@ 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)
(let ((error-code (flycheck-error-id err))
(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.

Expand Down
Loading