-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from realm/jp-comment-commands
Disable/re-enable rules from within source code comments. Fixes #4.
- Loading branch information
Showing
10 changed files
with
170 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Command.swift | ||
// SwiftLint | ||
// | ||
// Created by JP Simard on 8/29/15. | ||
// Copyright © 2015 Realm. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum CommandAction: String { | ||
case Enable = "enable" | ||
case Disable = "disable" | ||
} | ||
|
||
public struct Command { | ||
let action: CommandAction | ||
let ruleIdentifier: String | ||
let line: Int | ||
let character: Int | ||
|
||
public init(action: CommandAction, ruleIdentifier: String, line: Int, character: Int) { | ||
self.action = action | ||
self.ruleIdentifier = ruleIdentifier | ||
self.line = line | ||
self.character = character | ||
} | ||
|
||
public init?(string: NSString, range: NSRange) { | ||
let scanner = NSScanner(string: string.substringWithRange(range)) | ||
scanner.scanString("swiftlint:", intoString: nil) | ||
var actionNSString: NSString? = nil | ||
scanner.scanUpToString(" ", intoString: &actionNSString) | ||
guard let actionString = actionNSString as String?, | ||
action = CommandAction(rawValue: actionString), | ||
lineAndCharacter = string.lineAndCharacterForByteOffset(NSMaxRange(range)) else { | ||
return nil | ||
} | ||
self.action = action | ||
let ruleStart = scanner.string.startIndex.advancedBy(scanner.scanLocation + 1) | ||
ruleIdentifier = scanner.string.substringFromIndex(ruleStart) | ||
line = lineAndCharacter.line | ||
character = lineAndCharacter.character | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Region.swift | ||
// SwiftLint | ||
// | ||
// Created by JP Simard on 8/29/15. | ||
// Copyright © 2015 Realm. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SourceKittenFramework | ||
|
||
public struct Region { | ||
let start: Location | ||
let end: Location | ||
let disabledRuleIdentifiers: Set<String> | ||
|
||
public init(start: Location, end: Location, disabledRuleIdentifiers: Set<String>) { | ||
self.start = start | ||
self.end = end | ||
self.disabledRuleIdentifiers = disabledRuleIdentifiers | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.