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

Add checks documentation generator #16

Open
Jeehut opened this issue Apr 22, 2020 · 0 comments
Open

Add checks documentation generator #16

Jeehut opened this issue Apr 22, 2020 · 0 comments
Milestone

Comments

@Jeehut
Copy link
Member

Jeehut commented Apr 22, 2020

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) {
@Jeehut Jeehut changed the title Add rule documentation generator Add checks documentation generator Apr 22, 2020
@Jeehut Jeehut added this to the 1.0.0 milestone Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant