Skip to content

Commit

Permalink
Fixes some linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
rderik committed Sep 23, 2020
1 parent 581c030 commit 790f87d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
26 changes: 13 additions & 13 deletions Sources/octoprofile/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@ struct Octoprofile: ParsableCommand {

let regex = try NSRegularExpression(pattern: pluginPattern, options: [])
var content = [String]()
contents.enumerateLines() { line, _ in
contents.enumerateLines { line, _ in
let range = NSRange(line.startIndex..<line.endIndex, in: line)

if let match = regex.firstMatch(in: line, options: [], range: range) {
if let match = regex.firstMatch(in: line, options: [], range: range) {
let pluginNameRange = match.range(withName: "plugin")
if pluginNameRange.location != NSNotFound, let range = Range(pluginNameRange, in: line) {
let pluginName = String(line[range])
var parameter: String? = nil
var parameter: String?
let parameterRange = match.range(withName: "parameter")
if parameterRange.location != NSNotFound, let prange = Range(parameterRange, in: line) {
parameter = String(line[prange])
}
for (name, p) in plugins {
if pluginName == name {
var p = p
p.parameter = parameter
let output = regex.stringByReplacingMatches(in: line, options: [], range: match.range, withTemplate: p.execute())
content.append(output)
break
}
for (name, plugin) in plugins where pluginName == name {
var plugin = plugin
plugin.parameter = parameter
let output = regex.stringByReplacingMatches(in: line,
options: [],
range: match.range,
withTemplate: plugin.execute())
content.append(output)
break
}
}
} else {
Expand All @@ -53,8 +54,7 @@ struct Octoprofile: ParsableCommand {
FileHandle.standardError.write(error.localizedDescription.data(using: .utf8)!)
Foundation.exit(EXIT_FAILURE)
}
}
else {
} else {
print(content.joined(separator: "\n"))
}
}
Expand Down
28 changes: 14 additions & 14 deletions Sources/octoprofile/plugins/RssPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ struct BlogPost {
var url: String?
}


struct RssPlugin: OctoPlugin {
static var name = "RSS"

var parameter: String? {
get {
return _feedURL
Expand All @@ -20,7 +19,7 @@ struct RssPlugin: OctoPlugin {
defaultPostNum = Int(parameters?.last ?? "") ?? 5
}
}

var defaultPostNum = 5
private var _feedURL: String?

Expand All @@ -30,7 +29,7 @@ struct RssPlugin: OctoPlugin {
let message = "Error: missing feed URL"
stderr.write(message.data(using: .utf8)!)
Foundation.exit(EXIT_FAILURE)
}
}
guard let url = URL(string: _feedURL ) else {
let message = "Error: malformed url \(_feedURL)"
stderr.write(message.data(using: .utf8)!)
Expand All @@ -47,31 +46,32 @@ struct RssPlugin: OctoPlugin {
switch feed {
case .rss(let myFeed):
let postNum = min(defaultPostNum, myFeed.items?.count ?? 0)
for i in (0 ..< postNum) {
for i in (0 ..< postNum) {
let title = myFeed.items?[i].title ?? ""
let link = myFeed.items?[i].link ?? ""
blogPosts.append(BlogPost(title:title, url: link))
blogPosts.append(BlogPost(title: title, url: link))
}
case .atom(let myFeed):
let postNum = min(defaultPostNum, myFeed.entries?.count ?? 0)
for i in (0 ..< postNum) {
for i in (0 ..< postNum) {
let title = myFeed.entries?[i].title ?? ""
let link = myFeed.entries?[i].links?[0].attributes?.href ?? "#"
blogPosts.append(BlogPost(title:title, url: link))
blogPosts.append(BlogPost(title: title, url: link))
}
case .json(let myFeed):
print("Is Json")
let postNum = min(defaultPostNum, myFeed.items?.count ?? 0)
for i in (0 ..< postNum) {
for i in (0 ..< postNum) {
let title = myFeed.items?[i].title ?? ""
let link = myFeed.items?[i].url ?? ""
blogPosts.append(BlogPost(title:title, url: link))
blogPosts.append(BlogPost(title: title, url: link))
}
}

case .failure(let error):
stderr.write((error.localizedDescription.data(using: .utf8) ?? "Error: Can't parse feed".data(using: .utf8))!)
Foundation.exit(EXIT_FAILURE)
case .failure(let error):
stderr.write(
(error.localizedDescription.data(using: .utf8) ?? "Error: Can't parse feed".data(using: .utf8))!
)
Foundation.exit(EXIT_FAILURE)
}
var content = ""
for blogPost in blogPosts {
Expand Down
2 changes: 1 addition & 1 deletion Sources/octoprofile/plugins/TwitterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct TwitterPlugin: OctoPlugin {
private var username: String?

func execute() -> String {
guard let username = username else { return "" }
guard let username = username else { return "" }
return "[@\(username)](https://twitter.com/\(username))"
}
}

0 comments on commit 790f87d

Please sign in to comment.