https://github.com/guanguans/php-cs-fixer-custom-fixers
Use php-cs-fixer to format bats,blade.php,Dockerfile,env,json,md,mdx,sh,sql,tex,text,toml,txt,xml,yaml...files.
https://github.com/guanguans/php-cs-fixer-custom-fixers
autocorrect blade-formatter dockerfmt dotenv-linter format lint lint-md markdownlint php-cs-fixer pint shfmt sqlfluff sqruff textlint tombi typos xmllint yamlfmt zhlint
Last synced: 3 months ago
JSON representation
Use php-cs-fixer to format bats,blade.php,Dockerfile,env,json,md,mdx,sh,sql,tex,text,toml,txt,xml,yaml...files.
- Host: GitHub
- URL: https://github.com/guanguans/php-cs-fixer-custom-fixers
- Owner: guanguans
- License: mit
- Created: 2025-12-05T15:33:17.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-03-26T21:15:30.000Z (3 months ago)
- Last Synced: 2026-03-27T03:49:05.462Z (3 months ago)
- Topics: autocorrect, blade-formatter, dockerfmt, dotenv-linter, format, lint, lint-md, markdownlint, php-cs-fixer, pint, shfmt, sqlfluff, sqruff, textlint, tombi, typos, xmllint, yamlfmt, zhlint
- Language: PHP
- Homepage:
- Size: 331 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# php-cs-fixer-custom-fixers
> [!NOTE]
> Use php-cs-fixer to format bats,blade.php,Dockerfile,env,json,md,mdx,sh,sql,tex,text,toml,txt,xml,yaml...files. - 使用 php-cs-fixer 去格式化 bats、blade.php、Dockerfile、env、json、md、mdx、sh、sql、tex、text、toml、txt、xml、yaml...文件。
> A set of custom fixers for friendsofphp/php-cs-fixer. - 一套针对 `friendsofphp/php-cs-fixer` 的自定义修复器。
[](https://github.com/guanguans/php-cs-fixer-custom-fixers/actions/workflows/tests.yml)
[](https://github.com/guanguans/php-cs-fixer-custom-fixers/actions/workflows/php-cs-fixer.yml)
[](https://codecov.io/gh/guanguans/php-cs-fixer-custom-fixers)
[](https://packagist.org/packages/guanguans/php-cs-fixer-custom-fixers)
[](https://github.com/guanguans/php-cs-fixer-custom-fixers/releases)
[](https://packagist.org/packages/guanguans/php-cs-fixer-custom-fixers)
[](https://packagist.org/packages/guanguans/php-cs-fixer-custom-fixers)
## Requirement
* PHP >= 7.4
## Installation
```shell
composer require guanguans/php-cs-fixer-custom-fixers --dev --ansi -v
```
## Usage
### In your php-cs-fixer configuration([sample](.php-cs-fixer-custom.php)) register fixers and use them
```diff
registerCustomFixers($fixers = Guanguans\PhpCsFixerCustomFixers\Fixers::make())
->setRules([
'@PhpCsFixer:risky' => true,
+ Guanguans\PhpCsFixerCustomFixers\Fixer\CommandLineTool\BladeFormatterFixer::name() => true,
+ Guanguans\PhpCsFixerCustomFixers\Fixer\CommandLineTool\YamlfmtFixer::name() => true,
+ // Other fixers...
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
+ // ->name(Guanguans\PhpCsFixerCustomFixers\Fixer\CommandLineTool\BladeFormatterFixer::make()->extensionPatterns())
+ // ->name(Guanguans\PhpCsFixerCustomFixers\Fixer\CommandLineTool\YamlfmtFixer::make()->extensionPatterns())
+ // Other ...
+ ->name($fixers->extensionPatterns())
);
```
### Run php-cs-fixer
```shell
vendor/bin/php-cs-fixer check --config=.php-cs-fixer-custom.php --show-progress=dots --diff --ansi -vv # Check only
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer-custom.php --show-progress=dots --diff --dry-run --ansi -vv # Check only
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer-custom.php --show-progress=dots --diff --ansi -vv # Fix
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer-custom.php --show-progress=dots --diff --ansi -vvv --sequential # Fix with show debug information
```
## Fixers
AutocorrectFixer
Format `txt` files using [`autocorrect`](https://github.com/huacnlee/autocorrect).
Risky: it depends on the configuration of `autocorrect`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['autocorrect']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['txt', 'text', 'md', 'markdown', 'mdx', 'tex']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-Hello世界!
+Hello 世界!
```
Sample2: configuration(`['options' => ['--type' => 'txt']]`)
```diff
-Hello世界!
+Hello 世界!
```
BladeFormatterFixer
Format `blade.php` files using [`blade-formatter`](https://github.com/shufo/blade-formatter).
Risky: it depends on the configuration of `blade-formatter`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['blade-formatter']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['blade.php']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-@if($paginator->hasPages())
+@if ($paginator->hasPages())
- @lang('pagination.previous')
- @lang('pagination.previous')
- @lang('pagination.previous')
- @lang('pagination.previous')
- {{-- Previous Page Link --}}
- @if ($paginator->onFirstPage())
-
-
- @else
-
-
- @endif
+ {{-- Previous Page Link --}}
+ @if ($paginator->onFirstPage())
+
+ @else
+
+ @endif
@endif
```
Sample2: configuration(`['options' => ['--indent-size' => 2, '--extra-liners' => true]]`)
```diff
-@if($paginator->hasPages())
-
-
- @lang('pagination.previous')
- @lang('pagination.previous')
- {{-- Previous Page Link --}}
- @if ($paginator->onFirstPage())
-
-
- @else
-
-
- @endif
-
-
+@if ($paginator->hasPages())
+
+
- @lang('pagination.previous')
- @lang('pagination.previous')
+ {{-- Previous Page Link --}}
+ @if ($paginator->onFirstPage())
+
+ @else
+
+ @endif
+
+
@endif
```
DockerfmtFixer
Format `Dockerfile` files using [`dockerfmt`](https://github.com/reteps/dockerfmt).
Risky: it depends on the configuration of `dockerfmt`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['dockerfmt']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['Dockerfile']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-RUN foo \
+RUN foo \
# comment 1
-&& \
-# comment 2
-bar && \
-# comment 3
-baz
+ # comment 2
+ && bar \
+ # comment 3
+ && baz
```
Sample2: configuration(`['options' => ['--indent' => 2]]`)
```diff
-RUN foo \
- # comment 1
-&& \
-# comment 2
-bar && \
-# comment 3
-baz
+RUN foo \
+ # comment 1
+ # comment 2
+ && bar \
+ # comment 3
+ && baz
```
DotenvLinterFixer
Format `env` files using [`dotenv-linter`](https://github.com/dotenv-linter/dotenv-linter).
Risky: it depends on the configuration of `dotenv-linter`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['dotenv-linter', 'fix']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['env', 'env.example']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-FOO= BAR
-BAR = FOO
+BAR=FOO
+FOO=BAR
```
Sample2: configuration(`['options' => ['--plain' => true]]`)
```diff
-FOO=${BAR
-BAR="$BAR}"
+BAR="${BAR}"
+FOO=${BAR}
```
Sample3: configuration(`['options' => ['--plain' => true]]`)
```diff
-FOO=BAR BAZ
+FOO="BAR BAZ"
```
LintMdFixer
Format `md` files using [`lint-md`](https://github.com/lint-md/lint-md).
Risky: it depends on the configuration of `lint-md`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['lint-md']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['md', 'markdown']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
## 全角数字
-> 这件蛋糕只卖 1000 元。
+> 这件蛋糕只卖 1000 元。
```
Sample2: configuration(`['options' => ['--suppress-warnings' => true]]`)
```diff
## 块引用空格
-> 摇旗呐喊的热情
+> 摇旗呐喊的热情
->携光阴渐远去
+> 携光阴渐远去
```
MarkdownlintCli2Fixer
Format `md` files using [`markdownlint-cli2`](https://github.com/DavidAnson/markdownlint-cli2).
Risky: it depends on the configuration of `markdownlint-cli2`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['markdownlint-cli2']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['md', 'markdown']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
# Examples
+
## This is ordered list
-1. First item
+1. First item
2. Second item
## This is unordered list
-* https://link.com
-* [ this is link ](https://link.com )
-* ** bold text **
+*
+* [this is link](https://link.com )
+* **bold text**
```
Sample2: configuration(`['options' => ['--no-globs' => true]]`)
```diff
# Examples
+
## This is ordered list
-1. First item
+1. First item
2. Second item
## This is unordered list
-* https://link.com
-* [ this is link ](https://link.com )
-* ** bold text **
+*
+* [this is link](https://link.com )
+* **bold text**
```
MarkdownlintFixer
Format `md` files using [`markdownlint`](https://github.com/igorshubovych/markdownlint-cli).
Risky: it depends on the configuration of `markdownlint`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['markdownlint']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['md', 'markdown']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
# Examples
+
## This is ordered list
-1. First item
+1. First item
2. Second item
## This is unordered list
* https://link.com
-* [ this is link ](https://link.com )
-* ** bold text **
+* [this is link](https://link.com )
+* **bold text**
```
Sample2: configuration(`['options' => ['--dot' => true]]`)
```diff
# Examples
+
## This is ordered list
-1. First item
+1. First item
2. Second item
## This is unordered list
* https://link.com
-* [ this is link ](https://link.com )
-* ** bold text **
+* [this is link](https://link.com )
+* **bold text**
```
PintFixer
Format `php` files using [`pint`](https://github.com/laravel/pint).
Risky: it depends on the configuration of `pint`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['php', 'vendor/bin/pint']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['php']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
ShfmtFixer
Format `sh` files using [`shfmt`](https://github.com/mvdan/sh).
Risky: it depends on the configuration of `shfmt`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['shfmt']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['sh', 'bats']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
#!/bin/bash
-if foo ; then
- bar
+if foo; then
+ bar
fi
for i in 1 2 3; do
- bar
+ bar
done
```
Sample2: configuration(`['options' => ['--minify' => true]]`)
```diff
#!/bin/bash
-
-if foo ; then
- bar
+if foo;then
+bar
fi
-
-for i in 1 2 3; do
- bar
+for i in 1 2 3;do
+bar
done
```
SqlfluffFixer
Format `sql` files using [`sqlfluff`](https://github.com/sqlfluff/sqlfluff).
Risky: it depends on the configuration of `sqlfluff`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['sqlfluff', 'format']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['sql']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
+SELECT
+ customer_id,
+ customer_name,
+ COUNT(order_id) AS total
FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
GROUP BY customer_id, customer_name
HAVING COUNT(order_id) > 5
ORDER BY COUNT(order_id) DESC;
```
Sample2: configuration(`['options' => ['--nocolor' => true]]`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
+SELECT
+ customer_id,
+ customer_name,
+ COUNT(order_id) AS total
FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
GROUP BY customer_id, customer_name
HAVING COUNT(order_id) > 5
ORDER BY COUNT(order_id) DESC;
```
SqruffFixer
Format `sql` files using [`sqruff`](https://github.com/quarylabs/sqruff).
Risky: it depends on the configuration of `sqruff`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['sqruff', 'fix']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['sql']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
+SELECT customer_id, customer_name, COUNT(order_id) AS total
FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
GROUP BY customer_id, customer_name
HAVING COUNT(order_id) > 5
ORDER BY COUNT(order_id) DESC;
```
Sample2: configuration(`['options' => ['--parsing-errors' => true]]`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
+SELECT customer_id, customer_name, COUNT(order_id) AS total
FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
GROUP BY customer_id, customer_name
HAVING COUNT(order_id) > 5
ORDER BY COUNT(order_id) DESC;
```
TextlintFixer
Format `txt` files using [`textlint`](https://github.com/textlint/textlint).
Risky: it depends on the configuration of `textlint`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['textlint']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['txt', 'text', 'md', 'markdown']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`['options' => ['--rule' => 'terminology']]`)
```diff
-jquery is javascript library.
+jQuery is JavaScript library.
```
Sample2: configuration(`['options' => ['--rule' => 'terminology', '--no-color' => true]]`)
```diff
-jquery is javascript library.
+jQuery is JavaScript library.
```
TombiFixer
Format `toml` files using [`tombi`](https://github.com/tombi-toml/tombi).
Risky: it depends on the configuration of `tombi`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['tombi', 'format']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['toml']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
key1 = "value1"
-key2="value2"
+key2 = "value2"
```
Sample2: configuration(`['options' => ['--diff' => true]]`)
```diff
-items = [
- "a",
- "b",
- "c"
-]
+items = ["a", "b", "c"]
```
Sample3: configuration(`['options' => ['--diff' => true]]`)
```diff
-items = ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk"]
+items = [
+ "aaa",
+ "bbb",
+ "ccc",
+ "ddd",
+ "eee",
+ "fff",
+ "ggg",
+ "hhh",
+ "iii",
+ "jjj",
+ "kkk"
+]
```
TyposFixer
Format `any` files using [`typos`](https://github.com/crate-ci/typos).
Risky: it depends on the configuration of `typos`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['typos']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['*']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-nd
-numer
-styl
+and
+number
+style
```
Sample2: configuration(`['options' => ['--sort' => true]]`)
```diff
-nd
-numer
-styl
+and
+number
+style
```
XmllintFixer
Format `xml` files using [`xmllint`](https://gnome.pages.gitlab.gnome.org/libxml2/xmllint.html).
Risky: it depends on the configuration of `xmllint`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['xmllint']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['xml', 'xml.dist']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
- `wrap_attributes_min_attrs` (`int`): minimum number of xml tag attributes for force wrap attribute options; defaults to `5`
Sample1: configuration(`default`)
```diff
-
+
+
-
-
+
+
-
- src/
-
+
+ src/
+
```
Sample2: configuration(`['options' => ['--noblanks' => true]]`)
```diff
-
+
+
-
-
+
+
-
- src/
-
+
+ src/
+
```
YamlfmtFixer
Format `yaml` files using [`yamlfmt`](https://github.com/google/yamlfmt).
Risky: it depends on the configuration of `yamlfmt`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['yamlfmt']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['yaml', 'yml']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
issues:
- types: [ opened ]
+ types: [opened]
```
Sample2: configuration(`['options' => ['-verbose' => true]]`)
```diff
to_be_merged: &tbm
key1: value1
merged_map:
- <<: *tbm
+ !!merge <<: *tbm
```
Sample3: configuration(`['options' => ['-verbose' => true]]`)
```diff
-commands: >
+commands: >-
[ -f "/usr/local/bin/foo" ] &&
echo "skip install" ||
go install github.com/foo/foo@latest
```
ZhlintFixer
Format `zh_CN.md` files using [`zhlint`](https://github.com/zhlint-project/zhlint).
Risky: it depends on the configuration of `zhlint`.
Configuration options:
- `command` (`string[]`): the command to run and its arguments listed as separate entries; defaults to `['zhlint']`
- `cwd` (`string`, `null`): the working directory or null to use the working dir of the current PHP process; defaults to `null`
- `env` (`array`): the environment variables or null to use the same environment as the current PHP process; defaults to `[]`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['zh_CN.md']`
- `input` (`string`, `null`): the input as stream resource, scalar or \Traversable, or null for no input; defaults to `null`
- `options` (`array`): the command options to run listed as separate entries; defaults to `[]`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `null`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
- `timeout` (`float`, `int`, `null`): the timeout in seconds or null to disable; defaults to `10`
Sample1: configuration(`default`)
```diff
-3 minute(s) left 中文
+3 minute(s)left 中文
-case-abbr:Pure JavaScript (a.k.a. Vanilla) 中文
+case-abbr:Pure JavaScript(a.k.a. Vanilla)中文
-case-backslash:a \# b 中文\# __中文__ \# 中文 __\#__ __中文__\#中文__\#__
+case-backslash:a \# b 中文\# __中文__ \# 中文 __\#__ __中文__\#中文 __\#__
-case-traditional:a「b『c』d」e 中文
+case-traditional:a “b ‘c’ d” e 中文
-mark-raw:a `b` c `d`e`f` g`h`i 中文
+mark-raw:a `b` c `d` e `f` g `h` i 中文
-mark-type:a__[b](x)__c__[ d ](y)__e 中文
+mark-type:a__[b](x)__c__ [d](y) __e 中文
-space-brackets:(x)a(b)c (d )e( f) g ( h ) i(j)k (l) m __( a )__ b( __c__ )d(e) 中文
+space-brackets:(x)a(b)c(d)e(f)g(h)i(j)k(l)m__(a)__b(__c__)d(e)中文
-space-punctuation:中文 。 中文(中文)中文。中文 . 中文(中文)中文.
+space-punctuation:中文。中文(中文)中文。中文。中文(中文)中文。
-space-quotations: a " hello world " b 中文
+space-quotations:a “hello world” b 中文
-unify-punctuation:中文,中文 (中文) 中文'中文'中文"中文"中文 (中文)(中文)中文 (中文)。
+unify-punctuation:中文,中文(中文)中文 ‘中文’ 中文 “中文” 中文(中文)(中文)中文(中文)。
```
Sample2: configuration(`['options' => ['--config' => null]]`)
```diff
-3 minute(s) left 中文
+3 minute(s)left 中文
-case-abbr:Pure JavaScript (a.k.a. Vanilla) 中文
+case-abbr:Pure JavaScript(a.k.a. Vanilla)中文
-case-backslash:a \# b 中文\# __中文__ \# 中文 __\#__ __中文__\#中文__\#__
+case-backslash:a \# b 中文\# __中文__ \# 中文 __\#__ __中文__\#中文 __\#__
-case-traditional:a「b『c』d」e 中文
+case-traditional:a “b ‘c’ d” e 中文
-mark-raw:a `b` c `d`e`f` g`h`i 中文
+mark-raw:a `b` c `d` e `f` g `h` i 中文
-mark-type:a__[b](x)__c__[ d ](y)__e 中文
+mark-type:a__[b](x)__c__ [d](y) __e 中文
-space-brackets:(x)a(b)c (d )e( f) g ( h ) i(j)k (l) m __( a )__ b( __c__ )d(e) 中文
+space-brackets:(x)a(b)c(d)e(f)g(h)i(j)k(l)m__(a)__b(__c__)d(e)中文
-space-punctuation:中文 。 中文(中文)中文。中文 . 中文(中文)中文.
+space-punctuation:中文。中文(中文)中文。中文。中文(中文)中文。
-space-quotations: a " hello world " b 中文
+space-quotations:a “hello world” b 中文
-unify-punctuation:中文,中文 (中文) 中文'中文'中文"中文"中文 (中文)(中文)中文 (中文)。
+unify-punctuation:中文,中文(中文)中文 ‘中文’ 中文 “中文” 中文(中文)(中文)中文(中文)。
```
JsonFixer
Format `json` files.
Risky: it depends on the configuration.
Configuration options:
- `decode_flags` (`int`): the flags to use when decoding JSON; defaults to `0`
- `encode_flags` (`int`): the flags to use when encoding JSON; defaults to `7342016`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['json']`
- `indent_string` (`' '`, `' '`, `'\t'`): the string to use for indentation; defaults to `' '`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `'\n'`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
Sample1: configuration(`default`)
```diff
{
- "phrase": "\u4f60\u597d\uff01"
+ "phrase": "你好!"
}
```
Sample2: configuration(`['indent_string' => ' ']`)
```diff
{
- "name": "guanguans/php-cs-fixer-custom-fixers",
- "keywords": [
- "dev",
- "fixer",
- "standards"
- ],
- "authors": [
- {
- "name": "guanguans",
- "email": "ityaozm@gmail.com",
- "homepage": "https://github.com/guanguans"
- }
- ]
+ "name": "guanguans/php-cs-fixer-custom-fixers",
+ "keywords": [
+ "dev",
+ "fixer",
+ "standards"
+ ],
+ "authors": [
+ {
+ "name": "guanguans",
+ "email": "ityaozm@gmail.com",
+ "homepage": "https://github.com/guanguans"
+ }
+ ]
}
```
SqlOfDoctrineSqlFormatterFixer
Format `sql` files using [`doctrine/sql-formatter`](https://github.com/doctrine/sql-formatter).
Risky: it depends on the configuration of `doctrine/sql-formatter`.
Configuration options:
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['sql']`
- `indent_string` (`' '`, `' '`, `'\t'`): the SQL string with HTML styles and formatting wrapped in a <pre> tag; defaults to `' '`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `'\n'`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
Sample1: configuration(`default`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
-FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
-GROUP BY customer_id, customer_name
-HAVING COUNT(order_id) > 5
-ORDER BY COUNT(order_id) DESC;
+SELECT
+ customer_id,
+ customer_name,
+ COUNT(order_id) AS total
+FROM
+ customers
+ INNER JOIN orders ON customers.customer_id = orders.customer_id
+GROUP BY
+ customer_id,
+ customer_name
+HAVING
+ COUNT(order_id) > 5
+ORDER BY
+ COUNT(order_id) DESC;
```
Sample2: configuration(`['indent_string' => ' ']`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
-FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
-GROUP BY customer_id, customer_name
-HAVING COUNT(order_id) > 5
-ORDER BY COUNT(order_id) DESC;
+SELECT
+ customer_id,
+ customer_name,
+ COUNT(order_id) AS total
+FROM
+ customers
+ INNER JOIN orders ON customers.customer_id = orders.customer_id
+GROUP BY
+ customer_id,
+ customer_name
+HAVING
+ COUNT(order_id) > 5
+ORDER BY
+ COUNT(order_id) DESC;
```
SqlOfPhpmyadminSqlParserFixer
Format `sql` files using [`phpmyadmin/sql-parser`](https://github.com/phpmyadmin/sql-parser).
Risky: it depends on the configuration of `phpmyadmin/sql-parser`.
Configuration options:
- `clause_newline` (`bool`): whether each clause should be on a new line; defaults to `true`
- `extensions` (`string[]`): the supported file extensions are used for formatting; defaults to `['sql']`
- `indent_parts` (`bool`): whether each part of each clause should be indented; defaults to `true`
- `indentation` (`' '`, `' '`, `'\t'`, `null`): the string used for indentation; defaults to `null`
- `line_ending` (`'\n'`, `'\r\n'`, `null`): the line ending used; defaults to `null`
- `parts_newline` (`bool`): whether each part should be on a new line; defaults to `true`
- `remove_comments` (`bool`): whether comments should be removed or not; defaults to `false`
- `single_blank_line_at_eof` (`'\n'`, `'\r\n'`, `null`): the line ending to use at the end of the file; defaults to `'\n'`
- `skip_paths` (`string[]`): list of paths to skip; defaults to `[]`
Sample1: configuration(`default`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
-FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
-GROUP BY customer_id, customer_name
-HAVING COUNT(order_id) > 5
-ORDER BY COUNT(order_id) DESC;
+SELECT
+ customer_id,
+ customer_name,
+ COUNT(order_id) AS total
+FROM
+ customers
+INNER JOIN orders ON customers.customer_id = orders.customer_id
+GROUP BY
+ customer_id,
+ customer_name
+HAVING
+ COUNT(order_id) > 5
+ORDER BY
+ COUNT(order_id)
+DESC
+ ;
```
Sample2: configuration(`['clause_newline' => false]`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
-FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
-GROUP BY customer_id, customer_name
-HAVING COUNT(order_id) > 5
-ORDER BY COUNT(order_id) DESC;
+SELECT customer_id, customer_name, COUNT(order_id) AS total FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id GROUP BY customer_id, customer_name HAVING COUNT(order_id) > 5 ORDER BY COUNT(order_id)
+DESC;
```
Sample3: configuration(`['indentation' => ' ']`)
```diff
-SELECT customer_id, customer_name, COUNT(order_id) as total
-FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
-GROUP BY customer_id, customer_name
-HAVING COUNT(order_id) > 5
-ORDER BY COUNT(order_id) DESC;
+SELECT
+ customer_id,
+ customer_name,
+ COUNT(order_id) AS total
+FROM
+ customers
+INNER JOIN orders ON customers.customer_id = orders.customer_id
+GROUP BY
+ customer_id,
+ customer_name
+HAVING
+ COUNT(order_id) > 5
+ORDER BY
+ COUNT(order_id)
+DESC
+ ;
```
## Composer scripts
```shell
composer checks:required
composer php-cs-fixer-custom-fixers:install-command-line-tools --dry-run
composer php-cs-fixer-custom-fixers:install-command-line-tools -vvv
composer php-cs-fixer-custom-fixers:update-fixers-document
composer php-cs-fixer:fix
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
* [guanguans](https://github.com/guanguans)
* [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.