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

Space after brace and PSR-2 #347

Closed
Yumash opened this issue Dec 8, 2014 · 7 comments
Closed

Space after brace and PSR-2 #347

Yumash opened this issue Dec 8, 2014 · 7 comments

Comments

@Yumash
Copy link

Yumash commented Dec 8, 2014

Found a strange error in Jenkins
2014-12-08 11 27 40

phpcs --report=full --standard=PSR2 ChecklistController.php

FILE: ...jobs/2report_dev/workspace/frontend/controllers/ChecklistController.php
--------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 6 LINES
--------------------------------------------------------------------------------
...
 168 | ERROR | [x] Expected 1 space after closing brace; newline found

So i didn't found a word in PSR-2 about needing a space before newline. Maybe there's a bug that CS does not tract newline as a space?

@aik099
Copy link
Contributor

aik099 commented Dec 8, 2014

Could you please attach (maybe in gist form) complete file, because I suspect something around that code might be affecting the final shown error.

@Yumash
Copy link
Author

Yumash commented Dec 8, 2014

I pushed it here: https://github.com/Jumashev/test/blob/master/ChecklistController.php (no editing, just copied from one repo to another)

@gsherwood
Copy link
Member

Read this: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#51-if-elseif-else

Specifically this bit:

and that else and elseif are on the same line as the closing brace from the earlier body.

PSR-2 requires a single space between the closing brace of the IF and the ELSE keyword. You need to write it like this:

if (...) {
    // code here
} else {
  // code here
}

In your code, the else keyword is on the line following the brace, not on the same line, hence the error message mentioning that newline it found. Does this clear things up?

@Yumash
Copy link
Author

Yumash commented Dec 8, 2014

Feel ashamed, so sorry for inconvenience :)

But if i would like not to strictly follow the PSR-2 - is there any chance to add there some exclusions to CS like as for this case?

Thank you!

@aik099
Copy link
Contributor

aik099 commented Dec 8, 2014

@jumashev that's where custom rulesets comes in. In there you can extend existing standards by adding/removing/tuning their sniffs or even completely create own standard.

@Yumash
Copy link
Author

Yumash commented Dec 8, 2014

Great! Thank you!

@Yumash Yumash closed this as completed Dec 8, 2014
@gsherwood
Copy link
Member

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

No branches or pull requests

3 participants