Skip to content

Commit

Permalink
Add a new checker 'r' for R
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kunhtkun authored and bbatsov committed Apr 11, 2024
1 parent 1cc0415 commit 900b8e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions doc/languages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
python-pyright
python-mypy
r-lintr
r
racket
rpm-rpmlint
rst-sphinx
Expand Down Expand Up @@ -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")))
Expand Down
6 changes: 6 additions & 0 deletions test/flycheck-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 900b8e7

Please sign in to comment.