Add a new checker 'r' for R

This is a rather rudimentary checker using only the builtin 'parse'
function of R. It can only report syntax/parsing errors, but it does not
depend on any third-party libraries.

R actually has some builtin utilities for linting (for example,
'codetools'), but as far as I know those require evaluating the source
code, so only 'parse' is used.
pull/2065/merge
Kunht Kun 2024-04-10 17:40:42 -04:00 committed by Bozhidar Batsov
parent 1cc041503d
commit 900b8e7975
4 changed files with 27 additions and 0 deletions

View File

@ -10,6 +10,7 @@ New Features
- [#2035]: Added colors to FlyC mode line and updated mode line menu.
- [#2059]: Enable checkers for new AUCTeX 14 modes.
- [#1987]: Add a flag ``flycheck-auto-display-errors-after-checking`` control whether to display errors automatically after checking.
- [#2070]: Add a new syntax checker ``r`` for R with the builtin ``parse`` function.
-----------
Bugs fixed

View File

@ -1136,6 +1136,10 @@ to view the docstring of the syntax checker. Likewise, you may use
Linters to use as a string with an R expression which selects the
linters to use.
.. syntax-checker:: r
Check syntax with R's builtin ``parse`` function.
.. supported-language:: Racket
.. syntax-checker:: racket

View File

@ -204,6 +204,7 @@
python-pyright
python-mypy
r-lintr
r
racket
rpm-rpmlint
rst-sphinx
@ -11017,6 +11018,21 @@ See URL `https://github.com/jimhester/lintr'."
:message (if has-lintr "present" "missing")
:face (if has-lintr 'success '(bold error)))))))
(flycheck-define-checker r
"An R syntax checker using the builtin `parse' function.
See URL: `https://www.r-project.org/'."
:command ("R" "--slave" "--no-restore" "--no-save" "-e"
"parse(file=file('stdin'), srcfile='<stdin>')")
:standard-input t
:error-patterns
((error line-start (zero-or-more space) "<stdin>:" line ":" column ": "
(message) line-end))
:modes (ess-mode ess-r-mode)
:predicate
;; Don't check ESS files which do not contain R
(lambda () (equal ess-language "S")))
(defun flycheck-racket-has-expand-p (checker)
"Whether the executable of CHECKER provides the `expand' command."
(eql 0 (flycheck-call-checker-process checker nil nil nil "expand")))

View File

@ -4365,6 +4365,12 @@ Perhaps:
'(4 6 warning "Do not use absolute paths." :checker r-lintr)
'(7 5 error "unexpected end of input" :checker r-lintr))))
(flycheck-ert-def-checker-test r r nil
(let ((flycheck-disabled-checkers '(r-lintr)))
(flycheck-ert-should-syntax-check
"language/r.R" 'R-mode
'(8 0 error "unexpected end of input" :checker r))))
(flycheck-ert-def-checker-test racket racket nil
(skip-unless (funcall (flycheck-checker-get 'racket 'predicate)))
(let ((inhibit-message t))