7 New Features in Easy Coding Standard 2.2

After extensive cooperation with David Grudl on Nette\CodingStandard EasyCodingStandard got new features, that moved the project to completely new level of comfort.


Prepared configs, reduction of config to few lines, --config option and more.

Huge thanks to David Grudl who gave me the feedback, ideas and Windows bug fixes while working on Nette\CodingStandard package. I'll write "how to" for Nette\CodingStandard later, but today we'll look on new features it uses from EasyCodingStandard 2.2.

1. Shorter Bin

Are you tired of tyops in vendor/bin/easy-coding-standard?

Now you can use ecs bin instead:

vendor/bin/ecs

2. Prepared Configs

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 9 prepared configs.

PHP_CodeSniffer + PHP-CS-Fixer

vendor/symplify/easy-coding-standard/config/php54-checkers.neon
vendor/symplify/easy-coding-standard/config/php70-checkers.neon
vendor/symplify/easy-coding-standard/config/php71-checkers.neon
vendor/symplify/easy-coding-standard/config/psr2-checkers.neon
vendor/symplify/easy-coding-standard/config/symfony-checkers.neon
vendor/symplify/easy-coding-standard/config/symfony-risky-checkers.neon

Custom

vendor/symplify/easy-coding-standard/config/symplify.neon
vendor/symplify/easy-coding-standard/config/spaces.neon
vendor/symplify/easy-coding-standard/config/common.neon

This shortened Symplify config from 256 lines to just 22 lines.

3. Use Whole Set But 1 Checker

I like Symfony set from PHP-CS-Fixer, but I'd like to remove 4 checkers. Do I have to put all checkers I want to use explicitly to the config?

Not anymore!

Use the set and exclude unwanted checkers in exclude_checkers option:

includes:
    - vendor/symplify/easy-coding-standard/config/symfony-checkers.neon

parameters:
    exclude_checkers:
        # from PHP-CS-Fixer Symfony set
        - PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer
        - PhpCsFixer\Fixer\Operator\NewWithBracesFixer
        - PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer
        - PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer

4. Skip More Than 1 File For Specific Checker

If you need to skip more files, just use fnmatch pattern in skip section.

parameters:
    skip:
        SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff:
            - "*packages/CodingStandard/src/Sniffs/*/*Sniff.php"

5. New Command Show Display Used Checkers

Do you know, what checkers do you use?

vendor/bin/ecs show

Or what checkers are in particular config?

vendor/bin/ecs show --config vendor/nette/coding-standard/coding-standard-php71.neon

This is rather debug or info tool, but it might come handy.

You can find more options of this command in README.

6. Scan *.php and *.phpt Files

EasyCodingStandard checks only *.php files by default. But what if you want to check *.phpt as well as in case of Nette\CodingStandard?

To add files with another suffixes you need to add own source provider:

namespace App\Finder;

use IteratorAggregate;
use Nette\Utils\Finder;
use SplFileInfo;
use Symplify\EasyCodingStandard\Contract\Finder\CustomSourceProviderInterface;

final class PhpAndPhptFilesProvider implements CustomSourceProviderInterface
{
    /**
     * @param string[] $source
     */
    public function find(array $source): IteratorAggregate
    {
        # $source is "source" argument passed in CLI
        # inc CLI: "vendor/bin/ecs check /src" => here: ['/src']
        return Finder::find('*.php', '*.phpt')->in($source);
    }
}

And register it as a normal Symfony service:

# easy-coding-standard.neon
services:
    App\Finder\PhpAndPhptFilesProvider: ~

Explore README or SourceProvider in Nette\CodingStandard for more.

7. Are you Tabs Person?

You're welcomed:

parameters:
    indentation: tab # "spaces" by default


You can find these features in README with more detailed use examples.

Like it? Try It

If you find these 7 news useful, you can try EasyCodingStandard right now:

composer require symplify/easy-coding-standard
vendor/bin/ecs

Happy code-style checking!



What do you think?