3

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

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
taher
  • 539
  • 1
  • 9
  • 22

1 Answers1

2

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.

Fenton
  • 241,084
  • 71
  • 387
  • 401
  • 2
    Is it possible use lint in current file instead of value for args that you used? – taher May 01 '15 at 15:29
  • A more sophisticated regex and task: https://github.com/ikappas/vscode-phpcs/issues/28#issuecomment-517370358 ( I couldn't get it to work, but maybe someone else can ) – mbomb007 Jan 10 '20 at 20:18