Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code and php

Is it possible to use phplint and phpcs with Visual Studio Code editor?
It seems that it's possible with Visual Studio Code tasks, is it right? If yes, how?
Visual Studio Code Tasks

like image 848
taher Avatar asked Sep 02 '26 09:09

taher


1 Answers

This is a very basic example of a PHPLint task for Visual Studio Code. It isn't very sophisticated, but you will see that it gets things working.

A more sophisticated Regular Expression is needed to properly identify which lines are errors, which are warnings, and which don't matter at all.

{
    "command": "C:\\phplint\\phpl.bat",
    "version": "0.1.0",
    "args": [
        "C:\\Code\\index.php"
    ],
    "problemMatcher": {
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(.*)$",
            "message": 1
        }
    }
}

I am using a custom problem matcher to parse the output of PHPLint. The pattern has a regexp, which parses the output of PHPLint, followed by a list of what is in each position (in this case, I am just treating the whole line as a "message" - a bit too basic, but you get the idea).

This is essentially how you would create a task for anything you can access on the command line.

like image 114
Fenton Avatar answered Sep 04 '26 10:09

Fenton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!