Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxyudin/4988d7de94f73610face7afbf76c0c00 to your computer and use it in GitHub Desktop.
Save maxyudin/4988d7de94f73610face7afbf76c0c00 to your computer and use it in GitHub Desktop.
phpcs + WordPress Coding Standards + Sublime Text 3

phpcs + WordPress Coding Standards + Sublime Text 3

phpcs установлен через composer глобально в ~/.config/composer/vendor/squizlabs/php_codesniffer/

Для конкретного проекта:

Создать composer.json в директории проекта:

{
    "name": "maxyudin/my-project-name",
    "description": "Some description",
    "type": "project",
    "require": {},
    "require-dev": {
        "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
        "wp-coding-standards/wpcs": "^2.3",
        "phpcompatibility/phpcompatibility-wp": "*"
    }
}

Затем в консоли:

$ cd ~/project/directory/path
$ composer update

И проверить, что все ОК:

$ ./vendor/bin/phpcs -i

Должно получиться так:

The installed coding standards are Squiz, Zend, MySource, PSR12, PSR2, PEAR, PSR1, PHPCompatibility, PHPCompatibilityParagonieSodiumCompat, PHPCompatibilityParagonieRandomCompat, PHPCompatibilityWP, WordPress-Core, WordPress-Extra, WordPress and WordPress-Docs

Sublime Text

  • Установить SublimeLinter
  • Установить SublimeLinter-phpcs

Preferences -> Package Settings -> SublimeLinter -> Settings

// SublimeLinter Settings - User
{
    "paths": {
        "linux": "~/.config/composer/vendor/squizlabs/php_codesniffer/bin/phpcs",
        "osx": [],
        "windows": [],
    },
    "linters": {
        "phpcs": {
            "@disable": false,
            "excludes": [
                "*.html",
            ],
            "args": "--standard=WordPress --runtime-set testVersion 5.4- -s",
        }
    },
}

"args" нужно поменять на нужный стандарт и версию PHP.


Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment