Skip to content

Commit 0135e01

Browse files
committed
Rename the swift-format utility to swift-indent
This is to distinguish the C++ indenting functionality from the new formatter that is written in Swift.
1 parent 28b3d8e commit 0135e01

21 files changed

+142
-142
lines changed

docs/SwiftFormat.md

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

docs/SwiftIndent.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
# Swift-indent
3+
4+
## Introduction
5+
6+
Note: This tool is still a work in progress.
7+
8+
swift-indent is a tool for automatically indenting your Swift files according to a
9+
set of rules. It is implemented as another driver kind, like swiftc, the batch
10+
compiler, so swift-indent is actually a symbolic link to swift. This tool uses
11+
libIDE to indent code, so it can be leveraged from multiple systems and editors.
12+
13+
## Usage
14+
15+
To print all the available options:
16+
17+
swift-indent -help
18+
19+
By default, swift-indent will output the indented file to the standard output:
20+
21+
swift-indent sample.swift
22+
23+
You can either output the result to a separate file:
24+
25+
swift-indent sample.swift -o result.swift
26+
27+
Or you can indent in-place (the original file will be overwritten):
28+
29+
swift-indent -in-place sample.swift
30+
31+
If you want to indent using tabs instead of spaces, use the `-use-tabs` option:
32+
33+
swift-indent -use-tabs sample.swift
34+
35+
You can set the number of tabs or spaces using the `-tab-width` and
36+
`-indent-width` options, respectively.
37+
38+
If you want to indent cases in switch statements, use the "-indent-switch-case"
39+
option. The result would be something like this:
40+
41+
switch aSwitch {
42+
case .some(let s):
43+
print(s)
44+
45+
swift-indent supports indenting a range of lines from a file:
46+
47+
swift-indent -line-range 2:45 sample.swift
48+
49+
This will indent the file from lines 2 to 45, inclusive.
50+
51+
You can indent several files, but the `-line-range` option is not supported in
52+
that case.
53+
54+
You can also provide several line ranges by using multiple `-line-range` options:
55+
56+
swift-indent -line-range 2:45 -line-range 100:120 sample.swift

include/swift/Driver/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Driver {
158158
Interactive, // swift
159159
Batch, // swiftc
160160
AutolinkExtract, // swift-autolink-extract
161-
SwiftFormat // swift-format
161+
SwiftIndent // swift-indent
162162
};
163163

164164
class InputInfoMap;

include/swift/IDE/Formatting.h renamed to include/swift/IDE/Indenting.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Formatting.h -------------------------------------------*- C++ -*-===//
1+
//===--- Indenting.h --------------------------------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_FORMATTING_H
14-
#define SWIFT_FORMATTING_H
13+
#ifndef SWIFT_INDENTING_H
14+
#define SWIFT_INDENTING_H
1515

1616
namespace swift {
1717
namespace ide {
@@ -101,4 +101,4 @@ std::pair<LineRange, std::string> reformat(LineRange Range,
101101
} // namespace ide
102102
} // namespace swift
103103

104-
#endif // LLVM_SWIFT_FORMATTING_H
104+
#endif // SWIFT_INDENTING_H

include/swift/Option/Options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace options {
3333
DoesNotAffectIncrementalBuild = (1 << 8),
3434
AutolinkExtractOption = (1 << 9),
3535
ModuleWrapOption = (1 << 10),
36-
SwiftFormatOption = (1 << 11),
36+
SwiftIndentOption = (1 << 11),
3737
ArgumentIsPath = (1 << 12),
3838
ModuleInterfaceOption = (1 << 13),
3939
};

include/swift/Option/Options.td

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def AutolinkExtractOption : OptionFlag;
2929
// The option should be accepted by swift -modulewrap
3030
def ModuleWrapOption : OptionFlag;
3131

32-
// The option should be accepted by swift-format
33-
def SwiftFormatOption : OptionFlag;
32+
// The option should be accepted by swift-indent
33+
def SwiftIndentOption : OptionFlag;
3434

3535
// The option should not be accepted by the driver.
3636
def NoDriverOption : OptionFlag;
@@ -152,7 +152,7 @@ def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>,
152152
HelpText<"Set the driver mode to either 'swift' or 'swiftc'">;
153153

154154
def help : Flag<["-", "--"], "help">,
155-
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption, SwiftFormatOption]>,
155+
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption, SwiftIndentOption]>,
156156
HelpText<"Display available options">;
157157
def h : Flag<["-"], "h">, Alias<help>;
158158
def help_hidden : Flag<["-", "--"], "help-hidden">,
@@ -174,7 +174,7 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
174174

175175
def o : JoinedOrSeparate<["-"], "o">,
176176
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption,
177-
NoInteractiveOption, SwiftFormatOption, ArgumentIsPath]>,
177+
NoInteractiveOption, SwiftIndentOption, ArgumentIsPath]>,
178178
HelpText<"Write output to <file>">, MetaVarName<"<file>">;
179179

180180
def j : JoinedOrSeparate<["-"], "j">, Flags<[DoesNotAffectIncrementalBuild]>,
@@ -588,28 +588,28 @@ def AssertConfig : Separate<["-"], "assert-config">,
588588
def code_formatting_Group : OptionGroup<"<code formatting options>">;
589589

590590
def use_tabs : Flag<["-"], "use-tabs">, Group<code_formatting_Group>,
591-
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
591+
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
592592
HelpText<"Use tabs for indentation.">;
593593

594594
def indent_switch_case : Flag<["-"], "indent-switch-case">,
595595
Group<code_formatting_Group>,
596-
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
596+
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
597597
HelpText<"Indent cases in switch statements.">;
598598

599599
def in_place : Flag<["-"], "in-place">, Group<code_formatting_Group>,
600-
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
600+
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
601601
HelpText<"Overwrite input file with formatted file.">;
602602

603603
def tab_width : Separate<["-"], "tab-width">, Group<code_formatting_Group>,
604-
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
604+
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
605605
HelpText<"Width of tab character.">, MetaVarName<"<n>">;
606606

607607
def indent_width : Separate<["-"], "indent-width">, Group<code_formatting_Group>,
608-
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
608+
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
609609
HelpText<"Number of characters to indent.">, MetaVarName<"<n>">;
610610

611611
def line_range : Separate<["-"], "line-range">, Group<code_formatting_Group>,
612-
Flags<[NoInteractiveOption, NoBatchOption, SwiftFormatOption]>,
612+
Flags<[NoInteractiveOption, NoBatchOption, SwiftIndentOption]>,
613613
HelpText<"<start line>:<end line>. Formats a range of lines (1-based). "
614614
"Can only be used with one input file.">, MetaVarName<"<n:n>">;
615615

lib/Driver/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void Driver::parseDriverKind(ArrayRef<const char *> Args) {
9797
.Case("swift", DriverKind::Interactive)
9898
.Case("swiftc", DriverKind::Batch)
9999
.Case("swift-autolink-extract", DriverKind::AutolinkExtract)
100-
.Case("swift-format", DriverKind::SwiftFormat)
100+
.Case("swift-indent", DriverKind::SwiftIndent)
101101
.Default(None);
102102

103103
if (Kind.hasValue())
@@ -3053,7 +3053,7 @@ void Driver::printHelp(bool ShowHidden) const {
30533053
break;
30543054
case DriverKind::Batch:
30553055
case DriverKind::AutolinkExtract:
3056-
case DriverKind::SwiftFormat:
3056+
case DriverKind::SwiftIndent:
30573057
ExcludedFlagsBitmask |= options::NoBatchOption;
30583058
break;
30593059
}

lib/IDE/Formatting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "swift/Parse/Parser.h"
1616
#include "swift/Frontend/Frontend.h"
1717
#include "swift/Basic/SourceManager.h"
18-
#include "swift/IDE/Formatting.h"
18+
#include "swift/IDE/Indenting.h"
1919
#include "swift/Subsystems.h"
2020

2121
using namespace swift;

test/lit.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ if 'syntax_parser_lib' in config.available_features:
274274
config.swift_syntax_parser_test = inferSwiftBinary('swift-syntax-parser-test')
275275
config.swift_reflection_dump = inferSwiftBinary('swift-reflection-dump')
276276
config.swift_remoteast_test = inferSwiftBinary('swift-remoteast-test')
277-
config.swift_format = inferSwiftBinary('swift-format')
277+
config.swift_indent = inferSwiftBinary('swift-indent')
278278
config.clang = inferSwiftBinary('clang')
279279
config.llvm_link = inferSwiftBinary('llvm-link')
280280
config.swift_llvm_opt = inferSwiftBinary('swift-llvm-opt')
@@ -403,7 +403,7 @@ if '-enable-astscope-lookup' in config.swift_test_options:
403403
config.available_features.add("enable-astscope-lookup")
404404
if '-disable-parser-lookup' in config.swift_test_options:
405405
config.available_features.add("disable-parser-lookup")
406-
config.substitutions.append( ('%swift-format', config.swift_format) )
406+
config.substitutions.append( ('%swift-indent', config.swift_indent) )
407407
config.substitutions.append( ('%llvm-link', config.llvm_link) )
408408
config.substitutions.append( ('%swift-llvm-opt', config.swift_llvm_opt) )
409409
config.substitutions.append( ('%llvm-dwarfdump', config.llvm_dwarfdump) )

test/swift-format/main.swift renamed to test/swift-indent/main.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// RUN: %swift-format %s >%t.response
1+
// RUN: %swift-indent %s >%t.response
22
// RUN: diff -u %s.response %t.response
3-
// RUN: %swift-format -indent-width 2 %s >%t.response
3+
// RUN: %swift-indent -indent-width 2 %s >%t.response
44
// RUN: diff -u %s.indent2.response %t.response
5-
// RUN: %swift-format -use-tabs %s >%t.response
5+
// RUN: %swift-indent -use-tabs %s >%t.response
66
// RUN: diff -u %s.tabs.response %t.response
7-
// RUN: %swift-format -line-range 24:29 %s >%t.response
7+
// RUN: %swift-indent -line-range 24:29 %s >%t.response
88
// RUN: diff -u %s.lines.response %t.response
9-
// RUN: %swift-format -indent-switch-case %s >%t.response
9+
// RUN: %swift-indent -indent-switch-case %s >%t.response
1010
// RUN: diff -u %s.indentswitch.response %t.response
1111

1212
import Foundation

test/swift-format/main.swift.indent2.response renamed to test/swift-indent/main.swift.indent2.response

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// RUN: %swift-format %s >%t.response
1+
// RUN: %swift-indent %s >%t.response
22
// RUN: diff -u %s.response %t.response
3-
// RUN: %swift-format -indent-width 2 %s >%t.response
3+
// RUN: %swift-indent -indent-width 2 %s >%t.response
44
// RUN: diff -u %s.indent2.response %t.response
5-
// RUN: %swift-format -use-tabs %s >%t.response
5+
// RUN: %swift-indent -use-tabs %s >%t.response
66
// RUN: diff -u %s.tabs.response %t.response
7-
// RUN: %swift-format -line-range 24:29 %s >%t.response
7+
// RUN: %swift-indent -line-range 24:29 %s >%t.response
88
// RUN: diff -u %s.lines.response %t.response
9-
// RUN: %swift-format -indent-switch-case %s >%t.response
9+
// RUN: %swift-indent -indent-switch-case %s >%t.response
1010
// RUN: diff -u %s.indentswitch.response %t.response
1111

1212
import Foundation

test/swift-format/main.swift.indentswitch.response renamed to test/swift-indent/main.swift.indentswitch.response

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// RUN: %swift-format %s >%t.response
1+
// RUN: %swift-indent %s >%t.response
22
// RUN: diff -u %s.response %t.response
3-
// RUN: %swift-format -indent-width 2 %s >%t.response
3+
// RUN: %swift-indent -indent-width 2 %s >%t.response
44
// RUN: diff -u %s.indent2.response %t.response
5-
// RUN: %swift-format -use-tabs %s >%t.response
5+
// RUN: %swift-indent -use-tabs %s >%t.response
66
// RUN: diff -u %s.tabs.response %t.response
7-
// RUN: %swift-format -line-range 24:29 %s >%t.response
7+
// RUN: %swift-indent -line-range 24:29 %s >%t.response
88
// RUN: diff -u %s.lines.response %t.response
9-
// RUN: %swift-format -indent-switch-case %s >%t.response
9+
// RUN: %swift-indent -indent-switch-case %s >%t.response
1010
// RUN: diff -u %s.indentswitch.response %t.response
1111

1212
import Foundation

test/swift-format/main.swift.lines.response renamed to test/swift-indent/main.swift.lines.response

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// RUN: %swift-format %s >%t.response
1+
// RUN: %swift-indent %s >%t.response
22
// RUN: diff -u %s.response %t.response
3-
// RUN: %swift-format -indent-width 2 %s >%t.response
3+
// RUN: %swift-indent -indent-width 2 %s >%t.response
44
// RUN: diff -u %s.indent2.response %t.response
5-
// RUN: %swift-format -use-tabs %s >%t.response
5+
// RUN: %swift-indent -use-tabs %s >%t.response
66
// RUN: diff -u %s.tabs.response %t.response
7-
// RUN: %swift-format -line-range 24:29 %s >%t.response
7+
// RUN: %swift-indent -line-range 24:29 %s >%t.response
88
// RUN: diff -u %s.lines.response %t.response
9-
// RUN: %swift-format -indent-switch-case %s >%t.response
9+
// RUN: %swift-indent -indent-switch-case %s >%t.response
1010
// RUN: diff -u %s.indentswitch.response %t.response
1111

1212
import Foundation

test/swift-format/main.swift.response renamed to test/swift-indent/main.swift.response

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// RUN: %swift-format %s >%t.response
1+
// RUN: %swift-indent %s >%t.response
22
// RUN: diff -u %s.response %t.response
3-
// RUN: %swift-format -indent-width 2 %s >%t.response
3+
// RUN: %swift-indent -indent-width 2 %s >%t.response
44
// RUN: diff -u %s.indent2.response %t.response
5-
// RUN: %swift-format -use-tabs %s >%t.response
5+
// RUN: %swift-indent -use-tabs %s >%t.response
66
// RUN: diff -u %s.tabs.response %t.response
7-
// RUN: %swift-format -line-range 24:29 %s >%t.response
7+
// RUN: %swift-indent -line-range 24:29 %s >%t.response
88
// RUN: diff -u %s.lines.response %t.response
9-
// RUN: %swift-format -indent-switch-case %s >%t.response
9+
// RUN: %swift-indent -indent-switch-case %s >%t.response
1010
// RUN: diff -u %s.indentswitch.response %t.response
1111

1212
import Foundation

test/swift-format/main.swift.tabs.response renamed to test/swift-indent/main.swift.tabs.response

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// RUN: %swift-format %s >%t.response
1+
// RUN: %swift-indent %s >%t.response
22
// RUN: diff -u %s.response %t.response
3-
// RUN: %swift-format -indent-width 2 %s >%t.response
3+
// RUN: %swift-indent -indent-width 2 %s >%t.response
44
// RUN: diff -u %s.indent2.response %t.response
5-
// RUN: %swift-format -use-tabs %s >%t.response
5+
// RUN: %swift-indent -use-tabs %s >%t.response
66
// RUN: diff -u %s.tabs.response %t.response
7-
// RUN: %swift-format -line-range 24:29 %s >%t.response
7+
// RUN: %swift-indent -line-range 24:29 %s >%t.response
88
// RUN: diff -u %s.lines.response %t.response
9-
// RUN: %swift-format -indent-switch-case %s >%t.response
9+
// RUN: %swift-indent -indent-switch-case %s >%t.response
1010
// RUN: diff -u %s.indentswitch.response %t.response
1111

1212
import Foundation

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
3434
#include "swift/IDE/CodeCompletion.h"
3535
#include "swift/IDE/CommentConversion.h"
36-
#include "swift/IDE/Formatting.h"
36+
#include "swift/IDE/Indenting.h"
3737
#include "swift/IDE/SourceEntityWalker.h"
3838
#include "swift/IDE/SyntaxModel.h"
3939
#include "swift/Subsystems.h"

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "SourceKit/Support/ThreadSafeRefCntPtr.h"
2222
#include "SourceKit/Support/Tracing.h"
2323
#include "swift/Basic/ThreadSafeRefCounted.h"
24-
#include "swift/IDE/Formatting.h"
24+
#include "swift/IDE/Indenting.h"
2525
#include "swift/IDE/Refactoring.h"
2626
#include "swift/Index/IndexSymbol.h"
2727
#include "llvm/ADT/IntrusiveRefCntPtr.h"

0 commit comments

Comments
 (0)