Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Move Configuration into the SwiftFormat module. #614

Merged
merged 1 commit into from
Sep 5, 2023
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
16 changes: 4 additions & 12 deletions Documentation/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Since Swift does not yet have a runtime reflection system, we use code
generation to keep the linting/formatting pipeline up-to-date. If you add or
remove any rules from the `SwiftFormatRules` module, or if you add or remove
remove any rules from the `SwiftFormat` module, or if you add or remove
any `visit` methods from an existing rule in that module, you must run the
`generate-pipeline` tool update the pipeline and configuration sources.

Expand All @@ -14,17 +14,9 @@ The easiest way to do this is to run the following command in your terminal:
swift run generate-pipeline
```

If successful, this tool will update
`Sources/SwiftFormatConfiguration/RuleRegistry+Generated.swift` and
`Sources/SwiftFormat/Pipelines+Generated.swift`.

Likewise, you should keep the Linux XCTest manifests updated if you add or
remove any tests from `swift-format` by running the following command in your
terminal:

```shell
swift test --generate-linuxmain
```
If successful, this tool will update the files `Pipelines+Generated.swift`,
`RuleNameCache+Generated.swift`, and `RuleRegistry+Generated.swift` in
the `Sources/SwiftFormat/Core` directory.

## Command Line Options for Debugging

Expand Down
15 changes: 6 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let package = Package(
name: "SwiftFormat",
targets: ["SwiftFormat", "SwiftFormatConfiguration"]
),
// TODO: Remove this product after the 509 release.
.library(
name: "SwiftFormatConfiguration",
targets: ["SwiftFormatConfiguration"]
Expand All @@ -49,22 +50,24 @@ let package = Package(
.target(
name: "SwiftFormat",
dependencies: [
"SwiftFormatConfiguration",
.product(name: "Markdown", package: "swift-markdown"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
]
),
// TODO: Remove this target after the 509 release.
.target(
name: "SwiftFormatConfiguration"
name: "SwiftFormatConfiguration",
dependencies: [
"SwiftFormat"
]
),
.target(
name: "_SwiftFormatTestSupport",
dependencies: [
"SwiftFormat",
"SwiftFormatConfiguration",
.product(name: "SwiftOperators", package: "swift-syntax"),
]
),
Expand Down Expand Up @@ -106,17 +109,12 @@ let package = Package(
name: "swift-format",
dependencies: [
"SwiftFormat",
"SwiftFormatConfiguration",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
]
),

.testTarget(
name: "SwiftFormatConfigurationTests",
dependencies: ["SwiftFormatConfiguration"]
),
.testTarget(
name: "SwiftFormatPerformanceTests",
dependencies: [
Expand All @@ -130,7 +128,6 @@ let package = Package(
name: "SwiftFormatTests",
dependencies: [
"SwiftFormat",
"SwiftFormatConfiguration",
"_SwiftFormatTestSupport",
.product(name: "Markdown", package: "swift-markdown"),
.product(name: "SwiftOperators", package: "swift-syntax"),
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/API/SwiftFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import Foundation
import SwiftDiagnostics
import SwiftFormatConfiguration
import SwiftOperators
import SwiftSyntax

Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/API/SwiftLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import Foundation
import SwiftDiagnostics
import SwiftFormatConfiguration
import SwiftOperators
import SwiftSyntax

Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/Core/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

import Foundation
import SwiftFormatConfiguration
import SwiftOperators
import SwiftSyntax
import SwiftParser
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/PrettyPrint/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

import Foundation
import SwiftFormatConfiguration
import SwiftSyntax

extension StringProtocol {
Expand Down
2 changes: 0 additions & 2 deletions Sources/SwiftFormat/PrettyPrint/Indent+Length.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
//
//===----------------------------------------------------------------------===//

import SwiftFormatConfiguration

extension Indent {
var character: Character {
switch self {
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/PrettyPrint/PrettyPrint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

import SwiftFormatConfiguration
import SwiftSyntax

/// PrettyPrinter takes a Syntax node and outputs a well-formatted, re-indented reproduction of the
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

import Foundation
import SwiftFormatConfiguration
import SwiftOperators
import SwiftSyntax

Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/PrettyPrint/Verbatim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

import Foundation
import SwiftFormatConfiguration

/// Describes options for behavior when applying the indentation of the current context when
/// printing a verbatim token.
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/PrettyPrint/WhitespaceLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

import SwiftFormatConfiguration
import SwiftSyntax

private let utf8Newline = UTF8.CodeUnit(ascii: "\n")
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftFormat/Rules/NoAssignmentInExpressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

import SwiftFormatConfiguration
import SwiftSyntax

/// Assignment expressions must be their own statements.
Expand Down
19 changes: 19 additions & 0 deletions Sources/SwiftFormatConfiguration/Compatibility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

// Make these symbols that used to live in `SwiftFormatConfiguration` available when that module is
// imported.
// TODO: Remove this after the 509 release.
@_exported import struct SwiftFormat.Configuration
@_exported import struct SwiftFormat.FileScopedDeclarationPrivacyConfiguration
@_exported import struct SwiftFormat.NoAssignmentInExpressionsConfiguration
@_exported import enum SwiftFormat.Indent
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

import SwiftFormatConfiguration
import SwiftFormat

extension Configuration {
/// The default configuration to be used during unit tests.
Expand Down
2 changes: 1 addition & 1 deletion Sources/_SwiftFormatTestSupport/DiagnosingTestCase.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat
import SwiftSyntax
import XCTest

Expand Down
3 changes: 2 additions & 1 deletion Sources/generate-pipeline/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ let pipelineFile = sourcesDirectory
.appendingPathComponent("Core")
.appendingPathComponent("Pipelines+Generated.swift")
let ruleRegistryFile = sourcesDirectory
.appendingPathComponent("SwiftFormatConfiguration")
.appendingPathComponent("SwiftFormat")
.appendingPathComponent("Core")
.appendingPathComponent("RuleRegistry+Generated.swift")

let ruleNameCacheFile = sourcesDirectory
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-format/Frontend/ConfigurationLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

import Foundation
import SwiftFormatConfiguration
import SwiftFormat

/// Loads formatter configurations, caching them in memory so that multiple operations in the same
/// directory do not repeatedly hit the file system.
Expand Down
1 change: 0 additions & 1 deletion Sources/swift-format/Frontend/FormatFrontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import Foundation
import SwiftDiagnostics
import SwiftFormat
import SwiftFormatConfiguration
import SwiftSyntax

/// The frontend for formatting operations.
Expand Down
1 change: 0 additions & 1 deletion Sources/swift-format/Frontend/Frontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import Foundation
import SwiftFormat
import SwiftFormatConfiguration
import SwiftSyntax
import SwiftParser

Expand Down
1 change: 0 additions & 1 deletion Sources/swift-format/Frontend/LintFrontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import Foundation
import SwiftDiagnostics
import SwiftFormat
import SwiftFormatConfiguration
import SwiftSyntax

/// The frontend for linting operations.
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-format/Subcommands/DumpConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import ArgumentParser
import Foundation
import SwiftFormatConfiguration
import SwiftFormat

extension SwiftFormatCommand {
/// Dumps the tool's default configuration in JSON format to standard output.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat
import XCTest

final class ConfigurationTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class AssignmentExprTests: PrettyPrintTestCase {
func testBasicAssignmentExprs() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/AttributeTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class AttributeTests: PrettyPrintTestCase {
func testAttributeParamSpacing() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/AwaitExprTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class AwaitExprTests: PrettyPrintTestCase {
func testBasicAwaits() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class BinaryOperatorExprTests: PrettyPrintTestCase {
func testNonRangeFormationOperatorsAreSurroundedByBreaks() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/ClassDeclTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class ClassDeclTests: PrettyPrintTestCase {
func testBasicClassDeclarations() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/ClosureExprTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class ClosureExprTests: PrettyPrintTestCase {
func testBasicFunctionClosures_noPackArguments() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class DeclNameArgumentTests: PrettyPrintTestCase {
func testSelectors_noPackArguments() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/DoStmtTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class DoStmtTests: PrettyPrintTestCase {
func testBasicDoStmt() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/EnumDeclTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class EnumDeclTests: PrettyPrintTestCase {
func testBasicEnumDeclarations() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class ExtensionDeclTests: PrettyPrintTestCase {
func testBasicExtensionDeclarations() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/FunctionCallTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class FunctionCallTests: PrettyPrintTestCase {
func testBasicFunctionCalls_noPackArguments() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/FunctionDeclTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class FunctionDeclTests: PrettyPrintTestCase {
func testBasicFunctionDeclarations_noPackArguments() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class IfConfigTests: PrettyPrintTestCase {
func testBasicIfConfig() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/IfStmtTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat
import XCTest

final class IfStmtTests: PrettyPrintTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class InitializerDeclTests: PrettyPrintTestCase {
func testBasicInitializerDeclarations_noPackArguments() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/MacroCallTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class MacroCallTests: PrettyPrintTestCase {
func testNoWhiteSpaceAfterMacroWithoutTrailingClosure() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/MacroDeclTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class MacroDeclTests: PrettyPrintTestCase {
func testBasicMacroDeclarations_noPackArguments() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class MemberAccessExprTests: PrettyPrintTestCase {
func testMemberAccess() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class ObjectLiteralExprTests: PrettyPrintTestCase {
func testColorLiteral_noPackArguments() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftFormatTests/PrettyPrint/OperatorDeclTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class OperatorDeclTests: PrettyPrintTestCase {
func testOperatorDecl() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat

final class PatternBindingTests: PrettyPrintTestCase {
func testBindingIncludingTypeAnnotation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftFormatConfiguration
import SwiftFormat
import SwiftOperators
import SwiftSyntax
import SwiftParser
Expand Down
Loading