girvain · 2022-06-04 08:58
It really seems like this is what’s happening as it runs fine from my project root but I loose functionality as I move further into the project. Any ideas?
nnoobb · 2022-06-04 13:02
The following functions might help to understand what flycheck does for the current buffer.
You can find enabled checkers:
```
M-x flycheck-verify-setup [ENTER]
```
You can get the command line executed by flycheck:
```
M-x flycheck-compile [ENTER]
Run syntax checker as compile command: <TYPE CHECKER NAME HERE> [ENTER]
```
You can find the function which computes the working directory:
```
M-:
Eval: (flycheck-checker-get '<TYPE CHECKER NAME HERE> 'working-directory) [ENTER]
```
girvain · 2022-06-04 13:52
Thanks for the help so far, I tried that Eval and i got nil which is weird. I've narrowed the issue down a bit now though and it's mostly phpcs's fault as even with absolute dir's as input, because the code standard files have relative likes to each other they only work still when the phpcs command is run from the project root. Heres my flycheck function currently:
(flycheck-define-checker phpcs
"stuff --standard=sniffs.xml"
:command ("phpcs" "--standard=/myproject../../sniffs.xml" source)
:error-patterns ((error line-start (file-name) ":" line ": error: " (message) line-end))
:modes php-mode
:next-checkers (php))
And the error message:
Fatal error: Uncaught PHP\_CodeSniffer\_Exception: Referenced sniff "vendor/../../ruleset.xml" does not exist in /me/myproject/vendor/squizlabs/php\_codesniffer/CodeSniffer.php:1167
S
​
I've had to change the path names but the rest is copy pasted. It's the same error in the terminal when i change directory which is why I came to the conclusion that flycheck running it's commands from the dir of the current buffer as it works when i'm at the project root where the codestandard file is and all it's relative paths links will work.
​
I hate php!
nnoobb · 2022-06-05 05:39
I don't know about php, but your guess might be right.
When working-directory is nil, the current directory of the checker is the directory of the current buffer.
For example, I assume that the project has a project configuration (a.xml) and a standard file (b.xml), the checker's definition would be roughly like this:
```
;; step1 define a function to get the project root dir somehow
;; I don't know php project standard, so I assume there must be
;; a.xml under the php project root dir...
(defun flycheck-php-project-root (&optional _checker)
"Return the nearest directory holding the a.xml configuration."
(and buffer-file-name
(locate-dominating-file buffer-file-name "a.xml")))
(flycheck-define-checker phpcs
"stuff --standard=sniffs.xml"
:command ("phpcs"
;; step 2 create an option string that passes the absolute path
(eval
(-when-let* ((root-dir (or (flycheck-php-project-root buffer-file-name) (file-name-directory (buffer-file-name)))))
(let ((standard-file (concat root-dir "b.xml")))
(concat "--standard=" (expand-file-name standard-file)))))
source)
;; step 3 bind a function to :working-directory if important
:working-directory flycheck-php-project-root)
```
My code is so messy, so I strongly recommend you see flycheck.el.
What I wanna say is that you can define both :command and :working-directory with functions and `eval`!
girvain · 2022-06-05 07:23
I managed to get to the bottom of it. First of all the code standard configs relative path weren’t set properly (not anything to do with me). Next was lsp mode taking over as the first checker and breaking the chain of the flycheck checkers for Php so I disabled the lsp checker for Php-mode. Now I don’t even need any custom flycheck checkers just a dir-locals file to set the executable and code standard. Thanks for your help with this. If anyone has ends up I’m the same boat message me and I’ll share my config but what I said should be enough info I think.