|
1 |
| - |
2 |
| -[](https://developer.apple.com/swift) |
3 |
| - |
| 1 | +[](https://developer.apple.com/swift) |
| 2 | + |
4 | 3 | [](https://swift.org/package-manager/)
|
5 | 4 | [](https://github.com/ikhvorost/swift-doc-coverage/actions/workflows/swift.yml)
|
6 | 5 | [](https://codecov.io/gh/ikhvorost/swift-doc-coverage)
|
| 6 | +[](https://github.com/ikhvorost/swift-doc-coverage) |
7 | 7 |
|
8 | 8 | [](https://www.paypal.com/donate/?hosted_button_id=TSPDD3ZAAH24C)
|
9 | 9 |
|
10 |
| -<p align="center"> |
11 |
| -<img src="swift-doc-coverage.png" alt="Swift Doc Coverage: Documentation coverage command-line utility for Swift files"> |
12 |
| -</p> |
13 |
| - |
14 | 10 | # Swift Doc Coverage
|
15 | 11 |
|
16 |
| -`swift-doc-coverage` generates documentation coverage statistics or warnings for Swift files and can be used from the command-line on macOS. |
| 12 | +`swift-doc-coverage` tool generates documentation coverage report for Swift files and can be used from the command-line on `macOS`. |
17 | 13 |
|
18 | 14 | ## Usage
|
19 | 15 |
|
20 |
| -The utility checks documentation for each declaration (class, structure, enumeration, protocol, type aliase, function, variable etc.) in swift files from provided path(s) and generate the coverage report. You can also provide a minimum access level (public, interval etc.) to include only needed declarations. |
| 16 | +The utility checks code documentation comments for each declaration (`class`, `struct`, `enum`, `protocol`, `func`, `typealias` etc.) in Swift files from provided path(s) and generates the documentation coverage report, Xcode warnings of json. |
21 | 17 |
|
22 |
| -```terminal |
23 |
| -$ swift-doc-coverage --help |
| 18 | +``` |
| 19 | +$ swift-doc-coverage -h |
24 | 20 | OVERVIEW: Generates documentation coverage statistics for Swift files.
|
25 | 21 |
|
26 |
| -USAGE: swift-doc-coverage [<inputs> ...] [--minimum-access-level <minimum-access-level>] [--report <report>] [--output <output>] |
| 22 | +USAGE: swift-doc-coverage <inputs> ... [--skips-hidden-files <skips-hidden-files>] [--ignore-regex <ignore-regex>] [--minimum-access-level <minimum-access-level>] [--report <report>] [--output <output>] |
27 | 23 |
|
28 | 24 | ARGUMENTS:
|
29 |
| - <inputs> One or more paths to a directory containing Swift files. |
| 25 | + <inputs> One or more paths to directories or Swift files. |
30 | 26 |
|
31 | 27 | OPTIONS:
|
| 28 | + -s, --skips-hidden-files <skips-hidden-files> |
| 29 | + An option to skip hidden files. (default: true) |
| 30 | + -i, --ignore-regex <ignore-regex> |
| 31 | + Skip source code files with file paths that match the |
| 32 | + given regular expression. |
32 | 33 | -m, --minimum-access-level <minimum-access-level>
|
33 |
| - The minimum access level of the symbols considered for coverage statistics: open, public, internal, fileprivate, private. (default: public) |
34 |
| - -r, --report <report> Report modes: statistics, warnings, json. (default: statistics) |
| 34 | + The minimum access level of the symbols considered |
| 35 | + for coverage statistics: open, public, internal, |
| 36 | + fileprivate, private. (default: public) |
| 37 | + -r, --report <report> Report modes: coverage, warnings, json. (default: |
| 38 | + coverage) |
35 | 39 | -o, --output <output> The file path for generated report.
|
36 | 40 | --version Show the version.
|
37 | 41 | -h, --help Show help information.
|
38 | 42 | ```
|
39 | 43 |
|
40 |
| -### Statistics report |
| 44 | +### Documentation coverage |
41 | 45 |
|
42 |
| -```terminal |
43 |
| -$ swift-doc-coverage ./Rect --report statistics --minimum-access-level internal |
44 |
| -1) ./Rect/Rect.swift: 50% [2/4] |
| 46 | +To get the documentation coverage report of Swift files in your directory for `public` access level and above (`open`) you can simple run: |
| 47 | + |
| 48 | +``` |
| 49 | +$ swift-doc-coverage ./Resources |
| 50 | +1) /Resources/Rect/Rect.swift: 50% [1/2] (0.013s) |
45 | 51 | Undocumented:
|
46 |
| -<Rect.swift:9:5> Rect.size |
47 |
| -<Rect.swift:12:5> Rect.center |
| 52 | +<Rect.swift:14:3> var Rect.center |
48 | 53 |
|
49 |
| -2) ./Rect/CompactRect.swift: 0% [0/4] |
| 54 | +2) /Resources/Size.swift: 0% [0/1] (0.002s) |
50 | 55 | Undocumented:
|
51 |
| -<CompactRect.swift:3:1> CompactRect |
52 |
| -<CompactRect.swift:4:5> CompactRect.origin |
53 |
| -<CompactRect.swift:5:5> CompactRect.size |
54 |
| -<CompactRect.swift:6:5> CompactRect.center |
| 56 | +<Size.swift:3:1> struct Size |
55 | 57 |
|
56 |
| -3) ./Rect/AlternativeRect.swift: 0% [0/4] |
| 58 | +3) /Resources/Point.swift: 0% [0/1] (0.002s) |
57 | 59 | Undocumented:
|
58 |
| -<AlternativeRect.swift:3:1> AlternativeRect |
59 |
| -<AlternativeRect.swift:4:5> AlternativeRect.origin |
60 |
| -<AlternativeRect.swift:5:5> AlternativeRect.size |
61 |
| -<AlternativeRect.swift:6:5> AlternativeRect.center |
| 60 | +<Point.swift:3:1> struct Point |
| 61 | +
|
62 | 62 |
|
63 |
| -Total: 16% [2/12] |
| 63 | +Total: 25% [1/4] (0.023s) |
64 | 64 | ```
|
65 | 65 |
|
66 | 66 | Where:
|
67 |
| -- \<Rect.swift:9:5\> - location in format "filename:line:column" |
68 |
| -- Rect.size - declaration name |
69 |
| - |
70 |
| -### JSON report |
| 67 | +- `file:///Resources/Rect/Rect.swift` - file path to a found Swift file |
| 68 | +- `50%` - documentation coverage in percents |
| 69 | +- `[1/2]` - documented declarations count vs all found declarations count |
| 70 | +- `(0.013s)` - a processing time |
| 71 | +- `<Rect.swift:14:3>` - a declaration location in format `<filename:line:column>` |
| 72 | +- `var Rect.center` - a declaration name |
71 | 73 |
|
72 |
| -It's possible to obtain documentation coverage statistics in JSON format: |
73 |
| - |
74 |
| -```terminal |
75 |
| -$ swift-doc-coverage ./Rect.swift -r json -m public -o ./Rect.json |
76 |
| -``` |
77 |
| -Rect.json: |
78 |
| -```json |
79 |
| -{ |
80 |
| - "sources" : [ |
81 |
| - { |
82 |
| - "path" : "./Rect.swift", |
83 |
| - "totalCount" : 4, |
84 |
| - "undocumented" : [ |
85 |
| - { |
86 |
| - "line" : 9, |
87 |
| - "name" : "Rect.size", |
88 |
| - "column" : 5 |
89 |
| - }, |
90 |
| - { |
91 |
| - "line" : 12, |
92 |
| - "name" : "Rect.center", |
93 |
| - "column" : 5 |
94 |
| - } |
95 |
| - ] |
96 |
| - } |
97 |
| - ] |
98 |
| -} |
99 |
| -``` |
| 74 | +You can also provide an other minimum access levels (`private`, `interval` etc.) to get documentation coverage for more declarations in your code. |
100 | 75 |
|
| 76 | +### Xcode warnings |
101 | 77 |
|
102 |
| -### XCode |
| 78 | +You can integrate the utility into your Xcode project to generate warnings for undocumented declarations by adding a build phase script: |
103 | 79 |
|
104 |
| -You can intergate the utility in your XCode project to generate warnings for undocumented declarations by adding a build phase script: `Your Target` > `Build Phases` > `Add a new buid phase` |
| 80 | +`Your Target` > `Build Phases` > `Add Run Script Phase` |
105 | 81 |
|
106 | 82 | ```terminal
|
107 | 83 | swift-doc-coverage "${SOURCE_ROOT}" --report warnings
|
108 | 84 | ```
|
109 | 85 |
|
110 |
| -After running the build command you can see next warnings in XCode: |
| 86 | +After running `Product` > `Build` command you can see next warnings in Xcode: |
111 | 87 |
|
112 | 88 | ```
|
113 |
| -⚠️ No documentation for 'logger'. |
114 |
| -⚠️ No documentation for 'MyClass'. |
115 |
| -⚠️ No documentation for 'MyClass.hello()'. |
116 |
| -⚠️ No documentation for 'MyClass.init()'. |
117 |
| -... |
| 89 | +⚠️ No documentation for 'var Rect.center'. |
| 90 | +⚠️ No documentation for 'struct Size'. |
| 91 | +⚠️ No documentation for 'struct Point'. |
118 | 92 | ```
|
119 | 93 |
|
120 |
| -> Swift Package Manager: Package.swift doesn't support adding build phase scripts so you need to run the utility manually for your package's folder or convert the package to XCode project. |
121 |
| -
|
122 |
| -## Installation |
123 |
| - |
124 |
| -### Manually |
| 94 | +### JSON |
125 | 95 |
|
126 |
| -To install the tool run next single command (using `curl`): |
| 96 | +It's possible to obtain all Swift declarations of your code in JSON format: |
127 | 97 |
|
128 |
| -```terminal |
129 |
| -$ bash <(curl -s https://raw.githubusercontent.com/ikhvorost/swift-doc-coverage/main/install.sh) |
| 98 | +``` |
| 99 | +$ swift-doc-coverage ./Rect -r json |
| 100 | +[ |
| 101 | + { |
| 102 | + "url" : "file:///Rect/Rect.swift", |
| 103 | + "declarations" : [ |
| 104 | + { |
| 105 | + "name" : "struct Rect", |
| 106 | + "column" : 1, |
| 107 | + "accessLevel" : 0, |
| 108 | + "keyword" : "struct", |
| 109 | + "comments" : [ |
| 110 | + { |
| 111 | + "isDoc" : true, |
| 112 | + "text" : "Doc line" |
| 113 | + } |
| 114 | + ], |
| 115 | + "line" : 4 |
| 116 | + }, |
| 117 | + { |
| 118 | + "column" : 3, |
| 119 | + "line" : 5, |
| 120 | + "comments" : [ |
| 121 | + ], |
| 122 | + "accessLevel" : 3, |
| 123 | + "name" : "let Rect.index", |
| 124 | + "keyword" : "let" |
| 125 | + }, |
| 126 | + { |
| 127 | + "name" : "var Rect.origin", |
| 128 | + "line" : 8, |
| 129 | + "column" : 3, |
| 130 | + "comments" : [ |
| 131 | + { |
| 132 | + "isDoc" : true, |
| 133 | + "text" : "Doc block" |
| 134 | + } |
| 135 | + ], |
| 136 | + "keyword" : "var", |
| 137 | + "accessLevel" : 4 |
| 138 | + }, |
| 139 | + { |
| 140 | + "accessLevel" : 2, |
| 141 | + "line" : 11, |
| 142 | + "comments" : [ |
| 143 | + { |
| 144 | + "text" : "Comment line", |
| 145 | + "isDoc" : false |
| 146 | + } |
| 147 | + ], |
| 148 | + "keyword" : "var", |
| 149 | + "column" : 3, |
| 150 | + "name" : "var Rect.size" |
| 151 | + }, |
| 152 | + { |
| 153 | + "name" : "var Rect.center", |
| 154 | + "column" : 3, |
| 155 | + "line" : 14, |
| 156 | + "keyword" : "var", |
| 157 | + "accessLevel" : 1, |
| 158 | + "comments" : [ |
| 159 | + { |
| 160 | + "text" : "Comment block", |
| 161 | + "isDoc" : false |
| 162 | + } |
| 163 | + ] |
| 164 | + } |
| 165 | + ] |
| 166 | + } |
| 167 | +] |
130 | 168 | ```
|
131 | 169 |
|
132 |
| -OR: |
| 170 | +## Installation |
133 | 171 |
|
134 |
| -```terminal |
135 |
| -$ git clone https://github.com/ikhvorost/swift-doc-coverage.git |
136 |
| -$ cd swift-doc-coverage |
137 |
| -$ sudo make install |
| 172 | +To install the tool just run the following commands in Terminal: |
| 173 | + |
| 174 | +``` |
| 175 | +git clone https://github.com/ikhvorost/swift-doc-coverage.git |
| 176 | +cd swift-doc-coverage |
| 177 | +sudo make install |
138 | 178 | ```
|
139 | 179 |
|
140 | 180 | ## License
|
|
0 commit comments