Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions drupal/flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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)
Expand Down