Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS not enforcing space after parenthesis when args span multiple lines #76

Open
mattheu opened this issue Aug 13, 2018 · 4 comments
Open

Comments

@mattheu
Copy link
Member

mattheu commented Aug 13, 2018

The following code is NOT flagged as an error, but I would expect it to be. Note missing space after the first (.

get_extended_template_part('atoms/heading', '4', [
	'heading_three' => 'This is a heading 3',
] );

However it is correctly enforced if the args are on a single line. e.g.

get_extended_template_part('atoms/heading', '4', [ 'heading_three' => 'This is a heading 3' ] );
@mattheu
Copy link
Member Author

mattheu commented Aug 13, 2018

In addition PHPCBF fixes this to the following, which I don't think is quite correct - certainly not enforced by PHPCS

get_extended_template_part(
	'atoms/heading', '2', [
		'heading_two'  => 'This is a heading 2',
	]
);

Digging... There are a couple of related issues. Seems a combination of the fact that WPCS isn't enforcing proper multiline function calls, and that these checks are ignroed for PHPCS only and not PHPCBF.

We ran into this issue on the a different project too and ended up ignoring this sniff for PHPCBF.

<exclude phpcbf-only="true" name="PEAR.Functions.FunctionCallSignature"/>

@kadamwhite
Copy link
Contributor

Needs refresh to see whether this is still an issue.

@mikeselander
Copy link
Contributor

I can confirm that the original issue is still present.

@tfrommen
Copy link
Contributor

tfrommen commented Mar 2, 2021

Using the most recent version of the HM Coding Standards, this does get flagged, as expected.

To reproduce, execute the following in some empty folder:

  • echo '{}' > composer.json
  • composer require humanmade/coding-standards
  • echo -e "<?php\nprint('foo', [\n\t42,\n], 'bar');\n" > code.php
  • ./vendor/bin/phpcs --standard=HM code.php

This results in the following output:

----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
 1 | ERROR | [ ] Missing file doc comment
 2 | ERROR | [ ] PHP syntax error: syntax error, unexpected ','
 2 | ERROR | [x] Expected 1 space after open parenthesis; 0 found
 4 | ERROR | [x] Expected 1 space before close parenthesis; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Both the missing space right after the open parenthesis and the one right before the closing parenthesis get flagged.

Also, running phpcbf, results in the expected code:

<?php
-print('foo', [
+print( 'foo', [
        42,
-], 'bar');
+], 'bar' );

Can you confirm this, @mattheu? Can we close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants