Skip to content

Commit

Permalink
Merge branch 'master' into swift2.3
Browse files Browse the repository at this point in the history
* master: (27 commits)
  Change `included` to `include`
  Update formatting
  fixup changelog entry from #789
  add fix to CHANGELOG.md
  fix Mark rule case `// MARK: -`
  Update CHANGELOG
  Add unit test for issue #786
  Fix #786: Private unit test rule not scoped to tests
  clarify that vertical_whitespace is on by default again
  fix for verticalspace regex bug
  fix setterAccesiblity typo
  Adding new configuration for private outlet rules to allow private(set)
  Add redundant nil coalesing operator rule
  release 0.12.0
  make Vertical Whitespace rule opt-in
  move changelog entry to appropriate section
  Release 0.11.2
  Fix long lines and unit test
  Fixed returns doc for init methods issue-557
  Move CHANGELOG item to Breaking
  ...
  • Loading branch information
norio-nomura committed Sep 1, 2016
2 parents 905564e + 36b7955 commit a5082fb
Show file tree
Hide file tree
Showing 22 changed files with 520 additions and 64 deletions.
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,59 @@

##### Enhancements

* Add `RedundantNilCoalesingRule` Opt-In rule that warns against `?? nil`.
[Daniel Beard](https://github.com/daniel-beard)
[#764](https://github.com/realm/SwiftLint/issues/764)

* Adds `allow_private_set` configuration for the `private_outlet` rule.
[Rohan Dhaimade](https://github.com/HaloZero)

##### Bug Fixes

* Fixed regex bug in Vertical Whitespace Rule by using SourceKitten instead.
The rule now enabled by default again (no longer opt-in).
[J. Cheyo Jimenez](https://github.com/masters3d)
[#772](https://github.com/realm/SwiftLint/issues/772)

* Fixed regex bug in Mark Rule where MARK could not be used with only a hyphen
but no descriptive text: `// MARK: -`.
[Ruotger Deecke](https://github.com/roddi)
[#778](https://github.com/realm/SwiftLint/issues/778)

* Fixed: Private unit test rule not scoped to test classes.
Fixed: Private unit test rule config is ignored if regex is missing.
[Cristian Filipov](https://github.com/cfilipov)
[#786](https://github.com/realm/SwiftLint/issues/786)

## 0.12.0: Vertical Laundry

##### Breaking

* Fixed: SwiftLint assumes paths in the YAML config file are relative to the
current directory even when `--path` is passed as an argument.
[Cristian Filipov](https://github.com/cfilipov)

##### Enhancements

* None.

##### Bug Fixes

* Made Vertical Whitespace Rule added in 0.11.2 opt-in due to performance
issues.
[JP Simard](https://github.com/jpsim)
[#772](https://github.com/realm/SwiftLint/issues/772)

## 0.11.2: Communal Clothesline

This release has seen a phenomenal uptake in community contributions!

##### Breaking

* None.

##### Enhancements

* Add `MarkRule` rule to enforce `// MARK` syntax.
[Krzysztof Rodak](https://github.com/krodak)
[#749](https://github.com/realm/SwiftLint/issues/749)
Expand Down Expand Up @@ -44,12 +97,20 @@
[bootstraponline](https://github.com/bootstraponline)
[#689](https://github.com/realm/SwiftLint/issues/689)

* Add rule to check for private unit tests (private unit tests don't get run
by XCTest).
[Cristian Filipov](https://github.com/cfilipov)

* Add configuration for setting a warning threshold.
[woodhamgh](https://github.com/woodhamgh)
[696](https://github.com/realm/SwiftLint/issues/696)

* Adds 'ConditionalReturnsOnNewLineRule' rule.
[Rohan Dhaimade](https://github.com/HaloZero)

* Made `- returns:` doc optional for initializers.
[Mohpor](https://github.com/mohpor)
[#557](https://github.com/realm/SwiftLint/issues/557)

##### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ following syntax:
```yaml
custom_rules:
pirates_beat_ninjas: # rule identifier
included: "*.swift" # regex that defines paths to include during linting. optional.
include: "*.swift" # regex that defines paths to include during linting. optional.
name: "Pirates Beat Ninjas" # rule name. optional.
regex: "([n,N]inja)" # matching pattern
match_kinds: # SyntaxKinds to match. optional.
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Extensions/File+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extension File {

internal func matchPattern(regex: NSRegularExpression) -> [(NSRange, [SyntaxKind])] {
return rangesAndTokensMatching(regex).map { range, tokens in
(range, tokens.map({ $0.type }).flatMap(SyntaxKind.init))
(range, tokens.flatMap { SyntaxKind(rawValue: $0.type) })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import Foundation

extension NSFileManager {
internal func filesToLintAtPath(path: String) -> [String] {
let absolutePath = path.absolutePathStandardized()
internal func filesToLintAtPath(path: String, rootDirectory: String? = nil) -> [String] {
let rootPath = rootDirectory ?? NSFileManager.defaultManager().currentDirectoryPath
let absolutePath = (path.absolutePathRepresentation(rootPath) as NSString)
.stringByStandardizingPath
var isDirectory: ObjCBool = false
guard fileExistsAtPath(absolutePath, isDirectory: &isDirectory) else {
return []
Expand Down
8 changes: 6 additions & 2 deletions Source/SwiftLintFramework/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@ public struct Configuration: Equatable {
public func lintablePathsForPath(path: String,
fileManager: NSFileManager = fileManager) -> [String] {
let pathsForPath = included.isEmpty ? fileManager.filesToLintAtPath(path) : []
let excludedPaths = excluded.flatMap(fileManager.filesToLintAtPath)
let includedPaths = included.flatMap(fileManager.filesToLintAtPath)
let excludedPaths = excluded.flatMap {
fileManager.filesToLintAtPath($0, rootDirectory: self.rootPath)
}
let includedPaths = included.flatMap {
fileManager.filesToLintAtPath($0, rootDirectory: self.rootPath)
}
return (pathsForPath + includedPaths).filter({ !excludedPaths.contains($0) })
}

Expand Down
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Models/MasterRuleList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public let masterRuleList = RuleList(rules:
OpeningBraceRule.self,
OperatorFunctionWhitespaceRule.self,
PrivateOutletRule.self,
PrivateUnitTestRule.self,
RedundantNilCoalesingRule.self,
ReturnArrowWhitespaceRule.self,
StatementPositionRule.self,
TodoRule.self,
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Rules/ColonRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public struct ColonRule: CorrectableRule, ConfigurationProviderRule {
let nsstring = file.contents as NSString
let commentAndStringKindsSet = Set(SyntaxKind.commentAndStringKinds())
return file.rangesAndTokensMatching(pattern).filter { range, syntaxTokens in
let syntaxKinds = syntaxTokens.map({ $0.type }).flatMap(SyntaxKind.init)
let syntaxKinds = syntaxTokens.flatMap { SyntaxKind(rawValue: $0.type) }
if !syntaxKinds.startsWith([.Identifier, .Typeidentifier]) {
return false
}
Expand Down
5 changes: 3 additions & 2 deletions Source/SwiftLintFramework/Rules/MarkRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public struct MarkRule: ConfigurationProviderRule {
description: "MARK comment should be in valid format.",
nonTriggeringExamples: [
"// MARK: good\n",
"// MARK: - good\n"
"// MARK: - good\n",
"// MARK: -\n"
],
triggeringExamples: [
"//MARK: bad",
Expand All @@ -32,7 +33,7 @@ public struct MarkRule: ConfigurationProviderRule {
)

public func validateFile(file: File) -> [StyleViolation] {
let options = ["MARK:[^ ]", "[^ ]MARK: [^-]", "\\sMARK:[^ ]", "MARK:[ ][-][^ ]"]
let options = ["MARK:[^ ]", "[^ ]MARK: [^-]", "\\sMARK:[^ ]", "MARK:[ ][-][^\\s ]"]
let pattern = "(" + options.joinWithSeparator("|") + ")"

return file.matchPattern(pattern, withSyntaxKinds: [.Comment]).flatMap { range in
Expand Down
29 changes: 19 additions & 10 deletions Source/SwiftLintFramework/Rules/MissingDocsRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension File {
guard let _ = (dictionary["key.kind"] as? String).flatMap(SwiftDeclarationKind.init),
offset = dictionary["key.offset"] as? Int64,
accessibility = dictionary["key.accessibility"] as? String
where acl.map({ $0.sourcekitValue() }).contains(accessibility) else {
where acl.map({ $0.rawValue }).contains(accessibility) else {
return substructureOffsets
}
if getDocumentationCommentBody(dictionary, syntaxMap: syntaxMap) != nil {
Expand All @@ -53,16 +53,25 @@ extension File {
}
}

public enum AccessControlLevel: String {
case Private = "private"
case Internal = "internal"
case Public = "public"
public enum AccessControlLevel: String, CustomStringConvertible {
case Private = "source.lang.swift.accessibility.private"
case Internal = "source.lang.swift.accessibility.internal"
case Public = "source.lang.swift.accessibility.public"

private func sourcekitValue() -> String {
internal init?(description value: String) {
switch value {
case "private": self = .Private
case "internal": self = .Internal
case "public": self = .Public
default: return nil
}
}

public var description: String {
switch self {
case Private: return "source.lang.swift.accessibility.private"
case Internal: return "source.lang.swift.accessibility.internal"
case Public: return "source.lang.swift.accessibility.public"
case Private: return "private"
case Internal: return "internal"
case Public: return "public"
}
}
}
Expand All @@ -72,7 +81,7 @@ public struct MissingDocsRule: OptInRule {
guard let array = [String].arrayOf(configuration) else {
throw ConfigurationError.UnknownConfiguration
}
let acl = array.flatMap(AccessControlLevel.init)
let acl = array.flatMap(AccessControlLevel.init(description:))
parameters = zip([.Warning, .Error], acl).map(RuleParameter<AccessControlLevel>.init)
}

Expand Down
11 changes: 8 additions & 3 deletions Source/SwiftLintFramework/Rules/PrivateOutletRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import SourceKittenFramework

public struct PrivateOutletRule: ASTRule, OptInRule, ConfigurationProviderRule {
public var configuration = SeverityConfiguration(.Warning)
public var configuration = PrivateOutletRuleConfiguration(allowPrivateSet: false)

public init() {}

Expand Down Expand Up @@ -47,8 +47,13 @@ public struct PrivateOutletRule: ASTRule, OptInRule, ConfigurationProviderRule {

// Check if private
let accessibility = (dictionary["key.accessibility"] as? String) ?? ""
let setterAccessiblity = (dictionary["key.setter_accessibility"] as? String) ?? ""
let isPrivate = accessibility == "source.lang.swift.accessibility.private"
guard !isPrivate else { return [] }
let isPrivateSet = setterAccessiblity == "source.lang.swift.accessibility.private"

if isPrivate || (self.configuration.allowPrivateSet && isPrivateSet) {
return []
}

// Violation found!
let location: Location
Expand All @@ -60,7 +65,7 @@ public struct PrivateOutletRule: ASTRule, OptInRule, ConfigurationProviderRule {

return [
StyleViolation(ruleDescription: self.dynamicType.description,
severity: configuration.severity,
severity: configuration.severityConfiguration.severity,
location: location
)
]
Expand Down
Loading

0 comments on commit a5082fb

Please sign in to comment.