Skip to content
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

Merged
merged 3 commits into from
Nov 29, 2016
Merged

Add autocorrection to MarkRule #893

merged 3 commits into from
Nov 29, 2016

Conversation

kohtenko
Copy link
Contributor

This pull request about adding autocorrect functionality to newly added MarkRule, in order to make updating code even simpler.

1

@codecov-io
Copy link

codecov-io commented Nov 25, 2016

Current coverage is 86.27% (diff: 100%)

Merging #893 into master will increase coverage by 0.17%

@@             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          

Powered by Codecov. Last update e63c6ce...57d8ece

Copy link
Collaborator

@jpsim jpsim left a 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 {
]
Copy link
Collaborator

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 {
Copy link
Collaborator

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] {
Copy link
Collaborator

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
Copy link
Collaborator

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private?

@kohtenko
Copy link
Contributor Author

Good points, all fixed

Copy link
Collaborator

@jpsim jpsim left a 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.

@jpsim jpsim merged commit 9900513 into realm:master Nov 29, 2016
jpsim added a commit that referenced this pull request Nov 29, 2016
@jpsim jpsim mentioned this pull request Nov 29, 2016
jpsim added a commit that referenced this pull request Nov 29, 2016
norio-nomura added a commit that referenced this pull request Nov 30, 2016
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants