Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Version pinning and SPM fix #1134

Merged
merged 3 commits into from
Jan 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#902](https://github.com/realm/SwiftLint/issues/902)

* Allow specifying a `swiftlint_version` configuration key which will log a
warning if the current running version of SwiftLint is different than this
value.
[JP Simard](https://github.com/jpsim)
[#221](https://github.com/realm/SwiftLint/issues/221)

##### Bug Fixes

* Ignore close parentheses on `vertical_parameter_alignment` rule.
Expand Down Expand Up @@ -140,6 +146,10 @@
* Fix linting directories with names ending with `.swift`.
[JP Simard](https://github.com/jpsim)

* Fix running `swiftlint version` when building with Swift Package Manager.
[Marcelo Fabri](https://github.com/marcelofabri)
[#1045](https://github.com/realm/SwiftLint/issues/1045)

## 0.15.0: Hand Washable Holiday Linens 🎄

##### Breaking
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ get_version:

set_version:
$(eval NEW_VERSION := $(filter-out $@,$(MAKECMDGOALS)))
sed 's/__VERSION__/$(NEW_VERSION)/g' script/Version.swift.template > Source/SwiftLintFramework/Models/Version.swift
@/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $(NEW_VERSION)" "$(SWIFTLINTFRAMEWORK_PLIST)"
@/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $(NEW_VERSION)" "$(SWIFTLINT_PLIST)"

Expand Down
17 changes: 13 additions & 4 deletions Source/SwiftLintFramework/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ private let fileManager = FileManager.default

private enum ConfigurationKey: String {
case disabledRules = "disabled_rules"
case enabledRules = "enabled_rules" // deprecated in favor of OptInRules
case enabledRules = "enabled_rules" // deprecated in favor of optInRules
case excluded = "excluded"
case included = "included"
case optInRules = "opt_in_rules"
case reporter = "reporter"
case swiftlintVersion = "swiftlint_version"
case useNestedConfigs = "use_nested_configs" // deprecated
case whitelistRules = "whitelist_rules"
case warningThreshold = "warning_threshold"
case whitelistRules = "whitelist_rules"
}

public struct Configuration: Equatable {
Expand All @@ -55,7 +56,13 @@ public struct Configuration: Equatable {
warningThreshold: Int? = nil,
reporter: String = XcodeReporter.identifier,
ruleList: RuleList = masterRuleList,
configuredRules: [Rule]? = nil) {
configuredRules: [Rule]? = nil,
swiftlintVersion: String? = nil) {

if let pinnedVersion = swiftlintVersion, pinnedVersion != Version.current.value {
queuedPrintError("Currently running SwiftLint \(Version.current.value) but " +
"configuration specified version \(pinnedVersion).")
}

self.included = included
self.excluded = excluded
Expand Down Expand Up @@ -148,7 +155,8 @@ public struct Configuration: Equatable {
reporter: dict[ConfigurationKey.reporter.rawValue] as? String ??
XcodeReporter.identifier,
ruleList: ruleList,
configuredRules: configuredRules)
configuredRules: configuredRules,
swiftlintVersion: dict[ConfigurationKey.swiftlintVersion.rawValue] as? String)
}

public init(path: String = Configuration.fileName, rootPath: String? = nil,
Expand Down Expand Up @@ -254,6 +262,7 @@ private func validKeys(ruleList: RuleList) -> [String] {
.included,
.optInRules,
.reporter,
.swiftlintVersion,
.useNestedConfigs,
.warningThreshold,
.whitelistRules
Expand Down
13 changes: 13 additions & 0 deletions Source/SwiftLintFramework/Models/Version.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Version.swift
// SwiftLint
//
// Created by Marcelo Fabri on 12/27/16.
// Copyright © 2016 Realm. All rights reserved.
//

public struct Version {
public let value: String

public static let current = Version(value: "0.15.0")
}
5 changes: 1 addition & 4 deletions Source/SwiftLintFramework/Reporters/HTMLReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ private let formatter: DateFormatter = {
return formatter
}()

private let swiftlintVersion = Bundle(identifier: "io.realm.SwiftLintFramework")?
.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0.0.0"

public struct HTMLReporter: Reporter {
public static let identifier = "html"
public static let isRealtime = false
Expand All @@ -26,7 +23,7 @@ public struct HTMLReporter: Reporter {
}

public static func generateReport(_ violations: [StyleViolation]) -> String {
return generateReport(violations, swiftlintVersion: swiftlintVersion,
return generateReport(violations, swiftlintVersion: Version.current.value,
dateString: formatter.string(from: Date()))
}

Expand Down
6 changes: 2 additions & 4 deletions Source/swiftlint/Commands/VersionCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
import Commandant
import Foundation
import Result

private let version = Bundle(identifier: "io.realm.SwiftLintFramework")!
.object(forInfoDictionaryKey: "CFBundleShortVersionString")!
import SwiftLintFramework

struct VersionCommand: CommandProtocol {
let verb = "version"
let function = "Display the current version of SwiftLint"

func run(_ options: NoOptions<CommandantError<()>>) -> Result<(), CommandantError<()>> {
print(version)
print(Version.current.value)
return .success()
}
}
4 changes: 4 additions & 0 deletions SwiftLint.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
D4B022A41E105636007E5297 /* GenericTypeNameRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4B022A31E105636007E5297 /* GenericTypeNameRule.swift */; };
D4B022B01E109816007E5297 /* CharacterSet+LinuxHack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4B022AF1E109816007E5297 /* CharacterSet+LinuxHack.swift */; };
D4B022B21E10B613007E5297 /* RedundantVoidReturnRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4B022B11E10B613007E5297 /* RedundantVoidReturnRule.swift */; };
D4C27BFE1E12D53F00DF713E /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C27BFD1E12D53F00DF713E /* Version.swift */; };
D4C4A34C1DEA4FF000E0E04C /* AttributesConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C4A34A1DEA4FD700E0E04C /* AttributesConfiguration.swift */; };
D4C4A34E1DEA877200E0E04C /* FileHeaderRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C4A34D1DEA877200E0E04C /* FileHeaderRule.swift */; };
D4C4A3521DEFBBB700E0E04C /* FileHeaderConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C4A3511DEFBBB700E0E04C /* FileHeaderConfiguration.swift */; };
Expand Down Expand Up @@ -387,6 +388,7 @@
D4B022A31E105636007E5297 /* GenericTypeNameRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenericTypeNameRule.swift; sourceTree = "<group>"; };
D4B022AF1E109816007E5297 /* CharacterSet+LinuxHack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CharacterSet+LinuxHack.swift"; sourceTree = "<group>"; };
D4B022B11E10B613007E5297 /* RedundantVoidReturnRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedundantVoidReturnRule.swift; sourceTree = "<group>"; };
D4C27BFD1E12D53F00DF713E /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; };
D4C4A34A1DEA4FD700E0E04C /* AttributesConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributesConfiguration.swift; sourceTree = "<group>"; };
D4C4A34D1DEA877200E0E04C /* FileHeaderRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileHeaderRule.swift; sourceTree = "<group>"; };
D4C4A3511DEFBBB700E0E04C /* FileHeaderConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileHeaderConfiguration.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -872,6 +874,7 @@
E88DEA781B098D4400A66CB0 /* RuleParameter.swift */,
E88DEA6A1B0983FE00A66CB0 /* StyleViolation.swift */,
E88DEA701B09847500A66CB0 /* ViolationSeverity.swift */,
D4C27BFD1E12D53F00DF713E /* Version.swift */,
3B12C9C41C322032000B423F /* MasterRuleList.swift */,
3BD9CD3C1C37175B009A5D25 /* YamlParser.swift */,
3BCC04CC1C4F5694006073C3 /* ConfigurationError.swift */,
Expand Down Expand Up @@ -1201,6 +1204,7 @@
D4A893351E15824100BF954D /* SwiftVersion.swift in Sources */,
D4B022B21E10B613007E5297 /* RedundantVoidReturnRule.swift in Sources */,
3BCC04D21C4F56D3006073C3 /* NameConfiguration.swift in Sources */,
D4C27BFE1E12D53F00DF713E /* Version.swift in Sources */,
B2902A0E1D6681F700BFCCF7 /* PrivateUnitTestConfiguration.swift in Sources */,
D47A510E1DB29EEB00A4CC21 /* SwitchCaseOnNewlineRule.swift in Sources */,
D462021F1E15F52D0027AAD1 /* NumberSeparatorRuleExamples.swift in Sources */,
Expand Down
13 changes: 13 additions & 0 deletions script/Version.swift.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Version.swift
// SwiftLint
//
// Created by Marcelo Fabri on 12/27/16.
// Copyright © 2016 Realm. All rights reserved.
//

public struct Version {
public let value: String

public static let current = Version(value: "__VERSION__")
}