branch: elpa/drupal-mode
commit 13b2fff6ef2e04c546c705ac1d9f282e2f4f9184
Author: Thomas Fini Hansen <[email protected]>
Commit: Thomas Fini Hansen <[email protected]>
Use flycheck-add-next-checker.
Properly chain into the checker chain for js/css modes. Also check info
files. Closes #41.
---
drupal/flycheck.el | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/drupal/flycheck.el b/drupal/flycheck.el
index 84d5da1a46..5f2d948bc5 100644
--- a/drupal/flycheck.el
+++ b/drupal/flycheck.el
@@ -28,19 +28,11 @@
(require 'flycheck)
(require 'drupal/phpcs)
-(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)
-
(defun drupal/flycheck-hook ()
"Enable drupal-mode support for flycheck."
- (when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes
drupal-js-modes))
- drupal/phpcs-standard)
- ;; Set the coding standard to "Drupal" (we checked that it is
- ;; supported above.
+ (when (and drupal-mode drupal/phpcs-standard)
+ ;; Set the coding standard to "Drupal" (phpcs.el has checked that
+ ;; it's supported).
(setq flycheck-phpcs-standard drupal/phpcs-standard)
;; Flycheck will also highlight trailing whitespace as an
@@ -50,11 +42,11 @@
(add-hook 'drupal-mode-hook #'drupal/flycheck-hook)
-(flycheck-define-checker css-js-phpcs
- "Check CSS and JavaScript using PHP_CodeSniffer.
+(flycheck-define-checker drupal-phpcs
+ "Check non-PHP Drupal files using PHP_CodeSniffer.
-PHP_CodeSniffer can be used to check non-PHP files, as exemplified by the
-Drupal code sniffer.
+The Drupal standard includes checks for non-PHP files, this
+checker runs those.
See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
:command ("phpcs" "--report=emacs"
@@ -72,11 +64,19 @@ See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
(warning line-start
(file-name) ":" line ":" column ": warning - " (message)
line-end))
- :modes (css-mode js-mode)
+ ;; We'd prefer to just check drupal-mode, but flycheck global mode
+ ;; finds the checker before we get a chance to set drupal-mode.
:predicate (lambda ()
- (and drupal/flycheck-phpcs-js-and-css (apply 'derived-mode-p
(append drupal-php-modes drupal-css-modes drupal-js-modes)))))
-
-(add-to-list 'flycheck-checkers 'css-js-phpcs)
+ (apply 'derived-mode-p (append drupal-php-modes
drupal-css-modes drupal-js-modes drupal-info-modes))))
+
+;; Append our custom checker.
+(add-to-list 'flycheck-checkers 'drupal-phpcs t)
+;; Add our checker as next-checker to checkers of all supported modes.
+(let ((modes (append drupal-css-modes drupal-js-modes drupal-info-modes)))
+ (dolist (checker (flycheck-defined-checkers))
+ (dolist (mode (flycheck-checker-modes checker))
+ (if (memq mode modes)
+ (flycheck-add-next-checker checker 'drupal-phpcs)))))
(provide 'drupal/flycheck)