From 033505ce4a7eece5a53645eb47cdbf767aa813bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Tue, 14 Jan 2014 11:29:12 +0100 Subject: [PATCH] Made `flymake-phpcs-standard' more safe. `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. --- README.mkdn | 2 +- flymake-phpcs.el | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.mkdn b/README.mkdn index 6809ec1..8e7f352 100644 --- a/README.mkdn +++ b/README.mkdn @@ -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 diff --git a/flymake-phpcs.el b/flymake-phpcs.el index f494b4f..ba1d6a5 100644 --- a/flymake-phpcs.el +++ b/flymake-phpcs.el @@ -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 ;; Maintainer: Sam Graham @@ -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