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=0.3
MAX_DIFF_PERCENT=0.25
total=0
differ=0
differing_files=""
Expand Down
10 changes: 9 additions & 1 deletion blink/internal/fixer/rules/constructs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions blink/internal/fixer/rules/constructs_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ func TestConstructsConfigCases(t *testing.T) {
{"followed default", SingleSpaceAroundConstruct{}, "<?php if($a){return 1;}", "<?php if ($a){return 1;}"},
{"followed list", SingleSpaceAroundConstruct{}.WithConfig(map[string]any{"constructs_followed_by_a_single_space": []any{"return"}}).(fixerRule), "<?php if($a){return 1;}", "<?php if($a){return 1;}"},
{"preceded", SingleSpaceAroundConstruct{}.WithConfig(map[string]any{"constructs_preceded_by_a_single_space": []any{"else"}}).(fixerRule), "<?php if ($a) {}else {}", "<?php if ($a) {} else {}"},
{"preceded joins block comment before elseif", SingleSpaceAroundConstruct{}.WithConfig(map[string]any{"constructs_preceded_by_a_single_space": []any{"elseif"}}).(fixerRule), "<?php if ($a) {\n}\n/* note */\nelseif ($b) {\n}", "<?php if ($a) {\n}\n/* note */ elseif ($b) {\n}"},
{"preceded keeps line comment before else", SingleSpaceAroundConstruct{}.WithConfig(map[string]any{"constructs_preceded_by_a_single_space": []any{"else"}}).(fixerRule), "<?php if ($a) {\n}\n// note\nelse {\n}", "<?php if ($a) {\n}\n// note\nelse {\n}"},
{"yield from", SingleSpaceAroundConstruct{}.WithConfig(map[string]any{"constructs_contain_a_single_space": []any{"yield_from"}}).(fixerRule), "<?php function f() { yield from $a; }", "<?php function f() { yield from $a; }"},
{"parens default none", NoSpacesInsideParenthesis{}, "<?php foo( $a );", "<?php foo($a);"},
{"parens single", NoSpacesInsideParenthesis{}.WithConfig(map[string]any{"space": "single"}).(fixerRule), "<?php foo($a, bar());", "<?php foo( $a, bar() );"},
Expand Down
9 changes: 9 additions & 0 deletions blink/internal/fixer/rules/gen_arrays.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ func commentAt(s *tokens.Stream, i int) bool {
return i >= 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
Expand Down
Loading