It is true. I created a VSCode plugin using Typescript to lint and format PHP files.
Current status of PHP Linter tools
While PHP has been around for a long time, linting and formatting PHP files are not as supported or maitained as other languages (say Javascript or python).
PHP has built in linting switch php -l
, but its only for syntax errors. It does not check for code style or formatting. This functionality can be easily added using many of the VSCode extensions.
In addition to that, there two popular libraries to lint/format PHP files:
- Has the most installs on packagist.
- Not regularly maintained. Commits are few and far between.
- Has an outdated documentation (last updated in 2016).
- Uses
xml
for configuration which is an outdated format for configuration.
2- PHP CS Fixer
- Highly maintined and regularly updated.
- It has fewer installs than PHP Code Sniffer, but the margin is not that big.
- Has a detailed documentation but it is still hard to navigate.
- Uses PHP for configuration which is a better format than
xml
but still not ideal.
Unfortunately, both libraries are not easy to configure and setup. Also, both libraries have a number of VSCode extensions, but they require the path to PHP executable to be set in the configuration, which is not as easy as it sounds, at least in my experience.
This extension
PHPTaqwim (Arabic for correction) aims to be a simple and easy to use extension to lint and format PHP files. It requires no configuration and it works out of the box. It is also configurable if you want to customize it.
Interestingly, it is written in Typescript, not PHP. This is the reason that it does not require PHP runtime to be installed on your machine. It uses PHP Parser under the hood to get PHP AST and apply the rules.
It also comes as a NPM CLI package, so you can use it in your CI/CD pipeline.