Home

Awesome

coc-php-cs-fixer

PHP CS Fixer (PHP Coding Standards Fixer) and Laravel Pint extension for coc.nvim

Install

:CocInstall coc-php-cs-fixer

Features

php-cs-fixer and laravel/pint are supported.

Note

The formatter tool used is php-cs-fixer by default. If you want to use laravel/pint, change the php-cs-fixer.activateTool setting in coc-settings.json.

{
  "php-cs-fixer.activateTool": "pint"
}

Detects the php-cs-fixer or pint tool. They are prioritized in order from the top.

  1. php-cs-fixer.toolPath or php-cs-fixer.pint.toolPath
  2. vendor/bin/php-cs-fixer or vendor/bin/pint
  3. php-cs-fixer or pint retrieved by the download feature (:CocCommand php-cs-fixer.download or php-cs-fixer.pintDownload)
    • php-cs-fixer:
      • Mac/Linux: ~/.config/coc/extensions/coc-php-cs-fixer-data/php-cs-fixer
      • Windows: ~/AppData/Local/coc/extensions/coc-php-cs-fixer-data/php-cs-fixer
    • pint:
      • Mac/Linux: ~/.config/coc/extensions/coc-php-cs-fixer-data/pint
      • Windows: ~/AppData/Local/coc/extensions/coc-php-cs-fixer-data/pint

If "1" and "2" above are not detected, the download feature will be executed (The prompt will be displayed)

Usage

coc-php-cs-fixer can be executed in multiple ways.

Auto run when saving a file

Add the settings to coc-settings.json.

{
  "[php]": {
    "coc.preferences.formatOnSave": true
  },
}

If the file size is large or the tool (php-cs-fixer or pint) is slow in your environment, formatting may not work properly when saving. In coc.nvim, time-consuming formatting on save is canceled.

In that case, please perform the formatting in another way.

Run from CocCommand

Run formatting from call function

Run codeAction from call function

Precedence of "php-cs-fixer" and "laravel/pint" configuration files and options

php-cs-fixer

  1. php-cs-fixer.config setting for this extension.
  2. .php-cs-fixer.php or .php-cs-fixer.dist.php config file in the workspace (project) root.
  3. options-reated settings for this extension. e.g. php-cs-fixer.rules and more.

pint

  1. php-cs-fixer.pint.config setting for this extension.
  2. pint.json config file in the workspace (project) root.
  3. options-reated settings for this extension. php-cs-fixer.pint.preset.

Configuration options

Commands

Code Actions

Thanks

License

MIT


This extension is built with create-coc-extension