Emacs interface to Psalm, includes checker for Flycheck.
- Emacs 24+
- Psalm latest/dev-master (NOT support 0.9 seriese)
- PHP 7.1+ or Docker runtime
- If you have not set up MELPA, see Getting Started - MELPA.
M-x package-install flycheck-psalm
(defun my-php-mode-setup ()
"My PHP-mode hook."
(require 'flycheck-psalm)
(flycheck-mode t))
(add-hook 'php-mode-hook 'my-php-mode-setup)
(add-hook 'php-mode-hook #'flymake-psalm-turn-on)
Install Docker. There is currently no official Docker image we can trust, so if you want to use it, you are at your own risk.
If you always use Docker for Psalm, add the following into your .emacs
file (~~/.emacs.d/init.el~)
;; Be sure to replace it with a Docker image you trust
(setq-default psalm-docker-image "your/dockerhub-image")
(setq-default psalm-executable 'docker)
Put the following into .dir-locals.el
files on the root directory of project.
((nil . ((php-project-root . git)
(psalm-executable . docker)
(psalm-working-dir . (root . "path/to/dir"))
(psalm-config-file . (root . "path/to/dir/psalm-docker.neon"))
(psalm-level . 7))))
If your project Composer relies on psalm, you do not need to set anything.
((nil . ((php-project-root . git)
(psalm-executable . docker)
(psalm-working-dir . (root . "path/to/dir"))
(psalm-config-file . (root . "path/to/dir/psalm-docker.neon"))
(psalm-level . 7))))
Please install vimeo/psalm package for each user environment or project by using Composer.
If you are unfamiliar with resolving dependencies, the following shell commands are recommended.
$ composer global require vimeo/psalm
NOTICE: We strongly recommend using the latest Psalm.
Please download psalm.phar
from Releases · vimeo/psalm.
Variables for psalm are mainly controlled by directory variables (.dir-locals.el
).
Frequently (root. "path/to/file")
notation appears in these variables. It is relative to the top level directory of the project. In general, the directory containing one of .projectile
, composer.json
, .git
file (or directory) is at the top level.
Please be aware that the root directory of the PHP project may NOT match either of Psalm’s %rootDir%
and/or %currentWorkingDirectory%
.
Typically, you would set the following .dir-locals.el
.
((nil . ((php-project-root . auto)
(psalm-executable . docker)
(psalm-working-dir . (root . "path/to/dir/"))
(psalm-config-file . (root . "path/to/dir/psalm-custom.neon"))
(psalm-level . max))))
If there is a psalm.neon
file in the root directory of the project, you do not need to set both psalm-working-dir
and psalm-config-file
.
Most variables defined in this package are buffer local. If you want to set it for multiple projects, use setq-default.
Path to working directory of Psalm.
- STRING
- Absolute path to `psalm’ working directory.
- ex)
"/path/to/psalm.phar"
- ex)
(root . STRING)
- Relative path to `psalm’ working directory from project root directory.
- ex)
(root . "path/to/dir")
- ex)
nil
- Use
(php-project-get-root-dir)
as working directory.
Path to project specific configuration file of Psalm.
- STRING
- Absolute path to
psalm
configuration file. (root . STRING)
- Relative path to
psalm
configuration file from project root directory. - NIL
- Search
psalm.neon(.dist)
in(psalm-get-working-dir)
.
- STRING
- Absolute path to `psalm’ executable file.
- ex)
"/path/to/psalm.phar"
- ex)
- SYMBOL
docker
- Use Docker using psalm/docker-image.
(root . STRING)
- Relative path to `psalm’ executable file from project root directory.
- ex)
(root . "script/psalm")
- ex)
(STRING . (ARGUMENTS ...))
- Command name and arguments.
- ex)
("docker" "run" "--rm" "-v" "/path/to/project-dir/:/app" "your/docker-image")
- ex)
nil
- Auto detect
psalm
executable file by composer dependencies of the project or executable command inPATH
environment variable.
Set flycheck psalm-executable automatically when non-NIL.
If non-NIL, add --show-info=true
option to command line argument. This variable can be overridden locally.