-
Notifications
You must be signed in to change notification settings - Fork 11
Add upgrade howto #58
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Upgrading from 2.x to 3.0 | ||
|
||
The main backward compatibility break in lmc/coding-standard version 3.0 is new PHP format used for | ||
code-style configuration. However, the changes are mostly "mechanical" and most of them can be automated. | ||
|
||
### 1. Update dependency in composer.json | ||
In require-dev section change the version constraint: | ||
|
||
```diff | ||
- "lmc/coding-standard": "^2.1", | ||
+ "lmc/coding-standard": "^3.0", | ||
``` | ||
|
||
Then run `composer update`. | ||
|
||
### 2. Change your easy-coding-standard.yaml | ||
Remove import section (otherwise the migration in step 3. won't work): | ||
```diff | ||
-imports: | ||
- - { resource: 'vendor/lmc/coding-standard/easy-coding-standard.yaml' } | ||
``` | ||
|
||
### 3. Automatically migrate config from `easy-coding-standard.yaml` to `ecs.php` | ||
Run following commands: | ||
|
||
```sh | ||
composer require symplify/config-transformer --dev | ||
vendor/bin/config-transformer switch-format easy-coding-standard.yaml --input-format yaml --output-format php | ||
mv easy-coding-standard.php ecs.php # rename to ecs.php | ||
composer remove symplify/config-transformer --dev # the migration tool can now be removed again | ||
``` | ||
|
||
### 4. Add import of the base `ecs.php` from lmc/coding-standard | ||
|
||
Because of the nature of how ECS process the configuration (which is, in fact, the behavior of underlying | ||
symfony/dependency-injection), you must follow the order in which you add your customizations. | ||
|
||
In your `ecs.php` add import of the lmc/coding-standard **after** you add `skip` parameter but **before** your custom code-style ajdustements: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo in |
||
|
||
```diff | ||
// ... | ||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$parameters = $containerConfigurator->parameters(); | ||
|
||
// Your skips - excluding fixers of paths must be placed BEFORE the import | ||
$parameters = $containerConfigurator->parameters(); | ||
$parameters->set(Option::SKIP, [__DIR__ . '/foo/bar']); | ||
|
||
+ $containerConfigurator->import(__DIR__. '/vendor/lmc/coding-standard/ecs.php'); | ||
|
||
// Your code style customizations and overrides of the default code-style must be placed AFTER the import | ||
$services->set(PhpUnitExpectationFixer::class) | ||
->call('configure', [['target' => '5.6']]); | ||
}; | ||
``` | ||
|
||
### 5. Configuration updates | ||
|
||
There are also few changes in configuration properties. The most notable is `skip` parameter, | ||
which is used for all path and sniff exclusions. So values from previous `skip`, `exclude_files` should all be merged into `skip`. | ||
|
||
```diff | ||
+use Symplify\EasyCodingStandard\ValueObject\Option; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$parameters = $containerConfigurator->parameters(); | ||
|
||
- $parameters->set('skip', [ForbiddenFunctionsSniff::class => ['src-tests/bootstrap.php']]); | ||
- $parameters->set('exclude_files', ['src/foo/bar.php']); | ||
+ $parameters->set(Option::SKIP, [ | ||
+ ForbiddenFunctionsSniff::class => ['src-tests/bootstrap.php'], | ||
+ 'src/foo/bar.php', | ||
+ ] | ||
+ ); | ||
|
||
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php'); | ||
}; | ||
|
||
``` | ||
|
||
See [ECS documentation](https://github.com/symplify/easy-coding-standard/tree/master#configuration) for more configuration options. | ||
|
||
### 6. Sanity check | ||
Besides running your code style checks, you can ensure all predefined LMC checks are loaded as well, by running: | ||
|
||
```sh | ||
vendor/bin/ecs show | ||
``` | ||
|
||
The result should end with something like: | ||
``` | ||
[OK] Loaded 164 checkers in total | ||
``` | ||
|
||
(or some close number, depending on your custom code-style settings). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use it already until the 3.0 version is actually released, one must obviously use branch constrain (
dev-feature/ecs-9
etc.)