Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Piñera committed Jul 1, 2017
1 parent 39cb38a commit a598969
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 57 deletions.
5 changes: 4 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ disabled_rules:
- trailing_whitespace
- nesting
- cyclomatic_complexity
- file_length
- file_length
line_length:
warning: 150
error: 170
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ language: generic
osx_image: xcode8
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
- brew upgrade swiftlint
- bundle install
script:
# - swiftlint lint --strict
- swift test
- bundle exec rake ci
after_success:
- bash <(curl -s https://codecov.io/bash)
16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ end

### TASKS ###

desc "Removes the build folder"
task :clean do
print "> Cleaning build/ folder"
`rm -rf build`
end

desc "Executes all the validation steps for CI"
task :ci => [:clean] do
print "> Linting project"
sh "swiftlint"
print "> Building the project"
sh "swift build"
print "> Executing tests"
sh "swift test"
end

desc "Bumps the version of xcodeprojlint. It creates a new tagged commit and archives the binary to be published with the release"
task :release => [:clean] do
abort '> Commit all your changes before starting the release' unless !any_git_changes?
Expand Down
4 changes: 2 additions & 2 deletions Sources/xcodeproj/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public struct BuildSettings {

extension BuildSettings: Equatable {

public static func ==(lhs: BuildSettings,
rhs: BuildSettings) -> Bool {
public static func == (lhs: BuildSettings,
rhs: BuildSettings) -> Bool {
return NSDictionary(dictionary: lhs.dictionary)
.isEqual(to: NSDictionary(dictionary: rhs.dictionary))
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/xcodeproj/PBXNativeTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ extension PBXNativeTarget: PBXProjPlistSerializable {
var dictionary: [PBXProjPlistCommentedString: PBXProjPlistValue] = [:]

dictionary["isa"] = .string(PBXProjPlistCommentedString(PBXNativeTarget.isa))
let buildConfigurationListComment = "Build configuration list for PBXNativeTarget \"\(name)\""
dictionary["buildConfigurationList"] = .string(PBXProjPlistCommentedString(PBXNativeTarget.isa,
comment: "Build configuration list for PBXNativeTarget \"\(name)\""))

comment: buildConfigurationListComment))
dictionary["buildPhases"] = .array(buildPhases
.map { buildPhase in
let comment: String? = buildPhaseType(from: buildPhase, proj: proj)
Expand All @@ -258,12 +258,12 @@ extension PBXNativeTarget: PBXProjPlistSerializable {
}

private func buildPhaseType(from reference: UUID, proj: PBXProj) -> String? {
let sources = proj.objects.sourcesBuildPhases.map{return $0.reference}
let frameworks = proj.objects.frameworksBuildPhases.map{return $0.reference}
let resources = proj.objects.resourcesBuildPhases.map{return $0.reference}
let copyFiles = proj.objects.copyFilesBuildPhases.map{return $0.reference}
let runScript = proj.objects.shellScriptBuildPhases.map{return $0.reference}
let headers = proj.objects.headersBuildPhases.map{return $0.reference}
let sources = proj.objects.sourcesBuildPhases.map {return $0.reference}
let frameworks = proj.objects.frameworksBuildPhases.map {return $0.reference}
let resources = proj.objects.resourcesBuildPhases.map {return $0.reference}
let copyFiles = proj.objects.copyFilesBuildPhases.map {return $0.reference}
let runScript = proj.objects.shellScriptBuildPhases.map {return $0.reference}
let headers = proj.objects.headersBuildPhases.map {return $0.reference}
if sources.contains(reference) {
return "Sources"
} else if frameworks.contains(reference) {
Expand All @@ -282,7 +282,7 @@ extension PBXNativeTarget: PBXProjPlistSerializable {

private func fileName(from reference: UUID, proj: PBXProj) -> String? {
return proj.objects.fileReferences
.filter{$0.reference == reference}
.filter {$0.reference == reference}
.flatMap { $0.path }
.first
}
Expand Down
1 change: 0 additions & 1 deletion Sources/xcodeproj/PBXProjWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ enum PBXProjPlistValue: ExpressibleByArrayLiteral, ExpressibleByDictionaryLitera
}
}


/// Protocol that defines that the element can return a plist element that represents itself.
protocol PBXProjPlistSerializable {
func pbxProjPlistElement(proj: PBXProj) -> (key: PBXProjPlistCommentedString, value: PBXProjPlistValue)
Expand Down
10 changes: 6 additions & 4 deletions Sources/xcodeproj/PBXProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ public struct PBXProject: ProjectElement, PBXProjPlistSerializable {
func pbxProjPlistElement(proj: PBXProj) -> (key: PBXProjPlistCommentedString, value: PBXProjPlistValue) {
var dictionary: [PBXProjPlistCommentedString: PBXProjPlistValue] = [:]
dictionary["isa"] = .string(PBXProjPlistCommentedString(PBXProject.isa))
dictionary["buildConfigurationList"] = .string(PBXProjPlistCommentedString(buildConfigurationList,
comment: "Build configuration list for PBXProject \"\(proj.name)\""))
let buildConfigurationListComment = "Build configuration list for PBXProject \"\(proj.name)\""
let buildConfigurationListCommentedString = PBXProjPlistCommentedString(buildConfigurationList,
comment: buildConfigurationListComment)
dictionary["buildConfigurationList"] = .string(buildConfigurationListCommentedString)
dictionary["compatibilityVersion"] = .string(PBXProjPlistCommentedString("\"\(compatibilityVersion)\""))
if let developmentRegion = developmentRegion {
dictionary["developmentRegion"] = .string(PBXProjPlistCommentedString(developmentRegion))
Expand All @@ -144,7 +146,7 @@ public struct PBXProject: ProjectElement, PBXProjPlistSerializable {
}
dictionary["knownRegions"] = PBXProjPlistValue.array(knownRegions
.map {.string(PBXProjPlistCommentedString("\($0)")) })

dictionary["mainGroup"] = .string(PBXProjPlistCommentedString(mainGroup))
if let productRefGroup = productRefGroup {
dictionary["productRefGroup"] = .string(PBXProjPlistCommentedString(productRefGroup,
Expand All @@ -160,7 +162,7 @@ public struct PBXProject: ProjectElement, PBXProjPlistSerializable {
.map { target in
return .string(PBXProjPlistCommentedString(target,
comment: nativeTarget(from: target, proj: proj)))
})
})
return (key: PBXProjPlistCommentedString(self.reference,
comment: "Project object"),
value: .dictionary(dictionary))
Expand Down
5 changes: 2 additions & 3 deletions Sources/xcodeproj/PBXSourcesBuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct PBXSourcesBuildPhase: ProjectElement, PBXProjPlistSerializable {
self.files = try unboxer.unbox(key: "files")
}

// MARK - Public
// MARK: - Public

/// Returns a new build phase removing the given file.
///
Expand Down Expand Up @@ -86,7 +86,7 @@ public struct PBXSourcesBuildPhase: ProjectElement, PBXProjPlistSerializable {
var dictionary: [PBXProjPlistCommentedString: PBXProjPlistValue] = [:]
dictionary["isa"] = .string(PBXProjPlistCommentedString(PBXSourcesBuildPhase.isa))
dictionary["buildActionMask"] = .string(PBXProjPlistCommentedString("\(buildActionMask)"))
dictionary["files"] = .array(files.map{ file in
dictionary["files"] = .array(files.map { file in
var comment: String? = nil
if let fileString = fileName(from: file, proj: proj) {
comment = "\(fileString) in Sources"
Expand All @@ -109,5 +109,4 @@ public struct PBXSourcesBuildPhase: ProjectElement, PBXProjPlistSerializable {
.first
}


}
5 changes: 3 additions & 2 deletions Sources/xcodeproj/XCBuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ extension XCBuildConfiguration {

}


// MARK: - XCBuildConfiguration Extension (ProjectElement)

extension XCBuildConfiguration: ProjectElement {
Expand Down Expand Up @@ -109,7 +108,9 @@ extension XCBuildConfiguration: PBXProjPlistSerializable {
dictionary["isa"] = .string(PBXProjPlistCommentedString(XCBuildConfiguration.isa))
dictionary["name"] = .string(PBXProjPlistCommentedString(name))
var buildSettingsDictionary: [PBXProjPlistCommentedString: PBXProjPlistValue] = [:]
buildSettings.dictionary.forEach { buildSettingsDictionary[PBXProjPlistCommentedString($0.key)] = .string(PBXProjPlistCommentedString($0.value)) }
buildSettings.dictionary.forEach {
buildSettingsDictionary[PBXProjPlistCommentedString($0.key)] = .string(PBXProjPlistCommentedString($0.value))
}
dictionary["buildSettings"] = .dictionary(buildSettingsDictionary)
return (key: PBXProjPlistCommentedString(self.reference,
comment: name),
Expand Down
19 changes: 14 additions & 5 deletions Sources/xcodeproj/XCConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public typealias XCConfigInclude = (include: Path, config: XCConfig)
/// .xcconfig configuration file.
public struct XCConfig {

// MARK - Attributes
// MARK: - Attributes

/// Configuration file path.
public let path: Path
Expand All @@ -24,7 +24,7 @@ public struct XCConfig {
///
/// - Parameters:
/// - path: path where the .xcconfig file is.
/// - includes: all the .xcconfig file includes. The order is very important since it determines how the values get overriden.
/// - includes: all the .xcconfig file includes. The order determines how the values get overriden.
/// - dictionary: dictionary that contains the config.
public init(path: Path, includes: [XCConfigInclude], buildSettings: BuildSettings) {
self.path = path
Expand Down Expand Up @@ -80,13 +80,17 @@ extension XCConfig {
self.buildSettings = BuildSettings(dictionary: buildSettings)
}

/// Given the path the line is being parsed from, it returns a function that parses a line, and returns the include path and the config that the include is pointing to.
/// Given the path the line is being parsed from, it returns a function that parses a line,
/// and returns the include path and the config that the include is pointing to.
///
/// - Parameter path: path of the config file that the line belongs to.
/// - Returns: function that parses the line.
private static func configFrom(path: Path) -> (String) -> (include: Path, config: XCConfig)? {
return { line in
return XCConfig.includeRegex.matches(in: line, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: line.characters.count))
return XCConfig.includeRegex.matches(in: line,
options: NSRegularExpression.MatchingOptions(rawValue: 0),
range: NSRange(location: 0,
length: line.characters.count))
.flatMap { (match) -> String? in
if match.numberOfRanges == 2 {
return NSString(string: line).substring(with: match.rangeAt(1))
Expand All @@ -108,7 +112,10 @@ extension XCConfig {
}

private static func settingFrom(line: String) -> (key: String, value: String)? {
return XCConfig.settingRegex.matches(in: line, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: line.characters.count))
return XCConfig.settingRegex.matches(in: line,
options: NSRegularExpression.MatchingOptions(rawValue: 0),
range: NSRange(location: 0,
length: line.characters.count))
.flatMap { (match) -> (key: String, value: String)? in
if match.numberOfRanges == 3 {
let key: String = NSString(string: line).substring(with: match.rangeAt(1))
Expand All @@ -120,8 +127,10 @@ extension XCConfig {
.first
}

// swiftlint:disable:next force_try line_length
private static var includeRegex: NSRegularExpression = try! NSRegularExpression(pattern: "#include\\s+\"(.+\\.xcconfig)\"",
options: .caseInsensitive)
// swiftlint:disable:next force_try line_length
private static var settingRegex: NSRegularExpression = try! NSRegularExpression(pattern: "(.+)\\s+=\\s+(\"?.[^\"]+\"?)",
options: .caseInsensitive)

Expand Down
2 changes: 1 addition & 1 deletion Sources/xcodeproj/XCConfigurationList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extension XCConfigurationList: PBXProjPlistSerializable {
private func plistComment(proj: PBXProj) -> String? {
let project = proj.objects.projects.filter { $0.buildConfigurationList == self.reference }.first
let target = proj.objects.nativeTargets.filter { $0.buildConfigurationList == self.reference }.first
if let _ = project {
if project != nil {
return "Build configuration list for PBXProject \"\(proj.name)\""
} else if let target = target {
return "Build configuration list for PBXNativeTarget \"\(target.name)\""
Expand Down
Loading

0 comments on commit a598969

Please sign in to comment.