2828(require 'flycheck )
2929(require 'drupal/phpcs )
3030
31- (defcustom drupal/flycheck-phpcs-js-and-css t
32- " 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."
33- :type `(choice
34- (const :tag " Yes" t )
35- (const :tag " No" nil ))
36- :group 'drupal )
37-
3831(defun drupal/flycheck-hook ()
3932 " Enable drupal-mode support for flycheck."
40- (when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes))
41- drupal/phpcs-standard)
42- ; ; Set the coding standard to "Drupal" (we checked that it is
43- ; ; supported above.
33+ (when (and drupal-mode drupal/phpcs-standard)
34+ ; ; Set the coding standard to "Drupal" (phpcs.el has checked that
35+ ; ; it's supported).
4436 (setq flycheck-phpcs-standard drupal/phpcs-standard)
4537
4638 ; ; Flycheck will also highlight trailing whitespace as an
5042
5143(add-hook 'drupal-mode-hook #'drupal/flycheck-hook )
5244
53- (flycheck-define-checker css-js -phpcs
54- " Check CSS and JavaScript using PHP_CodeSniffer.
45+ (flycheck-define-checker drupal -phpcs
46+ " Check non-PHP Drupal files using PHP_CodeSniffer.
5547
56- PHP_CodeSniffer can be used to check non-PHP files, as exemplified by the
57- Drupal code sniffer .
48+ The Drupal standard includes checks for non-PHP files, this
49+ checker runs those .
5850
5951See URL `http://pear.php.net/package/PHP_CodeSniffer/' ."
6052 :command (" phpcs" " --report=emacs"
@@ -72,11 +64,19 @@ See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
7264 (warning line-start
7365 (file-name) " :" line " :" column " : warning - " (message )
7466 line-end))
75- :modes (css-mode js-mode)
67+ ; ; We'd prefer to just check drupal-mode, but flycheck global mode
68+ ; ; finds the checker before we get a chance to set drupal-mode.
7669 :predicate (lambda ()
77- (and drupal/flycheck-phpcs-js-and-css (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes)))))
78-
79- (add-to-list 'flycheck-checkers 'css-js-phpcs )
70+ (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes drupal-info-modes))))
71+
72+ ; ; Append our custom checker.
73+ (add-to-list 'flycheck-checkers 'drupal-phpcs t )
74+ ; ; Add our checker as next-checker to checkers of all supported modes.
75+ (let ((modes (append drupal-css-modes drupal-js-modes drupal-info-modes)))
76+ (dolist (checker (flycheck-defined-checkers))
77+ (dolist (mode (flycheck-checker-modes checker))
78+ (if (memq mode modes)
79+ (flycheck-add-next-checker checker 'drupal-phpcs )))))
8080
8181
8282(provide 'drupal/flycheck )
0 commit comments