Skip to content

Commit 0b9e5d2

Browse files
committed
Added basic support for flycheck.
1 parent 866c3f4 commit 0b9e5d2

File tree

4 files changed

+119
-20
lines changed

4 files changed

+119
-20
lines changed

drupal-mode.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ mode-hook."
682682
(eval-after-load 'gtags '(require 'drupal/gtags))
683683
(eval-after-load 'ispell '(require 'drupal/ispell))
684684
(eval-after-load 'flymake-phpcs '(require 'drupal/flymake-phpcs))
685+
(eval-after-load 'flycheck '(require 'drupal/flycheck))
685686
;;;###autoload
686687
(eval-after-load 'pcomplete '(require 'drupal/pcomplete))
687688
;;;###autoload

drupal/flycheck.el

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
;;; drupal/flymake-phpcs.el --- Drupal-mode support for flymake-phpcs
2+
3+
;; Copyright (C) 2012, 2013 Arne Jørgensen
4+
5+
;; Author: Thomas Fini Hansen <[email protected]>
6+
7+
;; This file is part of Drupal mode.
8+
9+
;; Drupal mode is free software: you can redistribute it and/or modify
10+
;; it under the terms of the GNU General Public License as published
11+
;; by the Free Software Foundation, either version 3 of the License,
12+
;; or (at your option) any later version.
13+
14+
;; Drupal mode is distributed in the hope that it will be useful, but
15+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
16+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
;; General Public License for more details.
18+
19+
;; You should have received a copy of the GNU General Public License
20+
;; along with Drupal mode. If not, see <http://www.gnu.org/licenses/>.
21+
22+
;;; Commentary:
23+
24+
;; Enable drupal-mode support for flymake-phpcs.
25+
26+
;;; Code:
27+
28+
(require 'drupal/phpcs)
29+
30+
(defcustom drupal/flycheck-phpcs-dont-show-trailing-whitespace t
31+
"Non-nil means don't highlight trailing whitespace when flycheck-phpcs is in use.
32+
Flycheck-phpcs will also highlight trailing whitespace as an error
33+
so no need to highlight it twice."
34+
:type `(choice
35+
(const :tag "Yes" t)
36+
(const :tag "No" nil))
37+
:group 'drupal)
38+
39+
(defun drupal/flycheck-hook ()
40+
"Enable drupal-mode support for flycheck."
41+
(when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes))
42+
(executable-find "phpcs")
43+
drupal/phpcs-standard)
44+
;; Set the coding standard to "Drupal" (we checked that it is
45+
;; supported above.
46+
(set (make-local-variable 'flycheck-phpcs-standard) drupal/phpcs-standard)
47+
48+
;; Flycheck will also highlight trailing whitespace as an
49+
;; error so no need to highlight it twice.
50+
(when drupal/flycheck-phpcs-dont-show-trailing-whitespace
51+
(setq show-trailing-whitespace nil))
52+
)
53+
)
54+
55+
(add-hook 'drupal-mode-hook #'drupal/flycheck-hook)
56+
57+
58+
59+
(provide 'drupal/flycheck)
60+
61+
;;; drupal/flycheck.el ends here

drupal/flymake-phpcs.el

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,7 @@
2727

2828
(require 'flymake)
2929
(require 'flymake-phpcs)
30-
31-
(defcustom drupal/flymake-phpcs-standard
32-
(ignore-errors
33-
(let ((standards (with-output-to-string
34-
(with-current-buffer standard-output
35-
(call-process (executable-find flymake-phpcs-command) nil (list t nil) nil "-i")))))
36-
(when (string-match
37-
"\\(Drupal[^,
38-
]*\\)"
39-
standards)
40-
(match-string-no-properties 1 standards))))
41-
"Name of Drupal coding standard rules for PHP CodeSniffer.
42-
This can either be the name of an installed standard (to see
43-
installed standards run `phpcs -i') or it can be the file name of
44-
a standard. Adding file name requires PHP CodeSniffer version
45-
1.3.4 or newer."
46-
:link '(url-link :tag "Drupal Code Sniffer" "http://drupal.org/project/drupalcs")
47-
:group 'drupal)
30+
(require 'drupal/phpcs)
4831

4932
(defcustom drupal/flymake-phpcs-dont-show-trailing-whitespace t
5033
"Non-nil means don't highlight trailing whitespace when flymake-phpcs is in use.
@@ -59,10 +42,10 @@ so no need to highlight it twice."
5942
"Enable drupal-mode support for flymake-phpcs."
6043
(when (and (apply 'derived-mode-p (append drupal-php-modes drupal-css-modes drupal-js-modes))
6144
(executable-find flymake-phpcs-command)
62-
drupal/flymake-phpcs-standard)
45+
drupal/phpcs-standard)
6346
;; Set the coding standard to "Drupal" (we checked that it is
6447
;; supported above.
65-
(set (make-local-variable 'flymake-phpcs-standard) drupal/flymake-phpcs-standard)
48+
(set (make-local-variable 'flymake-phpcs-standard) drupal/phpcs-standard)
6649

6750
;; Flymake-phpcs will also highlight trailing whitespace as an
6851
;; error so no need to highlight it twice.

drupal/phpcs.el

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
;;; drupal/flymake-phpcs.el --- Drupal-mode support for flymake-phpcs
2+
3+
;; Copyright (C) 2012, 2013 Arne Jørgensen
4+
5+
;; Author: Arne Jørgensen <[email protected]>
6+
7+
;; This file is part of Drupal mode.
8+
9+
;; Drupal mode is free software: you can redistribute it and/or modify
10+
;; it under the terms of the GNU General Public License as published
11+
;; by the Free Software Foundation, either version 3 of the License,
12+
;; or (at your option) any later version.
13+
14+
;; Drupal mode is distributed in the hope that it will be useful, but
15+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
16+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
;; General Public License for more details.
18+
19+
;; You should have received a copy of the GNU General Public License
20+
;; along with Drupal mode. If not, see <http://www.gnu.org/licenses/>.
21+
22+
;;; Commentary:
23+
24+
;; Enable drupal-mode support for flymake-phpcs.
25+
26+
;;; Code:
27+
28+
(defcustom drupal/phpcs-standard
29+
; (ignore-errors
30+
(let ((standards (with-output-to-string
31+
(with-current-buffer standard-output
32+
;; Flymake uses flymake-phpcs-command, while
33+
;; flycheck just uses the phpcs
34+
;; command. Check for both.
35+
(call-process (or (and (boundp 'flymake-phpcs-command) (executable-find flymake-phpcs-command)) (executable-find "phpcs")) nil (list t nil) nil "-i")))))
36+
(when (string-match
37+
"\\(Drupal[^,
38+
]*\\)"
39+
standards)
40+
(match-string-no-properties 1 standards)))
41+
;)
42+
"Name of Drupal coding standard rules for PHP CodeSniffer.
43+
This can either be the name of an installed standard (to see
44+
installed standards run `phpcs -i') or it can be the file name of
45+
a standard. Adding file name requires PHP CodeSniffer version
46+
1.3.4 or newer."
47+
:link '(url-link :tag "Drupal Code Sniffer" "http://drupal.org/project/drupalcs")
48+
:group 'drupal)
49+
50+
51+
52+
(provide 'drupal/phpcs)
53+
54+
;;; drupal/phpcs.el ends here

0 commit comments

Comments
 (0)