Skip to content

Commit

Permalink
Renamed the library to SwiftSource
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhvorost committed Feb 21, 2024
1 parent e721b34 commit 726825a
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
.watchOS(.v6)
],
products: [
.library(name: "SwiftDocCoverage", targets: ["SwiftDocCoverage"]),
.library(name: "SwiftSource", targets: ["SwiftSource"]),
.executable(name: "swift-doc-coverage", targets: ["swift-doc-coverage"])
],
dependencies: [
Expand All @@ -22,7 +22,7 @@ let package = Package(
],
targets: [
.target(
name: "SwiftDocCoverage",
name: "SwiftSource",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
Expand All @@ -31,7 +31,7 @@ let package = Package(
.executableTarget(
name: "swift-doc-coverage",
dependencies: [
.target(name: "SwiftDocCoverage"),
.target(name: "SwiftSource"),
.product(name: "ArgumentParser", package: "swift-argument-parser")
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension String : LocalizedError {

public struct Coverage {
let urls: [URL]
let minAccessLevel: AccessLevel
let minAccessLevel: SwiftAccessLevel
let output: Output

private static func files(path: String, ext: String, skipsHiddenFiles: Bool, ignoreFilenameRegex: String) throws -> [URL] {
Expand All @@ -42,7 +42,9 @@ public struct Coverage {
if isDirectory.boolValue {
var urls = [URL]()

let regex: NSRegularExpression? = ignoreFilenameRegex.isEmpty ? nil : try NSRegularExpression(pattern: ignoreFilenameRegex)
let regex: NSRegularExpression? = ignoreFilenameRegex.isEmpty
? nil
: try NSRegularExpression(pattern: ignoreFilenameRegex)

let url = URL(fileURLWithPath: path)
let resourceKeys = Set<URLResourceKey>([.nameKey, .isDirectoryKey])
Expand Down Expand Up @@ -86,7 +88,7 @@ public struct Coverage {
return formatter
}()

public init(paths: [String], skipsHiddenFiles: Bool = true, ignoreFilenameRegex: String = "", minAccessLevel: AccessLevel = .public, output: Output = TerminalOutput()) throws {
public init(paths: [String], skipsHiddenFiles: Bool = true, ignoreFilenameRegex: String = "", minAccessLevel: SwiftAccessLevel = .public, output: Output = TerminalOutput()) throws {
self.urls = try paths.flatMap {
try Self.files(path: $0, ext: ".swift", skipsHiddenFiles: skipsHiddenFiles, ignoreFilenameRegex: ignoreFilenameRegex)
}
Expand Down Expand Up @@ -126,7 +128,7 @@ public struct Coverage {
try urls.forEach { url in
let time = Date()

let source = try Source(url: url)
let source = try SwiftSource(url: url)

guard source.declarations.count > 0 else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protocol DeclProtocol: DeclSyntaxProtocol {

// var attributes: AttributeListSyntax
var modifiers: DeclModifierListSyntax { get }
var keyword: Keyword { get }
var keyword: SwiftKeyword { get }
var name: TokenSyntax { get }

var genericParameterClause: GenericParameterClauseSyntax? { get }
Expand All @@ -43,50 +43,50 @@ extension DeclProtocol {
var funcSignature: FunctionSignatureSyntax? { nil }
var genericWhereClause: GenericWhereClauseSyntax? { nil }

var comments: [Comment] {
leadingTrivia.compactMap { Comment(piece: $0) }
var comments: [SwiftComment] {
leadingTrivia.compactMap { SwiftComment(piece: $0) }
}
var accessLevel: AccessLevel { AccessLevel(modifiers: modifiers) }
var accessLevel: SwiftAccessLevel { SwiftAccessLevel(modifiers: modifiers) }
}

// MARK: -

extension TypeAliasDeclSyntax: DeclProtocol {
var keyword: Keyword { .typealias }
var keyword: SwiftKeyword { .typealias }
}

extension AssociatedTypeDeclSyntax: DeclProtocol {
var keyword: Keyword { .associatedtype }
var keyword: SwiftKeyword { .associatedtype }
}

extension ClassDeclSyntax: DeclProtocol {
var keyword: Keyword { .class }
var keyword: SwiftKeyword { .class }
}

extension ActorDeclSyntax: DeclProtocol {
var keyword: Keyword { .actor }
var keyword: SwiftKeyword { .actor }
}

extension StructDeclSyntax: DeclProtocol {
var keyword: Keyword { .struct }
var keyword: SwiftKeyword { .struct }
}

extension ProtocolDeclSyntax: DeclProtocol {
var keyword: Keyword { .protocol }
var keyword: SwiftKeyword { .protocol }
}

extension ExtensionDeclSyntax: DeclProtocol {
var keyword: Keyword { .extension }
var keyword: SwiftKeyword { .extension }
var name: TokenSyntax { TokenSyntax(.identifier(extendedType.trimmedDescription), presence: .present)}
}

extension FunctionDeclSyntax: DeclProtocol {
var keyword: Keyword { .func }
var keyword: SwiftKeyword { .func }
var funcSignature: FunctionSignatureSyntax? { signature }
}

extension InitializerDeclSyntax: DeclProtocol {
var keyword: Keyword { .`init` }
var keyword: SwiftKeyword { .`init` }

var name: TokenSyntax {
let optionalMark = optionalMark?.trimmedDescription ?? ""
Expand All @@ -97,7 +97,7 @@ extension InitializerDeclSyntax: DeclProtocol {
}

extension SubscriptDeclSyntax: DeclProtocol {
var keyword: Keyword { .subscript }
var keyword: SwiftKeyword { .subscript }

var name: TokenSyntax {
TokenSyntax(.identifier("subscript"), presence: .present)
Expand All @@ -109,7 +109,7 @@ extension SubscriptDeclSyntax: DeclProtocol {
}

extension VariableDeclSyntax: DeclProtocol {
var keyword: Keyword { Keyword(token: bindingSpecifier)! }
var keyword: SwiftKeyword { SwiftKeyword(token: bindingSpecifier)! }

var name: TokenSyntax {
let name = bindings.map { $0.pattern.trimmedDescription }.joined(separator: ",")
Expand All @@ -118,11 +118,11 @@ extension VariableDeclSyntax: DeclProtocol {
}

extension EnumDeclSyntax: DeclProtocol {
var keyword: Keyword { .enum }
var keyword: SwiftKeyword { .enum }
}

extension EnumCaseDeclSyntax: DeclProtocol {
var keyword: Keyword { .case }
var keyword: SwiftKeyword { .case }

var name: TokenSyntax {
let name = elements.map {
Expand All @@ -135,10 +135,10 @@ extension EnumCaseDeclSyntax: DeclProtocol {
}

extension PrecedenceGroupDeclSyntax: DeclProtocol {
var keyword: Keyword { .precedencegroup }
var keyword: SwiftKeyword { .precedencegroup }
}

extension MacroDeclSyntax: DeclProtocol {
var keyword: Keyword { .macro }
var keyword: SwiftKeyword { .macro }
var funcSignature: FunctionSignatureSyntax? { signature }
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AccessLevel.swift
// SwiftAccessLevel.swift
//
// Created by Iurii Khvorost <iurii.khvorost@gmail.com> on 11.02.2022.
// Copyright © 2022 Iurii Khvorost. All rights reserved.
Expand All @@ -24,7 +24,7 @@
import SwiftSyntax


public enum AccessLevel: Int {
public enum SwiftAccessLevel: Int {
case `open`
case `public`
case `internal`
Expand Down Expand Up @@ -53,7 +53,7 @@ public enum AccessLevel: Int {
continue
}

if let accessLevel = AccessLevel(token: modifier.name) {
if let accessLevel = SwiftAccessLevel(token: modifier.name) {
self = accessLevel
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Comment.swift
// SwiftComment.swift
//
// Created by Iurii Khvorost <iurii.khvorost@gmail.com> on 11.02.2024.
// Copyright © 2022 Iurii Khvorost. All rights reserved.
Expand All @@ -24,7 +24,7 @@
import SwiftSyntax


public struct Comment {
public struct SwiftComment {
private let piece: TriviaPiece

public var text: String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Declaration.swift
// SwiftDeclaration.swift
//
// Created by Iurii Khvorost <iurii.khvorost@gmail.com> on 09.08.2022.
// Copyright © 2022 Iurii Khvorost. All rights reserved.
Expand Down Expand Up @@ -35,10 +35,10 @@ fileprivate struct StringBuilder {
}
}

public struct Declaration {
public let comments: [Comment]
public let accessLevel: AccessLevel
public var keyword: Keyword
public struct SwiftDeclaration {
public let comments: [SwiftComment]
public let accessLevel: SwiftAccessLevel
public var keyword: SwiftKeyword
public let name: String
public let line: Int
public let column: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Keyword.swift
// SwiftKeyword.swift
//
// Created by Iurii Khvorost <iurii.khvorost@gmail.com> on 11.02.2024.
// Copyright © 2022 Iurii Khvorost. All rights reserved.
Expand All @@ -24,7 +24,7 @@
import SwiftSyntax


public enum Keyword: String {
public enum SwiftKeyword: String {
case actor
case `associatedtype`
case `case`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Source.swift
// SwiftSource.swift
//
// Created by Iurii Khvorost <iurii.khvorost@gmail.com> on 08.08.2022.
// Copyright © 2022 Iurii Khvorost. All rights reserved.
Expand All @@ -25,9 +25,9 @@ import Foundation
import SwiftSyntax


public struct Source {
public struct SwiftSource {
public let url: URL?
public let declarations: [Declaration]
public let declarations: [SwiftDeclaration]

private init(url: URL?, source: String) {
self.url = url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Visitor: SyntaxVisitor {
private var context = [DeclProtocol]()
private let converter: SourceLocationConverter

private(set) var declarations = [Declaration]()
private(set) var declarations = [SwiftDeclaration]()

init(source: String) {
let sourceFile = Parser.parse(source: source)
Expand All @@ -45,7 +45,7 @@ class Visitor: SyntaxVisitor {
? context.map { $0.name.trimmedDescription }.joined(separator: ".")
: nil

let declaration = Declaration(decl: decl, path: path, location: startLocation)
let declaration = SwiftDeclaration(decl: decl, path: path, location: startLocation)
declarations.append(declaration)
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/swift-doc-coverage/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

import Foundation
import ArgumentParser
import SwiftDocCoverage
import SwiftSource


enum AccessLevelArgument: String, ExpressibleByArgument {
enum AccessLevel: String, ExpressibleByArgument {
case open, `public`, `internal`, `fileprivate`, `private`

var accessLevel: AccessLevel {
var accessLevel: SwiftAccessLevel {
switch self {
case .open: return .open
case .public: return .public
Expand Down Expand Up @@ -62,8 +62,8 @@ struct SwiftDocCoverage: ParsableCommand {
@Option(name: .shortAndLong, help: "Skip source code files with file paths that match the given regular expression.")
var ignoreFilenameRegex: String = ""

@Option(name: .shortAndLong, help: "The minimum access level of the symbols considered for coverage statistics: \(AccessLevelArgument.open), \(AccessLevelArgument.public), \(AccessLevelArgument.internal), \(AccessLevelArgument.fileprivate), \(AccessLevelArgument.private).")
var minimumAccessLevel: AccessLevelArgument = .public
@Option(name: .shortAndLong, help: "The minimum access level of the symbols considered for coverage statistics: \(AccessLevel.open), \(AccessLevel.public), \(AccessLevel.internal), \(AccessLevel.fileprivate), \(AccessLevel.private).")
var minimumAccessLevel: AccessLevel = .public

@Option(name: .shortAndLong, help: "Report modes: \(ReportArgument.statistics.rawValue), \(ReportArgument.warnings.rawValue), \(ReportArgument.json.rawValue).")
var report: ReportArgument = .statistics
Expand Down
Loading

0 comments on commit 726825a

Please sign in to comment.