Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/blink_parity_mautic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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=1.0
MAX_DIFF_PERCENT=0.8
total=0
differ=0
differing_files=""
Expand Down
16 changes: 12 additions & 4 deletions blink/internal/fixer/rules/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,18 @@ func (SingleLineAfterImports) Fix(s *tokens.Stream) bool {
if next.Kind == token.Punct && next.Value == "}" {
continue
}
if s.At(semi+1).Kind == token.Whitespace &&
hasNewline(s.At(semi+1).Value) && s.At(semi+1).Value != "\n\n" {
s.SetValue(semi+1, "\n\n")
changed = true
ws := s.At(semi + 1)
if ws.Kind == token.Whitespace && hasNewline(ws.Value) {
// preserve the import line's own indentation after the blank line, so a
// braced-namespace body keeps its level; a whitespace that already holds
// exactly one blank line (two newlines) is left untouched, as php-cs-fixer
if strings.Count(ws.Value, "\n") != 2 {
target := "\n\n" + indentBefore(s, i)
if ws.Value != target {
s.SetValue(semi+1, target)
changed = true
}
}
}
}
return changed
Expand Down
11 changes: 11 additions & 0 deletions blink/internal/fixer/rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,17 @@ func TestSingleLineAfterImports(t *testing.T) {
if want := "<?php\nuse A;\nuse B;\n\nclass C {}"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
}

// inside a braced namespace the following line keeps its indentation
got, changed = apply(t, SingleLineAfterImports{}, "<?php\nnamespace N {\n use A;\n class C {}\n}")
if want := "<?php\nnamespace N {\n use A;\n\n class C {}\n}"; !changed || got != want {
t.Fatalf("braced: changed=%v got=%q want=%q", changed, got, want)
}

// a blank line that already exists is left untouched
if _, changed := apply(t, SingleLineAfterImports{}, "<?php\nnamespace N {\n use A;\n\n class C {}\n}"); changed {
t.Fatal("existing blank line after import must be a no-op")
}
}

func TestNoTrailingWhitespace(t *testing.T) {
Expand Down
Loading