Tag: Sublime Text

  • How to install a php linter (WordPress standards) in Windows 10 and Sublime Text 3

    How to install a php linter (WordPress standards) in Windows 10 and Sublime Text 3

    For some time now, I’ve been thinking that I needed to get a php linter in my workflow.

    This little addition will decrease debugging time, letting me know instantly if there’s some kind of syntax mistake, and also with WordPress standards active will instruct me to follow all the coding standards.

    After a little chat with some friends yesterday night and seeing once again linting in action, I said to myself “Today I’ll get this thing working on Windows”.

    After some experiments and reading I’ve encountered the easiest and safest way to do this install, and finally get linting working on my setup (Windows + Sublime Text 3) these are the steps:

    Install PHP

    • Download the binaries from http://windows.php.net/download/ (I’ve selected the VC11 x86 Non Thread Safe version for my setup.)
    • Unzip the downloaded folder to c:\php
    • Activate some basic php modules:
      • Copy php.ini-production to php.ini
      • Uncomment the following lines:
        • extension_dir = “ext”
        • extension=php_bz2.dll
        • extension=php_curl.dll
        • extension=php_fileinfo.dll
        • extension=php_gd2.dll
        • extension=php_intl.dll
        • extension=php_mbstring.dll
        • extension=php_exif.dll
        • extension=php_openssl.dll
        • extension=php_pdo_mysql.dll
        • extension=php_pdo_sqlite.dll

    Install Composer

    Install PHP Code Sniffer using Composer

    • On your bash console run the following comand:
    • composer global require "squizlabs/php_codesniffer=*"

    Install WordPress PHPCS standards

    • On console discover the path to the linter executable
    • which phpcs
    • Go to the PHPCS directory, it should be something like: C:\Users\{your-user}\AppData\Roaming\Composer\vendor\bin\
    • Clone WordPress standards
    • git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
    • Add WordPress to PHPCS configuration

    • phpcs --config-set installed_paths /c/Users/{your-user}/AppData/Roaming/Composer/vendor/bin/wpcs
    • Set the default Standard as WordPress
    • phpcs --config-set default_standard WordPress

    Install Linter on Sublime Text 3

    The last steps are installing the linter packages on Sublime Text 3, for this open your Package Control and install the following packages:

    1. SublimeLinter
    2. SublimeLinter-phpcs

    Next, you’ll need to restart sublime and setup the linter configuration, it’s fairly simple, just copy the file in “Preferences/Package Settings/SublimeLinter/Settings – Default” to “Preferences/Package Settings/SublimeLinter/Settings – User” and edit the phpcs linter configuration setting the standard as WordPress:

    "phpcs": {
        "standard": "WordPress"
     },