7 New Features in Easy Coding Standard 2.2

This post is deprecated since December 2018
Now there is EasyCodingStandard 5, so this is rather 7 oldies.

This post was updated on November 2019
Updated with EasyCodingStandard 6, Neon → YAML, config import → sets parameters, checkersservices.

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:


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




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:

        - 'symfony'

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

            - '*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.yml

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
    App\Finder\PhpAndPhptFilesProvider: ~

Explore README or SourceProvider in Nette\CodingStandard for more.

7. Are you Tabs Person?

You're welcomed:

    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 --dev
vendor/bin/ecs check src --set psr12

Happy code-style checking!