emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/drupal-mode bd83268c5d 131/308: Add custom checker for che


From: ELPA Syncer
Subject: [nongnu] elpa/drupal-mode bd83268c5d 131/308: Add custom checker for checking CSS/JS files with phpcs.
Date: Tue, 25 Jan 2022 10:59:38 -0500 (EST)

branch: elpa/drupal-mode
commit bd83268c5de11d47fffcc1e70a270ba868e00188
Author: Thomas Fini Hansen <xen@xen.dk>
Commit: Thomas Fini Hansen <xen@xen.dk>

    Add custom checker for checking CSS/JS files with phpcs.
---
 drupal/flycheck.el | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/drupal/flycheck.el b/drupal/flycheck.el
index d3075bd801..58aeab0272 100644
--- a/drupal/flycheck.el
+++ b/drupal/flycheck.el
@@ -31,7 +31,14 @@
   "Non-nil means don't highlight trailing whitespace when flycheck-phpcs is in 
use.
 Flycheck-phpcs will also highlight trailing whitespace as an error
 so no need to highlight it twice."
-  :type `(choice 
+  :type `(choice
+          (const :tag "Yes" t)
+          (const :tag "No" nil))
+  :group 'drupal)
+
+(defcustom drupal/flycheck-phpcs-js-and-css t
+  "When Non-nil, override Flycheck to use PHPCS for checking CSS and 
JavaScript files instead of the checkers configured for css-mode and js-mode."
+  :type `(choice
           (const :tag "Yes" t)
           (const :tag "No" nil))
   :group 'drupal)
@@ -45,6 +52,12 @@ so no need to highlight it twice."
     ;; supported above.
     (set (make-local-variable 'flycheck-phpcs-standard) drupal/phpcs-standard)
 
+    (when drupal/flycheck-phpcs-js-and-css
+      (if (apply 'derived-mode-p (append drupal-css-modes drupal-js-modes))
+          (set (make-local-variable 'flycheck-checker) 'css-js-phpcs)
+        )
+      )
+
     ;; Flycheck will also highlight trailing whitespace as an
     ;; error so no need to highlight it twice.
     (when drupal/flycheck-phpcs-dont-show-trailing-whitespace
@@ -54,6 +67,28 @@ so no need to highlight it twice."
 
 (add-hook 'drupal-mode-hook #'drupal/flycheck-hook)
 
+(flycheck-declare-checker css-js-phpcs
+  "Check CSS and JavaScript  using PHP_CodeSniffer.
+
+PHP_CodeSniffer can be used to check non-PHP files, as exemplified by the
+Drupal code sniffer.
+
+See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
+  :command '("phpcs" "--report=emacs"
+             (option "--standard=" flycheck-phpcs-standard)
+             source)
+  ;; Though phpcs supports Checkstyle output which we could feed to
+  ;; `flycheck-parse-checkstyle', we are still using error patterns here,
+  ;; because PHP has notoriously unstable output habits.  See URL
+  ;; `https://github.com/lunaryorn/flycheck/issues/78' and URL
+  ;; `https://github.com/lunaryorn/flycheck/issues/118'
+  :error-patterns
+  '(("\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): error - \\(?4:.*\\)" error)
+    ("\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): warning - \\(?4:.*\\)" 
warning))
+  :modes '(css-mode js-mode)
+  :predicate #'(lambda ()
+                 (apply 'derived-mode-p (append drupal-php-modes 
drupal-css-modes drupal-js-modes))))
+
 
 
 (provide 'drupal/flycheck)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]