From 87bf4dda1cd6dc0895ac9681cd642ed10a17afe8 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 23 Jul 2022 13:01:23 +0900 Subject: [PATCH 1/7] Fix doc comments --- phpstan.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/phpstan.el b/phpstan.el index 143ab94..7b00645 100644 --- a/phpstan.el +++ b/phpstan.el @@ -58,9 +58,8 @@ ;; Variables: - (defgroup phpstan nil - "Interaface to PHPStan" + "Interaface to PHPStan." :tag "PHPStan" :prefix "phpstan-" :group 'tools @@ -229,7 +228,7 @@ NIL (php-project-get-root-dir))))) (defun phpstan-get-config-file () - "Return path to phpstan configure file or `NIL'." + "Return path to phpstan configure file or NIL." (if phpstan-config-file (if (and (consp phpstan-config-file) (eq 'root (car phpstan-config-file))) @@ -252,7 +251,7 @@ NIL phpstan-autoload-file))) (defun phpstan-normalize-path (source-original &optional source) - "Return normalized source file path to pass by `SOURCE-ORIGINAL' OR `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." @@ -272,7 +271,7 @@ it returns the value of `SOURCE' as it is." (or source source-original)))) (defun phpstan-get-level () - "Return path to phpstan configure file or `NIL'." + "Return path to phpstan configure file or NIL." (cond ((null phpstan-level) nil) ((integerp phpstan-level) (int-to-string phpstan-level)) From f32c057a7819c3c93af7e5be8758fadd28ff8e20 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 23 Jul 2022 13:16:08 +0900 Subject: [PATCH 2/7] Add phpstan.dist.neon to phpstan-get-config-file --- CHANGELOG.md | 1 + phpstan.el | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c9d053..b8d4951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,3 +7,4 @@ All notable changes of the phpactor.el are documented in this file using the [Ke ### Added * Add `phpstan-analyze-this-file` command +* Add `phpstan.dist.neon` to `phpstan-get-config-file` as PHPStan config files. diff --git a/phpstan.el b/phpstan.el index 7b00645..f241977 100644 --- a/phpstan.el +++ b/phpstan.el @@ -237,8 +237,8 @@ NIL phpstan-config-file) (let ((working-directory (phpstan-get-working-dir))) (when working-directory - (cl-loop for name in '("phpstan.neon" "phpstan.neon.dist") - for dir = (locate-dominating-file working-directory name) + (cl-loop for name in '("phpstan.neon" "phpstan.neon.dist" "phpstan.dist.neon") + for dir = (locate-dominating-file working-directory name) if dir return (expand-file-name name dir)))))) From 9bd4e4543631b1237acca113f2d84a67cf443632 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 23 Jul 2022 13:16:47 +0900 Subject: [PATCH 3/7] Add (require 'php) in eval-when-compile --- phpstan.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.el b/phpstan.el index f241977..250fac3 100644 --- a/phpstan.el +++ b/phpstan.el @@ -56,6 +56,8 @@ (require 'cl-lib) (require 'php-project) +(eval-when-compile + (require 'php)) ;; Variables: (defgroup phpstan nil From c5a926d20fbbe2cd91ebb0e852d1ec23381595d9 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 23 Jul 2022 15:04:04 +0900 Subject: [PATCH 4/7] Make flycheck analyze the original directly instead of temporary --- CHANGELOG.md | 4 ++++ flycheck-phpstan.el | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8d4951..a0cfe26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,7 @@ All notable changes of the phpactor.el are documented in this file using the [Ke * Add `phpstan-analyze-this-file` command * Add `phpstan.dist.neon` to `phpstan-get-config-file` as PHPStan config files. + +### Changed + +* Make flycheck analyze the original file directly instead of temporary files when there are no changes to the file. diff --git a/flycheck-phpstan.el b/flycheck-phpstan.el index 35af909..a4256b1 100644 --- a/flycheck-phpstan.el +++ b/flycheck-phpstan.el @@ -63,9 +63,10 @@ (flycheck-define-checker phpstan "PHP static analyzer based on PHPStan." :command ("php" (eval (phpstan-get-command-args)) - (eval (phpstan-normalize-path - (flycheck-save-buffer-to-temp #'flycheck-temp-file-inplace) - (flycheck-save-buffer-to-temp #'flycheck-temp-file-system)))) + (eval (if (or (buffer-modified-p) (not buffer-file-name)) + (phpstan-normalize-path + (flycheck-save-buffer-to-temp #'flycheck-temp-file-inplace)) + buffer-file-name))) :working-directory (lambda (_) (phpstan-get-working-dir)) :enabled (lambda () (flycheck-phpstan--enabled-and-set-variable)) :error-patterns From be3db2803cbee62d7aac84f1916c82e5201a8cf5 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 23 Jul 2022 18:29:38 +0900 Subject: [PATCH 5/7] Add autoload cookies to interactive commands --- phpstan.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.el b/phpstan.el index 250fac3..e902f5f 100644 --- a/phpstan.el +++ b/phpstan.el @@ -284,6 +284,7 @@ it returns the value of `SOURCE' as it is." "Return --memory-limit value." phpstan-memory-limit) +;;;###autoload (defun phpstan-analyze-this-file () "Analyze current buffer-file using PHPStan." (interactive) @@ -291,6 +292,7 @@ it returns the value of `SOURCE' as it is." (read-file-name "Choose a PHP script: "))))) (compile (mapconcat #'shell-quote-argument (append (phpstan-get-command-args t) (list file)) " ")))) +;;;###autoload (defun phpstan-analyze-file (file) "Analyze a PHP script FILE using PHPStan." (interactive (list (expand-file-name (read-file-name "Choose a PHP script: ")))) From 5dbe3f7a221e3f55a80841ce64ec6cf1f386e3bb Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 23 Jul 2022 23:09:31 +0900 Subject: [PATCH 6/7] Use cl-defun php-stan-get-command-args instead of defun --- phpstan.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpstan.el b/phpstan.el index e902f5f..b390a31 100644 --- a/phpstan.el +++ b/phpstan.el @@ -290,13 +290,15 @@ it returns the value of `SOURCE' as it is." (interactive) (let ((file (expand-file-name (or buffer-file-name (read-file-name "Choose a PHP script: "))))) - (compile (mapconcat #'shell-quote-argument (append (phpstan-get-command-args t) (list file)) " ")))) + (compile (mapconcat #'shell-quote-argument + (append (phpstan-get-command-args :include-executable t) (list file)) " ")))) ;;;###autoload (defun phpstan-analyze-file (file) "Analyze a PHP script FILE using PHPStan." (interactive (list (expand-file-name (read-file-name "Choose a PHP script: ")))) - (compile (mapconcat #'shell-quote-argument (append (phpstan-get-command-args t) (list file)) " "))) + (compile (mapconcat #'shell-quote-argument + (append (phpstan-get-command-args :include-executable t) (list file)) " "))) (defun phpstan-get-executable-and-args () "Return PHPStan excutable file and arguments." @@ -335,7 +337,7 @@ it returns the value of `SOURCE' as it is." ((executable-find "phpstan") (list (executable-find "phpstan"))) (t (error "PHPStan executable not found"))))))) -(defun phpstan-get-command-args (&optional include-executable) +(cl-defun phpstan-get-command-args (&key include-executable use-pro) "Return command line argument for PHPStan." (let ((executable-and-args (phpstan-get-executable-and-args)) (path (phpstan-normalize-path (phpstan-get-config-file))) From b832434f61cd83d193e7bfa5542fe7f8f9531f2f Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Sat, 23 Jul 2022 23:49:59 +0900 Subject: [PATCH 7/7] Add phpstan-pro command to launch PHPStan Pro --- CHANGELOG.md | 3 +++ phpstan.el | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0cfe26..d6ec178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ All notable changes of the phpactor.el are documented in this file using the [Ke * Add `phpstan-analyze-this-file` command * Add `phpstan.dist.neon` to `phpstan-get-config-file` as PHPStan config files. +* Add `phpstan-pro` command to launch [PHPStan Pro]. + +[PHPStan Pro]: https://phpstan.org/blog/introducing-phpstan-pro ### Changed diff --git a/phpstan.el b/phpstan.el index b390a31..3185f0c 100644 --- a/phpstan.el +++ b/phpstan.el @@ -300,6 +300,15 @@ it returns the value of `SOURCE' as it is." (compile (mapconcat #'shell-quote-argument (append (phpstan-get-command-args :include-executable t) (list file)) " "))) +;;;###autoload +(defun phpstan-pro () + "Analyze current PHP project using PHPStan Pro." + (interactive) + (let ((compilation-buffer-name-function (lambda (_) "*PHPStan Pro*")) + (command (mapconcat #'shell-quote-argument + (phpstan-get-command-args :include-executable t :use-pro t) " "))) + (compile command t))) + (defun phpstan-get-executable-and-args () "Return PHPStan excutable file and arguments." (cond @@ -347,6 +356,7 @@ it returns the value of `SOURCE' as it is." (append (if include-executable (list (car executable-and-args)) nil) (cdr executable-and-args) (list "analyze" "--error-format=raw" "--no-progress" "--no-interaction") + (and use-pro (list "--pro" "--no-ansi")) (and path (list "-c" path)) (and autoload (list "-a" autoload)) (and memory-limit (list "--memory-limit" memory-limit))