|
67 | 67 | (and (stringp v) |
68 | 68 | (string-match-p "\\`[0-9]\\'" v)))))) |
69 | 69 |
|
| 70 | +;;;###autoload |
| 71 | +(progn |
| 72 | + (defvar phpstan-replace-path-prefix) |
| 73 | + (make-variable-buffer-local 'phpstan-replace-path-prefix) |
| 74 | + (put 'phpstan-replace-path-prefix 'safe-local-variable |
| 75 | + #'(lambda (v) (or (null v) (stringp v))))) |
| 76 | + |
70 | 77 | ;; Usually it is defined dynamically by flycheck |
71 | 78 | (defvar flycheck-phpstan-executable) |
72 | 79 |
|
|
117 | 124 | (set (make-local-variable 'flycheck-phpstan-executable) |
118 | 125 | (car phpstan-executable))))) |
119 | 126 |
|
| 127 | +(defun phpstan-normalize-path (source-original source) |
| 128 | + "Return normalized source file path to pass by `SOURCE-ORIGINAL' OR `SOURCE'. |
| 129 | +
|
| 130 | +If neither `phpstan-replace-path-prefix' nor executable docker is set, |
| 131 | +it returns the value of `SOURCE' as it is." |
| 132 | + (let ((working-directory (expand-file-name (php-project-get-root-dir))) |
| 133 | + (prefix |
| 134 | + (cond |
| 135 | + ((not (null phpstan-replace-path-prefix)) phpstan-replace-path-prefix) |
| 136 | + ((and (consp phpstan-executable) |
| 137 | + (string= "docker" (car phpstan-executable))) "/app")))) |
| 138 | + (if prefix |
| 139 | + (expand-file-name |
| 140 | + (replace-regexp-in-string (concat "\\`" (regexp-quote working-directory)) |
| 141 | + "" |
| 142 | + source-original t t) |
| 143 | + prefix) |
| 144 | + source))) |
| 145 | + |
120 | 146 | (defun phpstan-get-level () |
121 | 147 | "Return path to phpstan configure file or `NIL'." |
122 | 148 | (cond |
|
151 | 177 | "analyze" "--errorFormat=raw" "--no-progress" "--no-interaction" |
152 | 178 | "-c" (eval (phpstan-get-config-file)) |
153 | 179 | "-l" (eval (phpstan-get-level)) |
154 | | - source) |
| 180 | + (eval (phpstan-normalize-path |
| 181 | + (flycheck-save-buffer-to-temp #'flycheck-temp-file-inplace) |
| 182 | + (flycheck-save-buffer-to-temp #'flycheck-temp-file-system)))) |
155 | 183 | :working-directory (lambda (_) (php-project-get-root-dir)) |
156 | 184 | :enabled (lambda () (phpstan-get-config-file-and-set-flycheck-variable)) |
157 | 185 | :error-patterns |
|
0 commit comments