emacs-php / phpstan.el Goto Github PK
View Code? Open in Web Editor NEWInterface to PHPStan (PHP static analyzer)
License: GNU General Public License v3.0
Interface to PHPStan (PHP static analyzer)
License: GNU General Public License v3.0
Hi, thanks for this great package!
I'm a bit confused about the usage of the phpstan-working-dir
variable.
I'm trying to setup phpstan.el so that I don't have to have a phpstan.neon
file in a project.
I got this working by setting (setq phpstan-working-dir ".")
so that the enabled check passes, however this seems very hacky.
Could you explain to me the use of phpstan-working-dir
? The documentation mentions it should be different than the project root but doesn't give an explicit example.
In addition, I think I've found a bug while trying to figure out the use case of phpstan-working-dir
. I tried the same "hack" (not having a phpstan.neon
file and setting (setq phpstan-working-dir ".")
) when using Docker.
In this case phpstan-get-config-file
returns NIL
which is passed to phpstan-normalize-path
however since prefix
is set to /app
the function throws an error
Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
replace-regexp-in-string("\\`/home/mark/Projects/testing-phpstan/" "" nil t t)
This is easily fixed by changing the function:
(defun phpstan-normalize-path (source-original &optional source)
"Return normalized source file path to pass by `SOURCE-ORIGINAL' OR `SOURCE'.
If neither `phpstan-replace-path-prefix' nor executable docker is set,
it returns the value of `SOURCE' as it is."
(let ((root-directory (expand-file-name (php-project-get-root-dir)))
(prefix
(or phpstan-replace-path-prefix
(cond
((eq 'docker phpstan-executable) "/app")
((and (consp phpstan-executable)
(string= "docker" (car phpstan-executable))) "/app")))))
- (if prefix
+ (if (and prefix source-original)
(expand-file-name
(replace-regexp-in-string (concat "\\`" (regexp-quote root-directory))
""
source-original t t)
prefix)
(or source source-original))))
I'm happy to send a PR to fix the above issue however, it seems quite hacky.
phpstan-get-config-file
will try to call expand-file-name
with a nil
directory if a project directory is not found.
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
expand-file-name(nil)
locate-dominating-file(nil "phpstan.neon")
phpstan-get-config-file()
flycheck-phpstan--enabled-and-set-variable()
#[0 "\300 \207" [flycheck-phpstan--enabled-and-set-variable] 1]()
#[0 "\302\300!\205��\303\300!\205��\301?\206��\301 \207" [phpstan #[0 "\300 \207" [flycheck-phpstan--enabled-and-set-variable] 1] flycheck-find-checker-executable flycheck-temp-files-writable-p] 2]()
#[0 "\303\300!\203��\301?\206��\304\300!�\301 )\207\305\306\307\310\300$\210\311\207" [phpstan #[0 "\302\300!\205��\303\300!\205��\301?\206��\301 \207" [phpstan #[0 "\300 \207" [flycheck-phpstan--enabled-and-set-variable] 1] flycheck-find-checker-executable flycheck-temp-files-writable-p] 2] default-directory flycheck-valid-checker-p flycheck-compute-working-directory lwarn flycheck :warning "%S is no valid Flycheck syntax checker.\nTry to reinstall the package defining this syntax checker." nil] 5]()
flycheck-may-enable-checker(phpstan)
flycheck-may-use-checker(phpstan)
flycheck-may-use-next-checker(phpstan)
#[257 "\300�!\205\n�\301\302�\"\207" [flycheck-may-use-next-checker throw seq--break] 4 "\n\n(fn ELT)"](phpstan)
mapc(#[257 "\300�!\205\n�\301\302�\"\207" [flycheck-may-use-next-checker throw seq--break] 4 "\n\n(fn ELT)"] (phpstan phpstan (warning . php-phpmd) (warning . php-phpcs)))
seq-do(#[257 "\300�!\205\n�\301\302�\"\207" [flycheck-may-use-next-checker throw seq--break] 4 "\n\n(fn ELT)"] (phpstan phpstan (warning . php-phpmd) (warning . php-phpcs)))
seq-find(flycheck-may-use-next-checker (phpstan phpstan (warning . php-phpmd) (warning . php-phpcs)))
flycheck-get-next-checker-for-buffer(php)
flycheck-finish-current-syntax-check(nil "~/")
flycheck-report-buffer-checker-status([cl-struct-flycheck-syntax-check #<buffer test.php> php #<process flycheck-php> "~/"] finished nil)
apply(flycheck-report-buffer-checker-status [cl-struct-flycheck-syntax-check #<buffer test.php> php #<process flycheck-php> "~/"] (finished nil))
#[128 "\301\302\300�#\207" [[cl-struct-flycheck-syntax-check #<buffer test.php> php #<process flycheck-php> "~/"] apply flycheck-report-buffer-checker-status] 5 "\n\n(fn &rest ARGS)"](finished nil)
flycheck-finish-checker-process(php 0 ("/tmp/flycheck27758vYe/test.php" "/tmp/flycheck27758vYe") "No syntax errors detected in /tmp/flycheck27758vYe/test.php\n" #[128 "\301\302\300�#\207" [[cl-struct-flycheck-syntax-check #<buffer test.php> php #<process flycheck-php> "~/"] apply flycheck-report-buffer-checker-status] 5 "\n\n(fn &rest ARGS)"] "~/")
flycheck-handle-signal(#<process flycheck-php> "finished\n")
My .dir-locals.el
file looks like this:
((php-mode
(flycheck-checker . phpstan)
(php-project-root . git)
(phpstan-executable . (root . "untracked/vendor/bin/phpstan"))
))
When I open one of my PHP files, I get presented with this error from flycheck:
Error while checking syntax automatically: (error "Invalid result from evaluation of (phpstan-get-command-args): (47 104 111 109 101 47 107 101 110 110 101 116 104 47 101 120 97 109 112 108 101 47 117 110 116 114 97 99 107 101 100 47 118 101 110 100 111 114 47 98 105 110 47 112 104 112 115 116 97 110 \"analyze\" \"--errorFormat=raw\" \"--no-progress\" \"--no-interaction\" \"-c\" \"/home/kenneth/example/phpstan.neon.dist\" \"-l\" \"0\")")
If I change the .dir-locals.el
to use the equivalent absolute path, it works fine:
((php-mode
(flycheck-checker . phpstan)
(php-project-root . git)
(phpstan-executable . "/home/kenneth/example/untracked/vendor/bin/phpstan")
))
I would expect these two cases to have equivalent behaviour.
Hi,
Thank you for your work on this package.
I'm been using spacemacs (develop branch) and phpstan separately for some time, but after having discovered this package, I wanted to give it a try.
I tried with phpstan installed globally and falled back to docker, but had the same error on both attempts
Suspicious state from syntax checker phpstan: Flycheck checker phpstan returned non-zero exit code 1, but its output contained no errors: Could not open input file: analyze
Can that error message tell what is wrong with my setup ?
I'm using this in .dir-locals.el
((nil . ((php-project-root . git)
(phpstan-executable . docker)
(phpstan-working-dir . (root . "."))
(phpstan-config-file . (root . "./phpstan.neon"))
(phpstan-level . 7))))
Then, I've begun a private php layer where I initialize some things and which could contain the source of this error, but it is more a spacemacs thing so I'lle leave it out for now.
The melpa recipe (https://github.com/melpa/melpa/blob/master/recipes/phpstan) is missing the flycheck-phpstan.el
file, which means that it isn't copied when using the straight package manager. This mean that requiring the file causes an error.
And shouldn't the old package be deleted? (https://github.com/melpa/melpa/blob/master/recipes/flycheck-phpstan)
I'm not sure if this is an issue with flycheck or the phpstan-flycheck
the other php flychecks don't run.
(flycheck-add-next-checker 'php 'phpstan)
That pretends it to the list of next checkers for php.
but even if I change it to append it still doesn't work. It will run all the other checkers but not get to phpspec.
If I modify flycheck.el
and manually add phpstan to next-checkers
of php
and php-cs
.
Then it works. It seems like flycheck doesn't honor the next-checkers list and they know it.
Just installed the latest phpstan-el (10-3-2020 Latest commit a1c30ca) and flycheck-phpstan.
Now (phpstan-get-executable) says : ("/home/rgr/.config/composer/vendor/bin/phpstan") since I installed using "composer g require phpstan/phpstan". But its listed as disabled with a different executable. I enabled (C-u C-c ! x). I added it to to flycheck-checkers. But I cant get it enabled.
Am I missing something obvious?
I'm creating this issue just to be notified if/when flymake support gets implemented
(defun my/php-mode-hook ()
"Gets run on php-mode load."
(make-local-variable 'company-backends)
(add-to-list 'company-backends 'company-phpactor)
(flycheck-select-checker 'phpstan)
(setq php-mode-coding-style 'psr2
c-basic-offset 4)
(when (eq 0 (buffer-size))
(insert "<?php\n\n")))
(use-package php-mode :ensure t
:init (add-hook 'php-mode-hook #'my/php-mode-hook))
(use-package flycheck-phpstan :ensure t :after (php-mode flycheck))
Syntax checker in buffer MyFile.php in php-mode:
phpstan (disabled)
- major mode: `php-mode' supported
- may enable: Automatically disabled!
- executable: Found at /usr/local/bin/php
Flycheck cannot use this syntax checker for this buffer.
Flycheck Mode is enabled. Use C-u C-c ! x to enable disabled
checkers.
--------------------
Flycheck version: 32snapshot (package: 20180422.2106)
Emacs version: 26.1
System: x86_64-apple-darwin17.5.0
Window system: ns
PHPStan Project Version - installed using project's composer.
PHPStan - PHP Static Analysis Tool dev-master@de7fd7d
Currently the logic looks for the phpstan.neon
file to enable the checker.
I store this file inside app/
or tests/
directories with a bit different configurations for each scenario and thus the check would never trigger. I'm not sure if it's worth to have this check as phpstan also works without config and people often don't have any, especially on smaller projects.
What I do now is I pass the config via the -c
option dynamically (I set this as buffer-local-variable in my php init hook). I have a pull request in the making that will add this option to flycheck as well.
WDYT?
https://phpstan.org/user-guide/command-line-usage#--memory-limit
--memory-limit
Specifies the memory limit in the same format
php.ini
accepts.Example:
--memory-limit 1G
Seems that if flycheck-phpstan finds a config file, but can't find a phpstan executable, it manages to error in a way that makes flycheck toss its cookies and never show any new errors for the buffer.
I install phpstan in vendor/bin
and don't have any global install, which works fine. But in a project where there's a phpstan.neon
, but phpstan haven't been installed, flycheck dies after the first check, and then seems to be in a permanent running state (at least according to doom-modeline).
Disabling the phpstan checker makes thing work when opening new buffers.
Running flycheck-compile
and selecting the phpstan checker gives a "PHPStan executable not found" error, which I've traced to phpstan-get-executable
.
I'm a bit surprised that flycheck apparently keels over because of the error thrown, I would have thought it would ignore the checker and carry on, but apparently not. On the other hand, it does force checker writers to handle errors and not rely on flycheck picking up the pieces.
I would think a possible solution would be having flycheck-phpstan--enabled-and-set-variable
check if the executable could be found and return nil in case of error.
phpstan.el/flycheck-phpstan.el
Line 58 in 6651577
"stirngp" is a typo for "stringp".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.