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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ Rules blink runs natively, per source. Regenerate with `blink/bin/rule-counts.sh
| PHP-CS-Fixer | 282 | 282 | 100% |
| Symplify | 34 | 34 | 100% |
| PHP_CodeSniffer | 66 | 114 | 57% |
| slevomat | 28 | 132 | 21% |
| **total** | **410** | **562** | **72%** |
| slevomat | 37 | 132 | 28% |
| **total** | **419** | **562** | **74%** |
<!-- parity-counts:end -->
6 changes: 3 additions & 3 deletions blink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ those expectations can differ from upstream's `.inc.fixed`. Regenerate them with
| PHP_CodeSniffer | 66 | 114 | 57% |
| **total** | **382** | **430** | **88%** |

blink runs 416 rules in all, its own extras included.
blink runs 425 rules in all, its own extras included.
<!-- rule-counts:end -->

### slevomat sniffs
Expand All @@ -50,11 +50,11 @@ measured against every fixable slevomat sniff in `slevomat-fixable-sniffs.txt`
| Namespaces | 0 | 13 | 0% |
| Numbers | 0 | 1 | 0% |
| Operators | 4 | 4 | 100% |
| PHP | 0 | 9 | 0% |
| PHP | 9 | 9 | 100% |
| TypeHints | 0 | 15 | 0% |
| Variables | 0 | 1 | 0% |
| Whitespaces | 0 | 1 | 0% |
| **total** | **28** | **132** | **21%** |
| **total** | **37** | **132** | **28%** |
<!-- slevomat-counts:end -->

## Build
Expand Down
9 changes: 9 additions & 0 deletions blink/internal/fixer/rules/priorities.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,30 @@ var fixerPriority = map[string]int{
"AttributeAndTargetSpacingSniff": 0,
"AttributesOrderSniff": 0,
"DisallowAttributesJoiningSniff": 0,
"DisallowDirectMagicInvokeCallSniff": 0,
"DisallowEqualOperatorsSniff": 0,
"DisallowMultipleAttributesPerLineSniff": 0,
"DisallowTrailingCommaInCallSniff": 0,
"DisallowTrailingCommaInClosureUseSniff": 0,
"DisallowTrailingCommaInDeclarationSniff": 0,
"ForbiddenClassesSniff": 0,
"LogicalOperatorSpacingSniff": 0,
"MultiLineArrayEndBracketPlacementSniff": 0,
"NamedArgumentSpacingSniff": 0,
"NegationOperatorSpacingSniff": 0,
"ReferenceSpacingSniff": 0,
"RequireArrowFunctionSniff": 0,
"RequireAttributeAfterDocCommentSniff": 0,
"RequireCombinedAssignmentOperatorSniff": 0,
"RequireExplicitAssertionSniff": 0,
"RequireMultiLineCallSniff": 0,
"RequireNowdocSniff": 0,
"RequireSingleLineCallSniff": 0,
"RequireTrailingCommaInCallSniff": 0,
"RequireTrailingCommaInClosureUseSniff": 0,
"RequireTrailingCommaInDeclarationSniff": 0,
"SemicolonSpacingSniff": 0,
"ShortListSniff": 0,
"SingleLineArrayWhitespaceSniff": 0,
"SpaceAfterNotSniff": 0,
"ClassInstantiationSniff": 0,
Expand All @@ -137,6 +143,7 @@ var fixerPriority = map[string]int{
"SpreadOperatorSpacingSniff": 0,
"StaticClosureSniff": 0,
"TrailingArrayCommaSniff": 0,
"TypeCastSniff": 0,
"UnusedInheritedVariablePassedToClosureSniff": 0,
"UselessParameterDefaultValueSniff": 0,
"RequireStrictTypesSniff": 0,
Expand All @@ -150,6 +157,8 @@ var fixerPriority = map[string]int{
"PostStatementCommentSniff": 0,
"ClosingDeclarationCommentSniff": 0,
"DocCommentAlignmentSniff": 0,
"UselessParenthesesSniff": 0,
"UselessSemicolonSniff": 0,
// getPriority() is 0 upstream; raised to run before blank_line_after_opening_tag
// so blink reaches the same output in a single pass (PHP-CS-Fixer loops to fixpoint)
"LinebreakAfterOpeningTagFixer": 2,
Expand Down
9 changes: 9 additions & 0 deletions blink/internal/fixer/rules/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ func ConstructFixers() []fixer.Fixer {
SlevomatDisallowAttributesJoining{},
SlevomatDisallowMultipleAttributesPerLine{},
SlevomatRequireAttributeAfterDocComment{},
SlevomatDisallowDirectMagicInvokeCall{},
SlevomatForbiddenClasses{},
SlevomatReferenceSpacing{},
SlevomatRequireExplicitAssertion{},
SlevomatRequireNowdoc{},
SlevomatShortList{},
SlevomatTypeCast{},
SlevomatUselessParentheses{},
SlevomatUselessSemicolon{},
OperatorLinebreak{},
PhpdocSeparation{},
PhpdocToComment{},
Expand Down
41 changes: 39 additions & 2 deletions blink/internal/fixer/rules/slevomat.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,17 @@ func (f *slvFile) enclosingScope(i int) int {
func (f *slvFile) braceOwner(open int) int {
for j := open - 1; j >= 0; j-- {
t := f.toks[j]
if t.kind == token.Variable {
return -1
}
if t.kind == token.Punct {
switch t.orig {
case ")", "]", "}":
case ")", "]":
if t.closer >= 0 {
j = t.closer
continue
}
case ";", "{", "(", "[":
case ";", "{", "}", "(", "[", "->", "?->", "::", "=":
return -1
}
}
Expand All @@ -786,6 +789,40 @@ func (f *slvFile) braceOwner(open int) int {
return -1
}

// isTraitUseBlock tells the "{" of a trait use's block.
func (f *slvFile) isTraitUseBlock(open int) bool {
for j := open - 1; j >= 0; j-- {
switch {
case f.isEmpty(j), f.isName(j), f.is(j, ","):
continue
case f.isKeyword(j, "use"):
return true
}
return false
}
return false
}

// scopeCondition is PHP_CodeSniffer's scope_condition: it returns the owner of the brace at i: "use" for a
// trait use block, else the keyword braceOwner finds, or -1.
func (f *slvFile) scopeCondition(i int) int {
open := i
if f.is(i, "}") {
open = f.toks[i].closer
}
if open < 0 {
return -1
}
if f.isTraitUseBlock(open) {
for j := open - 1; j >= 0; j-- {
if f.isKeyword(j, "use") {
return j
}
}
}
return f.braceOwner(open)
}

// isClosure tells a closure's "function" from a named function's.
func (f *slvFile) isClosure(fn int) bool {
n := f.nextEffective(fn+1, len(f.toks))
Expand Down
Loading
Loading