djoos / Symfony-coding-standard

Development repository for the Symfony coding standard
MIT License
401 stars 102 forks source link

Bad indentation sniff on multiple array arguments #27

Closed soullivaneuh closed 7 years ago

soullivaneuh commented 9 years ago

With this code:

        $formMapper
            ->with('General')
                ->add('name')
                ->add('values', 'sonata_type_collection', [
                    'by_reference'      => false,
                    'mapped'            => true,
                ], [
                    'edit'              => 'inline',
                    'inline'            => 'table',
                    'link_parameters'   => ['context' => $context],
                ])
            ->end()
        ;

CS found an error on line with ], [:

Multi-line function call not indented correctly; expected 20 spaces but found 16

But I think this is wrong.

The only way to make phpcs happy is to make this following "correction":

        $formMapper
            ->with('General')
                ->add('name')
                ->add('values', 'sonata_type_collection', [
                    'by_reference'      => false,
                    'mapped'            => true,
                    ], [
                    'edit'              => 'inline',
                    'inline'            => 'table',
                    'link_parameters'   => ['context' => $context],
                    ])
            ->end()
        ;

But that makes no sense IMO.

soullivaneuh commented 8 years ago

bump.

Is that project still maintained?

djoos commented 8 years ago

Hi @Soullivaneuh,

this project is still maintained, however: it's pretty much on the backburner. Do submit a PR if you want the issue to get fixed sooner, otherwise it will be down to our availability - which is quite low due to other projects recently...

Hope this helps!

Kind regards, David

soullivaneuh commented 8 years ago

Please have a look: https://github.com/squizlabs/PHP_CodeSniffer/issues/751#issuecomment-151803697

Apparently, we have to override the sniffer.

gl3n commented 8 years ago

:+1:

I encounter the same issue.

@Soullivaneuh Did you find a solution ?

dlasserre commented 8 years ago

+1

wrossier commented 8 years ago

+1

baptistecosta commented 8 years ago

Same here! sans titre

capture

geekdevs commented 8 years ago

@djoos I am trying to dig into the project. Please advice how you run tests locally. I've installed ant and running through it, but it gives a bunch of errors like shown below. Please advice what I am missing.

phpcs:
     [exec] 
     [exec] FILE: ...-standard/Symfony2/Tests/Objects/ObjectInstantiationUnitTest.php
     [exec] ----------------------------------------------------------------------
     [exec] FOUND 2 ERRORS AFFECTING 1 LINE
     [exec] ----------------------------------------------------------------------
     [exec]  28 | ERROR | Each class must be in a namespace of at least one level
     [exec]     |       | (a top-level vendor name)
     [exec]  28 | ERROR | Class name
     [exec]     |       | "Symfony2_Tests_Objects_ObjectInstantiationUnitTest" is
     [exec]     |       | not in camel caps format
     [exec] ----------------------------------------------------------------------
     [exec] 
     [exec] 
     [exec] FILE: ...-standard/Symfony2/Tests/Objects/ObjectInstantiationUnitTest.inc
     [exec] ----------------------------------------------------------------------
     [exec] FOUND 9 ERRORS AFFECTING 7 LINES
     [exec] ----------------------------------------------------------------------
     [exec]   4 | ERROR | [ ] Use parentheses when instantiating classes
     [exec]   5 | ERROR | [ ] Use parentheses when instantiating classes
     [exec]   6 | ERROR | [ ] Use parentheses when instantiating classes
     [exec]   7 | ERROR | [ ] Use parentheses when instantiating classes
     [exec]   8 | ERROR | [ ] Use parentheses when instantiating classes
     [exec]   8 | ERROR | [x] Space before opening parenthesis of function call
     [exec]     |       |     prohibited
     [exec]   8 | ERROR | [x] Space before opening parenthesis of function call
     [exec]     |       |     prohibited
     [exec]   9 | ERROR | [ ] Use parentheses when instantiating classes
     [exec]  10 | ERROR | [ ] Use parentheses when instantiating classes
     [exec] ----------------------------------------------------------------------
     [exec] PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
     [exec] ----------------------------------------------------------------------
wickedOne commented 8 years ago

@geekdevs it looks like you're running phpcs correctly. the errors you're seeing are the actual code style violations. for instance

Each class must be in a namespace of at least one level (a top-level vendor name)

means that you probably have a class in your project which looks like

<?php

namespace Foo;

while the correct way contains a top level name like

<?php

namespace Foo/Bar;

and

Use parentheses when instantiating classes

probably means you got a

$foo = new Bar;

rather than a

$foo = new Bar();

etc. please have a look at the code sniffer end user documentation on how to use phpcs. hope this helps…

geekdevs commented 8 years ago

@wickedOne well the problem is that I am not testing my own project, but this one (escapestudios/Symfony2-coding-standard) with unit tests it has in the project. So either this project has a lot of violations or it runs tests somehow specifically, that's why I ask.

wickedOne commented 8 years ago

usually the sniffs themself have to comply to the PEAR coding standard as defined over here (not sure thought whether they actually do).

djoos commented 8 years ago

Hi @geekdevs,

the coding standard was not complying with the PEAR coding standard - I've fixed that now. Could you give master another go? Give me a shout if you experience any further issues.

Hope this helps! David

djoos commented 8 years ago

Back on topic: multiple array arguments!

djoos commented 8 years ago

Hi guys,

are you still experiencing this issue? Looking into it (squiz/labs_phpcodesniffer 931223073e116381e7d2e701ce31dfd59a2ec226) I can't replicate this issue at all...

Is this related to this fix https://github.com/squizlabs/PHP_CodeSniffer/issues/698#issuecomment-180609565?

I'll close the issue for now, but please don't hesitate to reopen if you are still experiencing it...

Kind regards, David

gl3n commented 8 years ago

I confirm I don't encounter the error anymore.

geekdevs commented 8 years ago

I don't think it's fixed. The following gives error:

        $resolver->setDefaults([
            'attr' => [
                'novalidate' => 'novalidate',
            ],
        ]);

Multi-line function call not indented correctly; expected 12 spaces but found 16 (PEAR.Functions.FunctionCallSignature.Indent)

wickedOne commented 7 years ago

i think this one can be closed as

<?php

    $resolver->setDefaults([
        'attr' => [
            'novalidate' => 'novalidate',
        ],
    ]);

doesn't raise an error anymore...

soullivaneuh commented 6 years ago

Sorry but this issue is not fixed @djoos

This:

    public function lintReport(): LintReport
    {
        /** @var \Traversable $lintServices */
        $lintServices = $this->lintServiceManager->getServices();
        $lintServiceCodes = \array_map(static function (ServiceInterface $service) {
            return $service->getCodeName();
        }, \array_filter(\iterator_to_array(
            $lintServices
        ), static function (ServiceInterface $service) {
            return $service instanceof LintServiceInterface;
        }));
        $report = new LintReport();

Is transformed to this:

    public function lintReport(): LintReport
    {
        /** @var \Traversable $lintServices */
        $lintServices = $this->lintServiceManager->getServices();
        $lintServiceCodes = \array_map(static function (ServiceInterface $service) {
            return $service->getCodeName();
            }, \array_filter(\iterator_to_array(
            $lintServices
        ), static function (ServiceInterface $service) {
                    return $service instanceof LintServiceInterface;
        }));
        $report = new LintReport();

And this cause conflicts with php-cs-fixer.