Skip to content

Commit c936ea4

Browse files
authored
Merge pull request #18 from ra1028/feat/support-filelist-params
feat: Support filelist parameter via command line
2 parents e4df5ab + 5a86008 commit c936ea4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+767
-1487
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ xcuserdata/
55
vendor/
66
.bundle/
77
.tmp
8+
.swiftpm/
89
swift-mod.zip

.swift-mod.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ format:
22
indent: 4
33
lineBreakBeforeEachArgument: true
44

5-
targets:
6-
main:
7-
paths:
8-
- Sources
9-
excludedPaths:
10-
- "**/main.swift"
11-
rules:
12-
defaultAccessLevel:
13-
accessLevel: openOrPublic
14-
implicitInternal: true
5+
rules:
6+
defaultAccessLevel:
7+
accessLevel: openOrPublic
8+
implicitInternal: true
159

16-
defaultMemberwiseInitializer:
17-
implicitInitializer: true
18-
implicitInternal: true
19-
ignoreClassesWithInheritance: true
10+
defaultMemberwiseInitializer:
11+
implicitInitializer: true
12+
implicitInternal: true
13+
ignoreClassesWithInheritance: true

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.10
1+
0.1.0

Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
SWIFT_FORMAT_PATHS := Sources/ $(shell find Tests/**/*.swift -not -name XCTestManifests.swift)
1+
SWIFT_FORMAT_PATHS := Sources $(shell find Tests -type f -name "*.swift")
2+
SWIFT_MOD_PATHS := $(shell find Sources -type f -name "*.swift" -not -path "Sources/swift-mod/*")
23
SWIFT_BUILD_FLAGS := -c release --disable-sandbox
34
TOOL_NAME := swift-mod
45
XCODE_DEFAULT_TOOLCHAIN := /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
@@ -18,9 +19,6 @@ TOOL_BIN := $(TOOL_BIN_DIR)/$(TOOL_NAME)
1819

1920
.PHONY: $(MAKECMDGOALS)
2021

21-
xcodeproj:
22-
swift package generate-xcodeproj
23-
2422
build:
2523
swift build $(SWIFT_BUILD_FLAGS)
2624
@echo $(TOOL_BIN)
@@ -29,7 +27,7 @@ test:
2927
swift test -c release --parallel
3028

3129
mod:
32-
swift run -c release swift-mod
30+
swift run -c release swift-mod $(SWIFT_MOD_PATHS)
3331

3432
format:
3533
swift run -c release --package-path ./Tools -- swift-format format --configuration .swift-format.json -i -r $(SWIFT_FORMAT_PATHS)

Package.resolved

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

Package.swift

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,59 @@
22

33
import PackageDescription
44

5-
let testsSuffix = "Tests"
6-
7-
let core = Target.target(
8-
name: "SwiftModCore",
9-
dependencies: [
10-
.product(name: "SwiftSyntaxParser", package: "swift-syntax"),
11-
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
12-
"Yams",
13-
]
14-
)
15-
16-
let coreTests = Target.testTarget(
17-
name: core.name + testsSuffix,
18-
dependencies: [.target(name: core.name)] + core.dependencies
19-
)
20-
21-
let rules = Target.target(
22-
name: "SwiftModRules",
23-
dependencies: [.target(name: core.name)] + core.dependencies
24-
)
25-
26-
let rulesTests = Target.testTarget(
27-
name: rules.name + testsSuffix,
28-
dependencies: [.target(name: rules.name)] + rules.dependencies
29-
)
30-
31-
let commands = Target.target(
32-
name: "SwiftModCommands",
33-
dependencies: [.target(name: rules.name)] + rules.dependencies
34-
)
35-
36-
let commandsTests = Target.testTarget(
37-
name: commands.name + testsSuffix,
38-
dependencies: [.target(name: commands.name)] + commands.dependencies
39-
)
40-
41-
let cli = Target.executableTarget(
42-
name: "swift-mod",
43-
dependencies: [.target(name: commands.name)] + commands.dependencies
44-
)
45-
465
let package = Package(
476
name: "swift-mod",
487
platforms: [
498
.macOS("10.15")
509
],
5110
products: [
52-
.executable(name: "swift-mod", targets: [cli.name])
11+
.executable(
12+
name: "swift-mod",
13+
targets: ["swift-mod"]
14+
)
5315
],
5416
dependencies: [
5517
.package(url: "https://github.com/apple/swift-syntax", .upToNextMinor(from: "0.50600.1")),
18+
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "1.1.2")),
5619
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.2.3"),
5720
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.0")
5821
],
5922
targets: [
60-
cli,
61-
commands,
62-
commandsTests,
63-
rules,
64-
rulesTests,
65-
core,
66-
coreTests,
23+
.executableTarget(
24+
name: "swift-mod",
25+
dependencies: ["SwiftModCommands"]
26+
),
27+
.target(
28+
name: "SwiftModCommands",
29+
dependencies: [
30+
"SwiftModRules",
31+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
32+
]
33+
),
34+
.testTarget(
35+
name: "SwiftModCommandsTests",
36+
dependencies: ["SwiftModCommands"]
37+
),
38+
.target(
39+
name: "SwiftModRules",
40+
dependencies: ["SwiftModCore"]
41+
),
42+
.testTarget(
43+
name: "SwiftModRulesTests",
44+
dependencies: ["SwiftModRules"]
45+
),
46+
.target(
47+
name: "SwiftModCore",
48+
dependencies: [
49+
.product(name: "SwiftSyntaxParser", package: "swift-syntax"),
50+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
51+
"Yams",
52+
]
53+
),
54+
.testTarget(
55+
name: "SwiftModCoreTests",
56+
dependencies: ["SwiftModCore"]
57+
),
6758
],
6859
swiftLanguageVersions: [.v5]
6960
)

README.md

Lines changed: 48 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ swift-mod init
7474

7575
```sh
7676
swift-mod rules
77-
swift-mod rules --detail [RULE IDENTIFIER] # Display more detailed rule description
77+
swift-mod rules --rule [RULE NAME] # Display more detailed rule description
7878
```
7979

8080
4. Edit your configuration file with an editor you like, refering to the [documentation](#configuration).
8181

8282
5. Run
8383

8484
```sh
85-
swift-mod
85+
swift-mod <list of input files>
8686
```
8787

8888
---
@@ -95,26 +95,45 @@ swift-mod [COMMAND] [OPTIONS]
9595

9696
All commands can be display a usage by option `-h/--help`.
9797

98-
- `run` (or not specified): Modifies Swift source code by rules.
98+
- `run` (or not specified)
9999

100-
|OPTION|SHORT|USAGE|
101-
|:-|:-|:-|
102-
|--configuration|-c|The path to a configuration Yaml file|
103-
|--target|-t|The target name to be run partially|
104-
|--dry-run||Run without actually changing any files|
105-
|--check||Dry run that an error occurs if the any files should be changed|
100+
```
101+
OVERVIEW: Runs modification.
102+
103+
USAGE: swift-mod run [--mode <mode>] [--configuration <configuration>] [<paths> ...]
104+
105+
ARGUMENTS:
106+
<paths> Zero or more input filenames.
107+
108+
OPTIONS:
109+
-m, --mode <mode> Overrides running mode: modify|dry-run|check. (default: modify)
110+
-c, --configuration <configuration> The path to a configuration file.
111+
-h, --help Show help information.
112+
```
113+
114+
- `init`
115+
116+
```
117+
OVERVIEW: Generates a modify configuration file.
118+
119+
USAGE: swift-mod init [--output <output>]
106120
107-
- `init`: Generates a modify configuration file.
121+
OPTIONS:
122+
-o, --output <output> An output for the configuration file to be generated.
123+
-h, --help Show help information.
124+
```
108125

109-
|OPTION|SHORT|USAGE|
110-
|:-|:-|:-|
111-
|--output|-o|Path where the modify configuration should be generated|
126+
- `rules`
112127

113-
- `rules`: Display the list of rules and overview.
128+
```
129+
OVERVIEW: Display the list of rules.
114130
115-
|OPTION|SHORT|USAGE|
116-
|:-|:-|:-|
117-
|--detail|-d|A rule identifier to displaying detailed description|
131+
USAGE: swift-mod rules [--rule <rule>]
132+
133+
OPTIONS:
134+
-r, --rule <rule> A rule name to see detail.
135+
-h, --help Show help information.
136+
```
118137

119138
---
120139

@@ -124,7 +143,7 @@ Modification rules and targets are defines with YAML-formatted file. By default,
124143
Any file name is allowed with passing with option like follows:
125144

126145
```sh
127-
swift-mod --configuration your-config-file.yml
146+
swift-mod --configuration <configuration>
128147
```
129148

130149
### Example
@@ -133,25 +152,14 @@ swift-mod --configuration your-config-file.yml
133152
format:
134153
indent: 4
135154
lineBreakBeforeEachArgument: true
136-
targets:
137-
main:
138-
paths:
139-
- "**/main.swift"
140-
excludedPaths:
141-
- Modules/
142-
rules:
143-
defaultAccessLevel:
144-
accessLevel: internal
145-
implicitInternal: true
146-
module:
147-
paths:
148-
- Modules/
149-
rules:
150-
defaultAccessLevel:
151-
accessLevel: openOrPublic
152-
implicitInternal: true
153-
defaultMemberwiseInitializer:
154-
enabled: true
155+
rules:
156+
defaultAccessLevel:
157+
accessLevel: openOrPublic
158+
implicitInternal: true
159+
defaultMemberwiseInitializer:
160+
implicitInitializer: false
161+
implicitInternal: true
162+
ignoreClassesWithInheritance: false
155163
```
156164
157165
### Format
@@ -164,28 +172,8 @@ Format according to this setting only when changes occur.
164172
|indent|The number of spaces, or `tab` by text|Optional|4|
165173
|lineBreakBeforeEachArgument|Indicating whether to insert new lines before each function argument|Optional|true|
166174

167-
### Targets
168-
169-
Defines the several targets by name key that defines different paths or rules to apply.
170-
Glob paths are allowed for `paths` and `excludedPaths`.
171-
Each target can runs partially by command with option like follows:
172-
173-
```sh
174-
swift-mod --target [TARGET NAME]
175-
```
176-
177-
|KEY|VALUE|REQUIREMENT|DEFAULT|
178-
|:-|:-|:-|:-|
179-
|paths|The file names or paths to be applied rules. The directory is recursively lookup.|Required||
180-
|excludedPaths|The file name or paths to be ecluded from resolved `paths`|Optional|None|
181-
|rules|The set of rules to be applied|Required||
182-
183175
### Rules
184176

185-
Defines a modification rules enabled and its settings.
186-
All rules are opt-in.
187-
Rules where all settings are optional can specify only Boolean value indicating whether it's enabled by key `enabled`.
188-
189177
#### Default Access Level
190178

191179
|IDENTIFIER|OVERVIEW|
@@ -325,8 +313,7 @@ Run command:
325313
Pods/swift-mod/swift-mod [COMMAND] [OPTIONS]
326314
```
327315

328-
\* If you have changed the name of `Xcode.app` used in toolchain (`xcode-select -p`), `swift-mod` via CocoaPods can't be excuted. Please set the Xcode name to `Xcode.app`. (See: https://forums.swift.org/t/swiftsyntax-with-swift-5-1/29051)
329-
316+
\* If you have changed the name of `Xcode.app` used in toolchain (`xcode-select -p`), `swift-mod` via CocoaPods can't be excuted. Please set the Xcode name to `Xcode.app`. (See: <https://forums.swift.org/t/swiftsyntax-with-swift-5-1/29051>)
330317

331318
### Swift Version Support
332319

@@ -339,12 +326,8 @@ So you should use swift-mod version that built with compatible version of Swift
339326
|5.2 |0.0.4 |
340327
|5.3 |0.0.5 |
341328
|5.4 |0.0.6 |
342-
|5.5 |latest |
343-
344-
### Issue on macOS Before 10.14.4
345-
346-
Swift tool binary that works with static-stdlib can't running on macOS before 10.14.4.
347-
You need to update macOS or install the [Swift 5 Runtime Support for Command Line Tools](https://support.apple.com/kb/DL1998).
329+
|5.5 |0.0.7 |
330+
|5.6 |latest |
348331

349332
---
350333

@@ -366,12 +349,6 @@ In addition, swift-mod supports running on Linux, so you should test by installi
366349
make docker-test
367350
```
368351

369-
### Known Issue
370-
371-
Currently, swift-mod doesn't works properly with builds in `debug` configuration.
372-
It may due to stack overflow with tail recursion in the method that enumerating the Swift file paths.
373-
swift-mod works with optimizing tail recursion by builds in `release` configuration.
374-
375352
---
376353

377354
## License
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ArgumentParser
2+
import TSCBasic
3+
4+
public enum Mode: String, CaseIterable, ExpressibleByArgument {
5+
case modify
6+
case dryRun = "dry-run"
7+
case check
8+
}
9+
10+
extension AbsolutePath: ExpressibleByArgument {
11+
public init?(argument: String) {
12+
if let cwd = localFileSystem.currentWorkingDirectory {
13+
self.init(argument, relativeTo: cwd)
14+
}
15+
else {
16+
try? self.init(validating: argument)
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)