Skip to content

Commit

Permalink
Made `flymake-phpcs-standard' more safe.
Browse files Browse the repository at this point in the history
`flymake-phpcs-standard' is only safe as a local variable if the
specified standard is not pointing to a file/path to a standard.

So the safe-local-variable property is adjusted to only be safe when
the value is string-or-null-p AND it is not file-exists-p.

This might fail in the case where you specify i.e. PEAR as standard and
also have a file or folder named PEAR relative to the buffer. PHPCS will
choose the installed standard but `flymake-phpcs-standard' will consider
the setting unsafe. At least it only fails to the safe side - it won't
allow unsafe values but can mark a few safe values as unsafe.

Another approach would be to only accept all installed standards
(phpcs -i) as safe values but we'll spare the overhead of running
external commands.
  • Loading branch information
arnested committed Jan 14, 2014
1 parent 0c01867 commit 033505c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ something like the following to your .emacs:
(setq flymake-phpcs-command "~/projects/emacs-flymake-phpcs/bin/flymake_phpcs")
;; Customize the coding standard checked by phpcs
(setq flymake-phpcs-standard
(set-default 'flymake-phpcs-standard
"~/projects/devtools/php_codesniffer/MyCompanyStandard")
;; Show the name of sniffs in warnings (eg show
Expand Down
5 changes: 4 additions & 1 deletion flymake-phpcs.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; flymake-phpcs.el --- Flymake handler for PHP to invoke PHP-CodeSniffer
;;
;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
;; Copyright (C) 2011-2012, 2014 Free Software Foundation, Inc.
;;
;; Author: Sam Graham <libflymake-phpcs-emacs BLAHBLAH illusori.co.uk>
;; Maintainer: Sam Graham <libflymake-phpcs-emacs BLAHBLAH illusori.co.uk>
Expand Down Expand Up @@ -42,6 +42,9 @@
(defcustom flymake-phpcs-standard "PEAR"
"The coding standard to pass to phpcs via --standard."
:group 'flymake-phpcs
:safe (lambda (value)
(and (string-or-null-p value)
(not (file-exists-p value))))
:type 'string)

(defcustom flymake-phpcs-show-rule nil
Expand Down

0 comments on commit 033505c

Please sign in to comment.