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

PSR2/UseDeclaration: simplify the fix #1

Merged

Conversation

jrfnl
Copy link

@jrfnl jrfnl commented Feb 16, 2018

Based on a review of upstream PR squizlabs#1893, please find this as an optional suggestion for simplifying the logic a little.

All unit tests - including the new ones - still pass with this change included.
Added one more unit test case which looked like it wasn't covered yet.

@jrfnl jrfnl force-pushed the feature/test-is-bs-simplification branch 2 times, most recently from 99a42f5 to e35e559 Compare February 16, 2018 06:31
// Find either the start of the next line or the beginning of the next statement,
// whichever comes first.
for ($end = ++$end; $end < $phpcsFile->numTokens; $end++) {
if (isset(Tokens::$emptyTokens[$tokens[$end]['code']]) === false) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like some of the tokens in Tokens::$emptyTokens shouldn't be allowed: I think that only inline comments should be allowed and multi-line comments shouldn't be: https://github.com/dhensby/PHP_CodeSniffer/blob/master/src/Util/Tokens.php#L435

I don't think stuff like this should pass...

use Foo\Bar; /*
 * This multi-line comment shouldn't be allowed here.
 */

So, this sniff should build and use an array of $inlineCommentTokens.

@jrfnl @dhensby Do you agree?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think stuff like this should pass...

Have you tested it ? Not sure about previously, but this will definitely throw an error with the code I submitted.

Though I have to admit, I think the fixer will fail on it. I'll add an additional unit test for that and have a go at getting the fixer sorted.

So, this sniff should build and use an array of $inlineCommentTokens.
@jrfnl @dhensby Do you agree?

No. Multi-line block comments are tokenized as T_COMMENT as well, so that wouldn't solve anything.

Copy link

@iammattcoleman iammattcoleman Feb 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrfnl I'll admit I didn't test it. Sorry! I hadn't realized there isn't a separate token for inline comments.

@jrfnl jrfnl force-pushed the feature/test-is-bs-simplification branch from e35e559 to fd8050f Compare February 17, 2018 21:23
@jrfnl
Copy link
Author

jrfnl commented Feb 17, 2018

@iammattcoleman @dhensby I've updated the PR with yet more unit tests and an additional fix to allow the fixer to function correctly for:

  • multi-line block comments
  • when a trailing comment is encountered and another - stand-alone - comment is encountered on the next line.

Copy link

@iammattcoleman iammattcoleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 🍍

@jrfnl jrfnl force-pushed the feature/test-is-bs-simplification branch from fd8050f to 1530543 Compare February 17, 2018 23:33
@dhensby dhensby merged commit 5d58565 into dhensby:pulls/test-is-bs Feb 18, 2018
@jrfnl jrfnl deleted the feature/test-is-bs-simplification branch February 18, 2018 01:47
dhensby pushed a commit that referenced this pull request Aug 5, 2018
DisallowAlternativePHPTags: remove pre-PHP 5.4 work-around
dhensby pushed a commit that referenced this pull request Aug 16, 2018
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

Successfully merging this pull request may close these issues.

3 participants