Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Last active October 24, 2023 19:12

Revisions

  1. GaryJones revised this gist May 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion notes.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ git checkout 2.9.0

    ## Add path/to/phpcs/scripts to $PATH

    Tell Mac OS where it should look for executables.
    Tell Mac OS where it should look for executables. Add the following to the `~/.bash_profile` (or equivalent for other shells) file (creating it if it doesn't exist):

    ```sh
    export PATH=~/code/phpcs/scripts:$PATH
  2. GaryJones revised this gist May 21, 2017. 1 changed file with 18 additions and 4 deletions.
    22 changes: 18 additions & 4 deletions notes.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    ## Install PHP_CodeSniffer via git
    ## Install PHP_CodeSniffer (PHPCS) via git

    You can use the `.phar` for PHPCS, but it's easier to pull the repo down from git to then choose what version to use.

    ```sh
    cd ~
    @@ -8,20 +10,23 @@ git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs
    ```

    ## Use PHP_CodeSniffer 2.9
    WPCS does not support PHPCS 3.0 as it is a complete rewrite (namespaces etc.), so use 2.9 branch for now.

    ```sh
    git checkout 2.9.0
    ```

    ## Add path/to/phpcs/scripts to $PATH

    Tell Mac OS where it should look for executables.

    ```sh
    export PATH=~/code/phpcs/scripts:$PATH
    ```

    Check it is working by doing `which phpcs`. You may need to close and re-open the terminal.
    Check it is working by doing `which phpcs`, which should return the correct path. You may need to close and re-open the terminal.

    ## Install wpcs via git
    ## Install WordPress Coding Standards (WPCS) via git

    ```sh
    git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
    @@ -32,16 +37,24 @@ git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standar
    phpcs --config-set installed_paths ~/code/wpcs
    ```

    Check it is installed with `phpcs -i`.
    Check it is installed with `phpcs -i`. You should see WordPress, WordPress-Core, WordPress-Extra, WordPress-Docs and WordPress-VIP amongst the built-in standards.

    ## Install SublimeLinter package
    SublimeLinter 3 is the framework that allows linter subpackages to work (think of it like PostCSS, which doesn't do anything on its own).

    CMD-Shift-P -> Install Package -> SublimeLinter

    ## Install sublimelinter-phpcs package

    Now install the linter for PHPCS.

    CMD-Shift-P -> Install Package -> sublimelinter-phpcs

    (There are also `sublimelinter-*` packages for Sass, CSS, XML, JSHint etc.)

    ## Add ~/code/phpcs/scripts to osx sublime-settings
    We also need to tell Sublime Text where to look for the PHPCS executable.

    Tools -> SublimeLinter -> Open User Settings.

    ```json
    @@ -67,3 +80,4 @@ Tools -> SublimeLinter -> Open User Settings.

    ## Restart Sublime Text

    Open a PHP file and look for red outlines for issues. Move cursor to there and check status bar for description. Turn on Tools -> SublimeLinter ->Debug Mode and View -> Show Console for more information. You can also change the settings so that errors are shown on save etc. See repo for what these mean.
  3. GaryJones revised this gist May 19, 2017. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions notes.md
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,8 @@ git checkout 2.9.0
    export PATH=~/code/phpcs/scripts:$PATH
    ```

    Check it is working by doing `which phpcs`. You may need to close and re-open the terminal.

    ## Install wpcs via git

    ```sh
    @@ -27,15 +29,17 @@ git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standar

    ## Add WordPress Coding Standard to PHP_CodeSniffer
    ```sh
    phpcs --config-set installed_paths path/to/wpcs
    phpcs --config-set installed_paths ~/code/wpcs
    ```

    Check it is installed with `phpcs -i`.

    ## Install SublimeLinter package
    CMD-Shift-P -> Install Package -> SublimeLinter

    ## Install sublimelinter-phpcs package

    CMD-Shift-P -> Install Package -> sublimtlinter-phpcs
    CMD-Shift-P -> Install Package -> sublimelinter-phpcs

    ## Add ~/code/phpcs/scripts to osx sublime-settings
    Tools -> SublimeLinter -> Open User Settings.
    @@ -61,4 +65,5 @@ Tools -> SublimeLinter -> Open User Settings.
    },
    ```

    ## Restart Sublime
    ## Restart Sublime Text

  4. GaryJones created this gist May 19, 2017.
    64 changes: 64 additions & 0 deletions notes.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    ## Install PHP_CodeSniffer via git

    ```sh
    cd ~
    mkdir -p code
    cd code
    git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs
    ```

    ## Use PHP_CodeSniffer 2.9

    ```sh
    git checkout 2.9.0
    ```

    ## Add path/to/phpcs/scripts to $PATH

    ```sh
    export PATH=~/code/phpcs/scripts:$PATH
    ```

    ## Install wpcs via git

    ```sh
    git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
    ```

    ## Add WordPress Coding Standard to PHP_CodeSniffer
    ```sh
    phpcs --config-set installed_paths path/to/wpcs
    ```

    ## Install SublimeLinter package
    CMD-Shift-P -> Install Package -> SublimeLinter

    ## Install sublimelinter-phpcs package

    CMD-Shift-P -> Install Package -> sublimtlinter-phpcs

    ## Add ~/code/phpcs/scripts to osx sublime-settings
    Tools -> SublimeLinter -> Open User Settings.

    ```json
    "paths": {
    "linux": [],
    "osx": [
    '~/code/phpcs/scripts'
    ],
    "windows": []
    },
    ```

    ## Change standard to WordPress

    ```json
    "phpcs": {
    "@disable": false,
    "args": [],
    "excludes": [],
    "standard": "WordPress"
    },
    ```

    ## Restart Sublime