-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add autocorrection to MarkRule #893
Conversation
Current coverage is 86.27% (diff: 100%)@@ master #893 diff @@
==========================================
Files 114 114
Lines 5058 5121 +63
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 4355 4418 +63
Misses 703 703
Partials 0 0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! This is definitely on the right track. Mostly just missing description.corrections
for test purposes and a changelog entry.
@@ -39,20 +39,112 @@ public struct MarkRule: ConfigurationProviderRule { | |||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add corrections
to this RuleDescription
to cover correctable test scenarios.
return "(\(mark) -\(nonSpace))" | ||
} | ||
|
||
private var pattern: String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested formatting:
private var pattern: String {
return [
spaceStartPattern,
endNonSpacePattern,
endTwoOrMoreSpacePattern,
twoOrMoreSpacesAfterHyphenPattern,
nonSpaceAfterHyphenPattern
].joinWithSeparator("|")
}
return corrections | ||
} | ||
|
||
private func violationRangesInFile(file: File, withPattern pattern: String) -> [NSRange] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested formatting:
private func violationRangesInFile(file: File, withPattern pattern: String) -> [NSRange] {
let nsstring = file.contents as NSString
return file.rangesAndTokensMatching(pattern).filter { range, syntaxTokens in
let syntaxKinds = syntaxTokens.flatMap { SyntaxKind(rawValue: $0.type) }
return syntaxKinds.startsWith([.Comment])
}.flatMap { range, syntaxTokens in
let identifierRange = nsstring
.byteRangeToNSRange(start: syntaxTokens[0].offset, length: 0)
return identifierRange.map { NSUnionRange($0, range) }
}
}
var corrections = [Correction]() | ||
for var range in matches.reverse() { | ||
if keepLastChar { | ||
range.length = range.length - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
range.length -= 1
?
return result | ||
} | ||
|
||
public func correctFile(file: File, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
?
Good points, all fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic! I have a few minor points of style, and this is missing a changelog entry, but I'll take care of those in another PR.
* commit 'e0cafea80ffba746a103d8d5a25be8fcd0993c81': remove unnecessary file.invalidateCache() add changelog entry for #893 fix up indentation in MarkRule.swift omit self if it can be inferred Corrections for mark rule Update regex part to be more precise. Add autocorrection to MarkRule # Conflicts: # Source/SwiftLintFramework/Rules/ConditionalReturnsOnNewline.swift # Source/SwiftLintFramework/Rules/MarkRule.swift # Source/SwiftLintFramework/Rules/StatementPositionRule.swift
This pull request about adding autocorrect functionality to newly added MarkRule, in order to make updating code even simpler.