Switched from deprecated --set
option to PHP config.
Switched from YAML to PHP configs in Symplify 9.
After extensive cooperation with David Grudl on Nette\CodingStandard ECS got new features with focus on developer experience. Smart experience.
Prepared configs, reduction of config to few lines, --config
option and more.
Today we'll look on new features it uses from ECS.
# before
vendor/bin/easy-coding-standard
# now
vendor/bin/ecs
Before you had to name all the checkers manually in your config. There was no PSR2 group nor Symfony like there is in other tools. Now you can pick from 10 prepared configs.
PHP_CodeSniffer + PHP CS Fixer
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::SYMPLIFY);
// ...
// explore the constants on `SetList` class
};
Imagine you love the PSR-12 set, except that 1 checker. Do you skip the set completely or copy all the rules manually except the one?
Not anymore!
use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SetList::PSR_12);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, [
// ignore 1 rule everywhere
UnaryOperatorSpacesFixer::class => null,
]);
};
Do you need to skip more files for 1 specific checker? Now you can fnmatch
pattern:
use SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff;
// ...
$parameters->set(Option::SKIP, [
TypeHintDeclarationSniff::class => [
'*packages/CodingStandard/src/Sniffs/*/*Sniff.php'
],
]);
Show
Display Used CheckersDo you know, what checkers do you use?
vendor/bin/ecs show
This is rather debug or info tool, but it might come handy.
You can find more options of this command in README.
*.php
and *.phpt
FilesEasyCodingStandard checks only *.php
files by default. But what if you want to check *.phpt
as well as in case of Nette\CodingStandard?
Use Option::FILE_EXTENSIONS
:
// ...
$parameters->set(Option::FILE_EXTENSIONS, ['php', 'phpt']);
There you go:
// ...
$parameters->set(Option::INDENTATION, Option::INDENTATION_TAB);
If you find these 7 news useful, try ECS right now.
Happy coding!
Do you learn from my contents or use open-souce packages like Rector every day?
Consider supporting it on GitHub Sponsors.
I'd really appreciate it!