New in Symplify 3: 4 Improvements in EasyCodingStandard

This post was updated on December 2018
Updated with EasyCodingStandard 5, Neon to YAML migration and new simplified skip parameter syntax.

What is new in Easy Coding Standard 3? Nice diffs for fixable sniffs, smart excluding, support for sniff warnings and one more...

1. Exclude Files or Dirs

Do you have src/Migrations that you need to skip from your vendor/bin/ecs check src command?

# ecs.yml
parameters:
    exclude_files:
        - 'src/Migrations/LastMigration.php'
        # or better all files from the dir
        - '*src/Migrations/*.php'

With favorite fnmatch() function on board.

2. Warnings are Reported for Specific Sniffs

  Check the PR #481

Sniff warnings are skipped by default, because it doesn't make sense to differentiate errors vs warnings. Yet some official Sniffs only produce warnings and that made them useless. Like PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\CommentedOutCodeSniff.

That changed. New property $reportWarningsSniffs in Symplify\EasyCodingStandard\SniffRunner\File\File now lists all sniffs, that report warnings in ECS as well.

Do you miss useful Sniff that reports only warnings? Send PR to add it.

3. Nice and Clear Diff over Boring Table Report

  Check the PR #474

Inspired by PHP CS Fixer we've decided to use files diffs everywhere wherever it saves user daunting reading.

When a fixable sniff found an error, ECS reported it like this:

 ------ --------------------------------------------------------------------------------------------
  Line   src/Posts/Year2017/Ast/SomeClass.php
 ------ --------------------------------------------------------------------------------------------
  10     Property $someProperty should use doc block instead of one liner
         (SomeSniff)

But why bother with such detailed text information, if the ECS will fix it to better form anyway?

From now on, it is reported the PHP CS Fixer-way like all the fixers:

@@ -1,14 +1,13 @@
 final class SomeClass
 {
+    /**
+     * @var SomeType
+     */
-    /** @var SomeType */
     private $someProperty;
 }

    ----------- end diff -----------

Applied checkers:

 - SomeSniff

Which one do you prefer?

4. Skip Sniff Codes instead of Whole Sniffs

  Check the PR #388

If you wanted to skip specific part of sniff, you had to exclude whole sniff via exclude_checkers option:

# ecs.yml
parameters:
    exclude_checkers:
        # to skip ".UselessDocComment"
        - 'SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff'

But what if you liked all the other codes? Now you can:

# ecs.yml
parameters:
    skip:
        SomeScalarSniff.SpecificCode: ~

And all the other codes will be checked properly in your code.


  Check the PR #406

@ostrolucky took this feature even further and added skipping by list of files or fnmatch.

 # ecs.yml
 parameters:
     skip:
-        SomeScalarSniff.SpecificCode: ~
+        SomeScalarSniff.SpecificCode:
+            - '*src/Form/Type/*Type.php'

Hope you like the changes and thanks the people who push these tools further by every single PR or issue report!


Happy code fixing!


Found a typo? Fix it to join team of 73 people that improve content here

❤️️ Do you find value in topics what I write about?
Support my writing by throwing a couple bucks at my Patreon