branch: elpa/flycheck
commit 900b8e79754d21853a6e5b5a2802f317a7112a1e
Author: Kunht Kun <[email protected]>
Commit: Bozhidar Batsov <[email protected]>

    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.
---
 CHANGES.rst           |  1 +
 doc/languages.rst     |  4 ++++
 flycheck.el           | 16 ++++++++++++++++
 test/flycheck-test.el |  6 ++++++
 4 files changed, 27 insertions(+)

diff --git a/CHANGES.rst b/CHANGES.rst
index 6b58c0941b..3dd89b82f2 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -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
diff --git a/doc/languages.rst b/doc/languages.rst
index cc0b0354ae..c7f92a23f8 100644
--- a/doc/languages.rst
+++ b/doc/languages.rst
@@ -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
diff --git a/flycheck.el b/flycheck.el
index 7adc0cdbcc..74e99e851d 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -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")))
diff --git a/test/flycheck-test.el b/test/flycheck-test.el
index 8d0aa5bfd4..f0fd5bf14c 100644
--- a/test/flycheck-test.el
+++ b/test/flycheck-test.el
@@ -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))

Reply via email to