diff --git a/.github/workflows/blink_parity_mautic.yaml b/.github/workflows/blink_parity_mautic.yaml index ef3e8f80e7..e84c4d7d96 100644 --- a/.github/workflows/blink_parity_mautic.yaml +++ b/.github/workflows/blink_parity_mautic.yaml @@ -95,7 +95,7 @@ jobs: - name: Compare the two trees run: | # ratchet gate: fail once the differing share crosses this; lower it as parity improves - MAX_DIFF_PERCENT=0.3 + MAX_DIFF_PERCENT=0.25 total=0 differ=0 differing_files="" diff --git a/blink/internal/fixer/rules/constructs.go b/blink/internal/fixer/rules/constructs.go index dde73cf984..1137602b12 100644 --- a/blink/internal/fixer/rules/constructs.go +++ b/blink/internal/fixer/rules/constructs.go @@ -134,7 +134,15 @@ func (f SingleSpaceAroundConstruct) fixPreceded(s *tokens.Stream) bool { } prev := s.At(i - 1) if prev.Kind == token.Whitespace { - if !hasNewline(prev.Value) && prev.Value != " " { + if !hasNewline(prev.Value) { + if prev.Value != " " { + s.SetValue(i-1, " ") + changed = true + } + } else if p := i - 2; p >= 0 && isBlockOrDocComment(s.At(p)) { + // a block/doc comment directly before the construct joins it onto the + // comment's closing line ("*/ elseif"); php-cs-fixer collapses the + // whitespace unless a "//"/"#" line comment precedes (code cannot follow) s.SetValue(i-1, " ") changed = true } diff --git a/blink/internal/fixer/rules/constructs_config_test.go b/blink/internal/fixer/rules/constructs_config_test.go index a4dca68ae7..9c4b29f878 100644 --- a/blink/internal/fixer/rules/constructs_config_test.go +++ b/blink/internal/fixer/rules/constructs_config_test.go @@ -12,6 +12,8 @@ func TestConstructsConfigCases(t *testing.T) { {"followed default", SingleSpaceAroundConstruct{}, "= 0 && i < s.Len() && isComment(s.At(i)) } +// isBlockOrDocComment reports whether t is a "/* */" block comment or a "/** */" +// doc comment (not a "//"/"#" line comment and not a "#[...]" attribute). +func isBlockOrDocComment(t token.Token) bool { + if t.Kind == token.DocComment { + return true + } + return t.Kind == token.Comment && strings.HasPrefix(t.Value, "/*") +} + func isLineComment(t token.Token) bool { if t.Kind != token.Comment { return false