Skip to content

Commit f252314

Browse files
committed
update README
1 parent f0ad4ab commit f252314

1 file changed

Lines changed: 9 additions & 248 deletions

File tree

README.md

Lines changed: 9 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -1,256 +1,17 @@
1-
# The Easiest way to use Coding Standard
1+
# Easy Coding Standard – Development Repository
22

3-
[![Downloads total](https://img.shields.io/packagist/dt/symplify/easy-coding-standard.svg?style=flat-square)](https://packagist.org/packages/symplify/easy-coding-standard/stats)
3+
Development repository of [Symplify EasyCodingStandard (ECS)](https://github.com/easy-coding-standard/ecs). Code here is scoped, downgraded and deployed to the [easy-coding-standard/ecs](https://github.com/easy-coding-standard/ecs) repository that `composer require symplify/easy-coding-standard` installs.
44

5-
> [!IMPORTANT]
6-
> This is the **development repository** only. The code here is scoped, downgraded and deployed to the [easy-coding-standard/ecs](https://github.com/easy-coding-standard/ecs) repository, which is what `composer require symplify/easy-coding-standard` actually installs.
7-
>
8-
> Use this repository to **report issues and send pull requests**. Do not require it directly.
5+
User documentation lives in [`build/target-repository/README.md`](build/target-repository/README.md).
96

10-
<br>
11-
12-
## Killer Features
13-
14-
- Install on **any PHP 7.2-PHP 8.5** project with any dependencies
15-
- Blazing fast with parallel run out of the box
16-
- Use [PHP_CodeSniffer or PHP-CS-Fixer](https://tomasvotruba.com/blog/2017/05/03/combine-power-of-php-code-sniffer-and-php-cs-fixer-in-3-lines/) - anything you like
17-
- Use **prepared sets** and [PHP CS Fixer sets](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst) to save time
18-
19-
<br>
20-
21-
## Install
7+
PHP `>=8.4` required.
228

239
```bash
24-
composer require symplify/easy-coding-standard --dev
25-
```
26-
27-
<br>
28-
29-
## Usage
10+
composer install
3011

31-
```bash
32-
vendor/bin/ecs
33-
```
34-
35-
On the first run, ECS creates `ecs.php` config file with directories and first rule to kick off.
36-
37-
Then you can run again to see the suggested diffs:
38-
39-
```bash
40-
vendor/bin/ecs
12+
composer test # PHPUnit tests
13+
composer lint # phpstan + rector dry-run + check-cs
14+
composer lint.fix # auto-fix rector + coding standard
4115
```
4216

43-
To actually **fix your code**, add `--fix`:
44-
45-
```bash
46-
vendor/bin/ecs --fix
47-
```
48-
49-
That's it!
50-
51-
<br>
52-
53-
## Configure
54-
55-
Most of the time, you'll be happy with the default configuration. The most relevant part is configuring paths, checkers and sets:
56-
57-
```php
58-
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
59-
use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;
60-
use Symplify\EasyCodingStandard\Config\ECSConfig;
61-
62-
return ECSConfig::configure()
63-
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
64-
65-
// start slow with sole rules
66-
->withRules([
67-
ListSyntaxFixer::class,
68-
])
69-
->withConfiguredRule(
70-
ArraySyntaxFixer::class,
71-
['syntax' => 'long']
72-
)
73-
74-
// apply full set
75-
->withPreparedSets(psr12: true);
76-
```
77-
78-
<br>
79-
80-
Do you want to check all `*.php` files in your root (`ecs.php`, `rector.php` etc.)? Instead of listing them one by one, use `->withRootFiles()` method:
81-
82-
```php
83-
use Symplify\EasyCodingStandard\Config\ECSConfig;
84-
85-
return ECSConfig::configure()
86-
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
87-
->withRootFiles();
88-
```
89-
90-
<br>
91-
92-
### Gradual Adoption with Levels
93-
94-
Want to adopt a coding standard step by step instead of all at once? Use `with*Level()` methods to start from the safest rules and raise the level as your codebase catches up:
95-
96-
```php
97-
use Symplify\EasyCodingStandard\Config\ECSConfig;
98-
99-
return ECSConfig::configure()
100-
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
101-
->withSpacesLevel(0)
102-
->withArrayLevel(0)
103-
->withControlStructuresLevel(0)
104-
->withDocblockLevel(0);
105-
```
106-
107-
Each level enables the first N+1 rules from a curated list, ordered from safest to most invasive. Bump the number once your codebase is clean on the current level.
108-
109-
<br>
110-
111-
Do you want to include one of sets from [php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst)?
112-
113-
You can:
114-
115-
```php
116-
use Symplify\EasyCodingStandard\Config\ECSConfig;
117-
118-
return ECSConfig::configure()
119-
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
120-
->withPhpCsFixerSets(perCS20: true, doctrineAnnotation: true);
121-
```
122-
123-
<br>
124-
125-
### How to Skip Files/Rules?
126-
127-
Love the sets of rules, but want to skip single rule or some files?
128-
129-
```php
130-
use Symplify\EasyCodingStandard\Config\ECSConfig;
131-
132-
return ECSConfig::configure()
133-
->withSkip([
134-
// skip single rule
135-
ArraySyntaxFixer::class,
136-
137-
// skip single rule in specific paths
138-
ArraySyntaxFixer::class => [
139-
__DIR__ . '/src/ValueObject/',
140-
],
141-
142-
// skip directory by absolute or * mask
143-
__DIR__ . '/src/Migrations',
144-
145-
// skip directories by mask
146-
__DIR__ . '/src/*/Legacy',
147-
]);
148-
```
149-
150-
<br>
151-
152-
### Less Common Options
153-
154-
You probably won't use these, but they can give you more control over the internal process:
155-
156-
```php
157-
use Symplify\EasyCodingStandard\Config\ECSConfig;
158-
use Symplify\EasyCodingStandard\ValueObject\Option;
159-
160-
return ECSConfig::configure()
161-
// file extensions to scan
162-
->withFileExtensions(['php'])
163-
164-
// configure cache paths and namespace - useful e.g. Gitlab CI caching, where getcwd() produces always different path
165-
->withCache(
166-
directory: sys_get_temp_dir() . '/_changed_files_detector_tests',
167-
namespace: getcwd() // normalized to directory separator
168-
)
169-
170-
// print contents with specific indent rules
171-
->withSpacing(indentation: Option::INDENTATION_SPACES, lineEnding: PHP_EOL)
172-
173-
// modify parallel run
174-
->withParallel(timeoutSeconds: 120, maxNumberOfProcess: 32, jobSize: 20);
175-
```
176-
177-
Mentioned values are default ones.
178-
179-
<br>
180-
181-
### Controlling Output Format
182-
183-
You may want to use ECS to generate reports for third-party tooling.
184-
185-
We currently provide formatters for:
186-
187-
- `console`: Human-oriented printing à la PHP CS Fixer.
188-
- `json`: A custom JSON blob for arbitrary tooling.
189-
- `junit`: JUnit format to be used in different CI environments.
190-
- `checkstyle`: Useful for Github Action Reports.
191-
- `gitlab`: For Gitlab code quality reports or Code Climate tooling.
192-
193-
You can use the output format option as below
194-
195-
```bash
196-
vendor/bin/ecs --output-format=checkstyle
197-
```
198-
199-
For information on how each of these behave, refer to their respective
200-
[implementations](src/Console/Output/).
201-
202-
<br>
203-
204-
## FAQ
205-
206-
<br>
207-
208-
### How do I clear cache?
209-
210-
```bash
211-
vendor/bin/ecs --clear-cache
212-
```
213-
214-
<br>
215-
216-
### How can I see all used rules?
217-
218-
```bash
219-
vendor/bin/ecs list-checkers
220-
```
221-
222-
Do you look for json format?
223-
224-
```bash
225-
vendor/bin/ecs list-checkers --output-format json
226-
```
227-
228-
<br>
229-
230-
### Can I Use My [`.editorconfig`](https://editorconfig.org/)?
231-
232-
Mostly! By using `->withEditorConfig()` in `ecs.php`, ECS will automatically discover
233-
the `.editorconfig` file in the project's root directory. It will use any
234-
rules under `[*]` or `[*.php]` (the latter taking priority) and respect the
235-
settings for:
236-
237-
- `indent_style`
238-
- `end_of_line`
239-
- `max_line_length`
240-
- `trim_trailing_whitespace`
241-
- `insert_final_newline`
242-
- [`quote_type`](https://github.com/jednano/codepainter#quote_type-single-double-auto)
243-
- Only `single` and `auto` are respected.
244-
- Warning: this is a proposed field, but not fully standard.
245-
246-
These settings will take precedence over similar rules configured through sets
247-
like PSR12, to avoid conflicting with other tooling using your `.editorconfig`.
248-
249-
<br>
250-
251-
## How to Migrate from another coding standard tool?
252-
253-
Do you use another tool and want to migrate? It's pretty straightforward - here is "how to":
254-
255-
* for [PHP_CodeSniffer](https://tomasvotruba.com/blog/2018/06/04/how-to-migrate-from-php-code-sniffer-to-easy-coding-standard)
256-
* and [PHP CS Fixer](https://tomasvotruba.com/blog/2018/06/07/how-to-migrate-from-php-cs-fixer-to-easy-coding-standard).
17+
Please make sure `composer lint` and `composer test` pass before sending a pull request.

0 commit comments

Comments
 (0)