Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "laravel/pint" integration feature #7

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 66 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
# coc-php-cs-fixer

[PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) (PHP Coding Standards Fixer) extension for [coc.nvim](https://github.com/neoclide/coc.nvim)
[PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) (PHP Coding Standards Fixer) and [Laravel Pint](https://github.com/laravel/pint) extension for [coc.nvim](https://github.com/neoclide/coc.nvim)

## Install

`:CocInstall coc-php-cs-fixer`

## Features

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

- Formatter
- Command
- Code Action
- Status Bar
- `pint.json` Auto Completion and JSON validation
- Downloader

## Note

Detects the `php-cs-fixer` command. They are prioritized in order from the top.
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`.

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

- [DEMO](https://github.com/yaegassy/coc-php-cs-fixer/pull/7#issue-1293669659)

1. `php-cs-fixer.toolPath`
1. `vendor/bin/php-cs-fixer`
1. `php-cs-fixer` retrieved by the download feature (`:CocCommand php-cs-fixer.download`)
- 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`
---

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`
1. `vendor/bin/php-cs-fixer` or `vendor/bin/pint`
1. `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)

Expand All @@ -36,7 +63,10 @@ Add the settings to `coc-settings.json`.

### Run from CocCommand

- `:CocCommand php-cs-fixer.fix`
- If the `php-cs-fixer.activateTool` setting is `php-cs-fixer`
- `:CocCommand php-cs-fixer.fix`
- If the `php-cs-fixer.activateTool` setting is `pint`
- `:CocCommand php-cs-fixer.pintFix`

### Run formatting from call function

Expand All @@ -45,38 +75,63 @@ Add the settings to `coc-settings.json`.
### Run codeAction from call function

- `:call CocAction('codeAction')`
- Choose action: "Run: php-cs-fixer.fix"
- If the `php-cs-fixer.activateTool` setting is `php-cs-fixer`
- Choose action: `"Run: php-cs-fixer.fix"`
- If the `php-cs-fixer.activateTool` setting is `pint`
- Choose action: `"Run: php-cs-fixer.pintFix"`

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

## Precedence of php-cs-fixer config 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

- `php-cs-fixer.enable`: Enable coc-php-cs-fixer extension, default: `true`
- `php-cs-fixer.activateTool`: Formatter tool to be used, valid option `["php-cs-fixer", "pint"]`, default: `"php-cs-fixer"`
- `php-cs-fixer.toolPath`: The path to the php-cs-fixer tool (Absolute path), default: `""`
- `php-cs-fixer.config`: Path to php-cs-fixer config file (--config), default: `""`
- `php-cs-fixer.useCache`: Use a cache file when fixing files (--using-cache), default: `false`
- `php-cs-fixer.allowRisky`: Determines whether risky rules are allowed (--allow-risky), default: `false`
- `php-cs-fixer.rules`: Rules to use when fixing files (--rules), e.g. `"@PSR12,@Symfony"`, default: `"@PSR12"`
- `php-cs-fixer.enableIgnoreEnv`: Add the environment variable `PHP_CS_FIXER_IGNORE_ENV=1` and run php-cs-fixer, default: `false`
- `php-cs-fixer.downloadCheckOnStartup`: Perform built-in download if php-cs-fixer is not present at startup, default: `true`
- `php-cs-fixer.pint.toolPath`: The path to the pint tool (Absolute path), default: `""`
- `php-cs-fixer.pint.config`: Path to `pint.json` config file (`--config`), default: `""`
- `php-cs-fixer.pint.preset`: Presets define a set of rules that can be used to fix code style issues in your code (`--preset`), valid option `["laravel", "psr12", "symfony"]`, default: `"laravel"`
- `php-cs-fixer.downloadCheckOnStartup`: If `php-cs-fixer` or `pint` is not present at startup, run the built-in download. The tool to be downloaded will follow the `php-cs-fixer.activateTool` configuration, default: `true`
- `php-cs-fixer.downloadMajorVersion`: Specify the major version of php-cs-fixer to download for the extension, valid option `[2, 3]`, default: `3`
- `php-cs-fixer.enableFormatProvider`: Enable format provider, default: `true`
- `php-cs-fixer.enableActionProvider`: Enable codeAction provider, default: `true`

## Commands

- `php-cs-fixer.fix`: Run php-cs-fixer fix
- `php-cs-fixer.pintFix`: Run pint
- `php-cs-fixer.download`: Download php-cs-fixer
- By default, the "v3" series will be downloaded. If you want to download "v2" series, please change the `php-cs-fixer.downloadMajorVersion` setting.
- `php-cs-fixer.pintDownload`: Download pint
- `php-cs-fixer.showOutput`: Show php-cs-fixer output channel

## Code Actions

- `Run: php-cs-fixer.fix`
- `Run: php-cs-fixer.pintFix`

## Thanks

- <https://github.com/FriendsOfPHP/PHP-CS-Fixer>
- <https://github.com/laravel/pint>
- <https://github.com/mlocati/php-cs-fixer-configurator>
- <https://github.com/open-southeners/vscode-laravel-pint>

## License

Expand Down
49 changes: 47 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"url": "https://github.com/yaegassy/coc-php-cs-fixer"
},
"scripts": {
"schema": "curl -o schemas/pint-schema.json https://raw.githubusercontent.com/open-southeners/vscode-laravel-pint/main/pint-schema.json",
"lint": "eslint src --ext ts",
"clean": "rimraf lib",
"watch": "node esbuild.js --watch",
Expand Down Expand Up @@ -53,6 +54,12 @@
"onLanguage:php"
],
"contributes": {
"jsonValidation": [
{
"fileMatch": "pint.json",
"url": "./schemas/pint-schema.json"
}
],
"configuration": {
"type": "object",
"title": "coc-php-cs-fixer configuration",
Expand All @@ -61,7 +68,8 @@
"filetype": "php",
"patterns": [
".php-cs-fixer.php",
".php-cs-fixer.dist.php"
".php-cs-fixer.dist.php",
"pint.json"
]
}
],
Expand All @@ -71,6 +79,15 @@
"default": true,
"description": "Enable coc-php-cs-fixer extension"
},
"php-cs-fixer.activateTool": {
"type": "string",
"default": "php-cs-fixer",
"description": "",
"enum": [
"php-cs-fixer",
"pint"
]
},
"php-cs-fixer.toolPath": {
"type": "string",
"default": "",
Expand Down Expand Up @@ -104,7 +121,7 @@
"php-cs-fixer.downloadCheckOnStartup": {
"type": "boolean",
"default": true,
"description": "Perform built-in download if php-cs-fixer is not present at startup"
"description": "If `php-cs-fixer` or `pint` is not present at startup, run the built-in download. The tool to be downloaded will follow the `php-cs-fixer.activateTool` configuration"
},
"php-cs-fixer.downloadMajorVersion": {
"type": "number",
Expand All @@ -116,6 +133,26 @@
"description": "Specify the major version of php-cs-fixer to download for the extension",
"scope": "window"
},
"php-cs-fixer.pint.toolPath": {
"type": "string",
"default": "",
"description": "The path to the pint tool (Absolute path)"
},
"php-cs-fixer.pint.config": {
"type": "string",
"default": "",
"description": "Path to pint.json config file (--config)"
},
"php-cs-fixer.pint.preset": {
"type": "string",
"default": "laravel",
"description": "Presets define a set of rules that can be used to fix code style issues in your code (--preset)",
"enum": [
"laravel",
"psr12",
"symfony"
]
},
"php-cs-fixer.enableFormatProvider": {
"type": "boolean",
"default": true,
Expand All @@ -140,6 +177,14 @@
{
"command": "php-cs-fixer.showOutput",
"title": "Show php-cs-fixer output channel"
},
{
"command": "php-cs-fixer.pintFix",
"title": "Run pint"
},
{
"command": "php-cs-fixer.pintDownload",
"title": "Download pint"
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions schemas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Schemas

## pint-schema.json

- <https://raw.githubusercontent.com/open-southeners/vscode-laravel-pint/main/pint-schema.json>
Loading