Skip to content

Commit fe55e69

Browse files
committed
swift 5, swift package manager 5
missing comment lint rule
1 parent 5c8cb03 commit fe55e69

20 files changed

+126
-101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.build
33
/Packages
44
/*.xcodeproj
5+
.swiftpm

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM swift:4.2.1
2+
COPY Package.swift ./Package.swift
3+
COPY Sources ./Sources
4+
COPY Tests ./Tests
5+
RUN swift test --configuration debug

Makefile

Lines changed: 0 additions & 44 deletions
This file was deleted.

Overrides.xcconfig

Lines changed: 0 additions & 1 deletion
This file was deleted.

Package.resolved

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.0
22
import PackageDescription
33

44
let package = Package(
55
name: "stringray",
6+
platforms: [
7+
.macOS(.v10_14)
8+
],
69
products: [
710
.executable(
811
name: "stringray",
@@ -16,8 +19,8 @@ let package = Package(
1619
dependencies: [
1720
.package(url: "https://github.com/jpsim/Yams.git", from: "1.0.1"),
1821
.package(url: "https://github.com/scottrhoyt/SwiftyTextTable.git", from: "0.5.0"),
19-
.package(url: "https://github.com/g-Off/XcodeProject.git", from: "0.4.0"),
20-
.package(url: "https://github.com/g-Off/CommandRegistry.git", .branch("master")),
22+
.package(url: "https://github.com/g-Off/XcodeProject.git", from: "0.5.0-alpha.3"),
23+
.package(url: "https://github.com/g-Off/CommandRegistry.git", from: "0.1.0"),
2124
.package(url: "https://github.com/apple/swift-package-manager.git", from: "0.3.0")
2225
],
2326
targets: [
@@ -26,15 +29,15 @@ let package = Package(
2629
dependencies: [
2730
"CommandRegistry",
2831
"RayGun",
29-
"SwiftyTextTable"
32+
"SwiftyTextTable",
33+
"XcodeProject",
34+
"Utility",
35+
"Yams",
3036
]
3137
),
3238
.target(
3339
name: "RayGun",
3440
dependencies: [
35-
"Utility",
36-
"Yams",
37-
"XcodeProject"
3841
]
3942
),
4043
.testTarget(

Sources/RayGun/Exports.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/RayGun/Lint Rules/Linter.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import Foundation
9-
import Yams
109

1110
public struct Linter {
1211
public struct Config: Decodable {
@@ -29,11 +28,6 @@ public struct Linter {
2928
self.rules = [:]
3029
}
3130

32-
public init(url: Foundation.URL) throws {
33-
let string = try String(contentsOf: url, encoding: .utf8)
34-
self = try YAMLDecoder().decode(Config.self, from: string, userInfo: [:])
35-
}
36-
3731
public init(from decoder: Decoder) throws {
3832
let container = try decoder.container(keyedBy: CodingKeys.self)
3933
self.included = try container.decodeIfPresent([String].self, forKey: .included) ?? []
@@ -47,7 +41,8 @@ public struct Linter {
4741
public static let allRules: [LintRule] = [
4842
MissingLocalizationLintRule(),
4943
OrphanedLocalizationLintRule(),
50-
MissingPlaceholderLintRule()
44+
MissingPlaceholderLintRule(),
45+
MissingCommentLintRule()
5146
]
5247

5348
public struct Error: LocalizedError {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// MissingCommentLintRule.swift
3+
// RayGun
4+
//
5+
// Created by Geoffrey Foster on 2019-06-02.
6+
//
7+
8+
import Foundation
9+
10+
struct MissingCommentLintRule: LintRule {
11+
let info: RuleInfo = RuleInfo(identifier: "missing_comment", name: "Missing Comment", description: "", severity: .error)
12+
13+
func scan(table: StringsTable, url: Foundation.URL, config: Linter.Config.Rule?) throws -> [LintRuleViolation] {
14+
var violations: [LintRuleViolation] = []
15+
let file = Foundation.URL(fileURLWithPath: "\(table.base.identifier).lproj/\(table.name).strings", relativeTo: url)
16+
for entry in table.baseEntries where entry.comment == nil {
17+
let line = entry.location?.line
18+
let location = LintRuleViolation.Location(file: file, line: line)
19+
let reason = "Mismatched placeholders \(entry.key)"
20+
let violation = LintRuleViolation(locale: table.base, location: location, severity: config?.severity ?? info.severity, reason: reason)
21+
violations.append(violation)
22+
}
23+
return violations
24+
}
25+
}

Sources/RayGun/Strings Table/StringsTable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public struct StringsTable: Codable {
4545
return dictEntries[base] ?? [:]
4646
}
4747

48-
public init(name: String, base: Locale, entries: EntriesType, dictEntries: DictEntriesType) {
48+
public init(name: String, base: Locale, entries: EntriesType = [:], dictEntries: DictEntriesType = [:]) {
4949
self.name = name
5050
self.base = base
5151
self.entries = entries
@@ -125,7 +125,7 @@ public struct StringsTable: Codable {
125125
}
126126

127127
private mutating func replace(entry: Entry, with otherEntry: Entry, locale: Locale) {
128-
guard let index = entries[locale]?.index(of: entry) else { return }
128+
guard let index = entries[locale]?.firstIndex(of: entry) else { return }
129129
entries[locale]?[index] = otherEntry
130130
}
131131

0 commit comments

Comments
 (0)