Skip to content

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 1 commit into from
Feb 9, 2021
Merged
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
95 changes: 95 additions & 0 deletions UPGRADE-3.0.md
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",
Copy link
Contributor Author

@OndraM OndraM Feb 8, 2021

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.)

```

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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in ajdustements


```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).