AnyLint
AnyLint copied to clipboard
Add checks documentation generator
At the moment, getting a good overview of all the rules within a config file is hard. Thereforew, it would be great if a different and more useful kind of representation of the rules could be rendered, like a Markdown, JSON or HTML file. Consider for example Markdown, then this file:
#!/usr/local/bin/swift-sh
import AnyLint // @Flinesoft ~> 0.4.0
try Lint.logSummaryAndExit(arguments: CommandLine.arguments) {
// MARK: - Variables
let swiftSourceFiles: Regex = #"^App/Sources/.*\.swift$"#
let swiftTestFiles: Regex = #"^Tests/Sources/.*\.swift$"#
let swiftUITestFiles: Regex = #"^UITests/Sources/.*\.swift$"#
let allSwiftFiles: [Regex] = [swiftSourceFiles, swiftTestFiles, swiftUITestFiles]
// MARK: - Checks
// MARK: HandySwiftDelayTimeInterval
try Lint.checkFileContents(
checkInfo: "HandySwiftDelayTimeInterval: Use one of the HandySwift TimeInterval extension methods like `.milliseconds(500)` instead.",
regex: #"(\sdelay\(by:\s*)([\.\d]+)([,\)])"#,
matchingExamples: [" delay(by: 15) {", " delay(by: 0.5, qosClass: .background) {", " delay(by: .5, qosClass: .utility) {"],
nonMatchingExamples: [" delay(by: .seconds(15.0)) {", " delay(by: .milliseconds(500), qosClass: .background) {", " updelay(by: 15.0)"],
includeFilters: allSwiftFiles,
autoCorrectReplacement: #"$1.seconds($2)$3"#,
autoCorrectExamples: [
["before": " delay(by: 15) {", "after": " delay(by: .seconds(15)) {"],
["before": " delay(by: 0.5, qosClass: .background) {", "after": " delay(by: .seconds(0.5), qosClass: .background) {"],
["before": " delay(by: .1, qosClass: .utility) {", "after": " delay(by: .seconds(.1), qosClass: .background) {"],
]
)
}
Might be rendered to this Markdown:
# lint.swift
The following checks are included in this file:
## Checks
### HandySwiftDelayTimeInterval
Use one of the HandySwift TimeInterval extension methods like `.milliseconds(500)` instead.
<details>
<summary>Matching Examples</summary>
``
delay(by: 15) {
``
``
delay(by: 0.5, qosClass: .background) {
``
``
delay(by: .5, qosClass: .utility) {
``
</details>
<details>
<summary>Non-matching Examples</summary>
``
delay(by: .seconds(15.0)) {
``
``
delay(by: .milliseconds(500), qosClass: .background) {
``
``
updelay(by: 15.0)
``
</details>
<details>
<summary>Auto-correct Examples</summary>
Before:
``
delay(by: 15) {
``
After:
``
delay(by: .seconds(15)) {
``
---
Before:
``
delay(by: 0.5, qosClass: .background) {
``
After:
``
delay(by: .seconds(0.5), qosClass: .background) {
``
---
Before:
``
delay(by: .1, qosClass: .utility) {
``
After:
``
delay(by: .seconds(.1), qosClass: .utility) {
``
</details>
Which would be rendered on sites like GitHub to this:
lint.swift
The following checks are included in this file:
Checks
HandySwiftDelayTimeInterval
Use one of the HandySwift TimeInterval extension methods like .milliseconds(500)
instead.
Matching Examples
delay(by: 15) {
delay(by: 0.5, qosClass: .background) {
delay(by: .5, qosClass: .utility) {
Non-matching Examples
delay(by: .seconds(15.0)) {
delay(by: .milliseconds(500), qosClass: .background) {
updelay(by: 15.0)
Auto-correct Examples
Before:
delay(by: 15) {
After:
delay(by: .seconds(15)) {
Before:
delay(by: 0.5, qosClass: .background) {
After:
delay(by: .seconds(0.5), qosClass: .background) {
Before:
delay(by: .1, qosClass: .utility) {
After:
delay(by: .seconds(.1), qosClass: .utility) {