PHP-Parser icon indicating copy to clipboard operation
PHP-Parser copied to clipboard

Normalize comment classes

Open WinterSilence opened this issue 3 years ago • 7 comments

  • getReformattedText(): fix @return types, remove comment trimming to keep empty lines in comment at begin and end, optimize detection of multi-line comments
  • getShortestWhitespacePrefixLen(): replace float INF to PHP_INT_MAX
  • jsonSerialize(): update @psalm-return and remove redundant @return, fix nodeType

WinterSilence avatar Aug 07 '22 11:08 WinterSilence

Test failures are legitimate.

nikic avatar Aug 07 '22 14:08 nikic

@nikic yes, because

remove comment trimming to keep empty lines in comment at begin and end

If you agree with these changes, I'll update the tests

WinterSilence avatar Aug 07 '22 14:08 WinterSilence

The change to trimming is fine -- to verify, I've landed it separately as https://github.com/nikic/PHP-Parser/commit/1f504d2c7da6020d56144cdb8443a3ba681f6183. This was a leftover from an older implementation, when comments were expected to have a trailing newline.

It's some of the other changes that cause problematic changes in formatting.

nikic avatar Aug 07 '22 14:08 nikic

@nikic hm... I'm don't see how other changes can fail tests - content changed only here

WinterSilence avatar Aug 07 '22 14:08 WinterSilence

@nikic tests failed because startLine/endLine not correct in current test: $this->startLine === $this->endLine always return true because by default they set as -1 i.e. -1=-1

WinterSilence avatar Aug 07 '22 17:08 WinterSilence

@nikic I'm fixed fake/incorrect data passing to CommentTest tests, but I'm think other failed tests must be fixes in other PR's.

WinterSilence avatar Aug 10 '22 09:08 WinterSilence

@nikic added alternative check to test instances:

|| ($this->endLine === -1 && strpos($this->text, "\n") !== false)

WinterSilence avatar Sep 13 '22 22:09 WinterSilence