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

Trigger superfluous_disable_command for custom_rules #4755

Merged
merged 8 commits into from
Nov 7, 2023

Conversation

marcelofabri
Copy link
Collaborator

@marcelofabri marcelofabri commented Feb 7, 2023

Fixes #4754

Need to write tests, but wanna make sure nothing breaks horribly first.

@marcelofabri marcelofabri force-pushed the marcelo/custom-rules-disable branch from 04e2b94 to 05c948b Compare February 7, 2023 23:27
@SwiftLintBot
Copy link

SwiftLintBot commented Feb 7, 2023

16 Messages
📖 Linting Aerial with this PR took 1.19s vs 1.18s on main (0% slower)
📖 Linting Alamofire with this PR took 1.55s vs 1.57s on main (1% faster)
📖 Linting Brave with this PR took 8.94s vs 8.93s on main (0% slower)
📖 Linting DuckDuckGo with this PR took 4.49s vs 4.48s on main (0% slower)
📖 Linting Firefox with this PR took 10.39s vs 10.41s on main (0% faster)
📖 Linting Kickstarter with this PR took 11.01s vs 11.0s on main (0% slower)
📖 Linting Moya with this PR took 0.61s vs 0.62s on main (1% faster)
📖 Linting NetNewsWire with this PR took 3.27s vs 3.27s on main (0% slower)
📖 Linting Nimble with this PR took 0.82s vs 0.82s on main (0% slower)
📖 Linting PocketCasts with this PR took 8.76s vs 8.79s on main (0% faster)
📖 Linting Quick with this PR took 0.4s vs 0.39s on main (2% slower)
📖 Linting Realm with this PR took 11.5s vs 11.49s on main (0% slower)
📖 Linting Sourcery with this PR took 2.81s vs 2.82s on main (0% faster)
📖 Linting VLC with this PR took 1.55s vs 1.55s on main (0% slower)
📖 Linting Wire with this PR took 19.65s vs 19.56s on main (0% slower)
📖 Linting WordPress with this PR took 13.3s vs 13.32s on main (0% faster)

Generated by 🚫 Danger

@mildm8nnered
Copy link
Collaborator

@marcelofabri
Copy link
Collaborator Author

Damn - I was hoping I'd beat you to it, lol - https://github.com/realm/SwiftLint/compare/main...mildm8nnered:mildm8nnered-fix-superfluous_disable_command_for_custom_rules?expand=1

feel free to take over! idk when i'll have the time to continue/write tests for this

@mildm8nnered
Copy link
Collaborator

So I came up with this, which I added to CustomRulesTests on my branch - feel free to steal it.

    func testSuperfluousDisableCommandWithCustomRules() {
        let customRulesConfiguration: [String:Any] = [
            "custom1": [
                "regex": "pattern",
                "match_kinds": "comment"
            ]
        ]
        
        let example = Example(
            "// swiftlint:disable custom1\n",
            configuration: customRulesConfiguration
        ).skipWrappingInCommentTest()
        let configuration = try! Configuration(dict: ["custom_rules": customRulesConfiguration])
        let violations = violations(example, config: configuration)
        
        XCTAssertEqual(violations.count, 1)
        XCTAssertTrue(violations.allSatisfy { $0.ruleIdentifier == "superfluous_disable_command" })
    }

@marcelofabri marcelofabri force-pushed the marcelo/custom-rules-disable branch from 05c948b to bf38d33 Compare February 9, 2023 10:11
@marcelofabri
Copy link
Collaborator Author

Thanks @mildm8nnered! I've added this test and also another more complex one based on it - I think this is ready for review

@marcelofabri marcelofabri marked this pull request as ready for review February 9, 2023 10:12
@SimplyDanny SimplyDanny requested a review from mildm8nnered March 2, 2023 21:22
@marcosgriselli
Copy link

Is there anything we can help with to push this forward?

@marcelofabri marcelofabri force-pushed the marcelo/custom-rules-disable branch from f1531e6 to 1100c7c Compare November 7, 2023 08:40
@marcelofabri marcelofabri enabled auto-merge (squash) November 7, 2023 09:01
@marcelofabri marcelofabri merged commit 7499896 into main Nov 7, 2023
@marcelofabri marcelofabri deleted the marcelo/custom-rules-disable branch November 7, 2023 09:12
@keith
Copy link
Collaborator

keith commented Nov 7, 2023

With this commit I just get a violations for all my custom rules. For example with this code:

        // swiftlint:disable:next use_stroke_colors
        view.layer.borderColor = Color.clear.cgColor

and this regex rule:

  use_stroke_colors:
    name: "Use palette stroke colors instead of spectrum colors wherever possible."
    regex: '(?:border|stroke)Color = (?:(?:UI|CG)?Color)?\.(?!stroke|always|pink)'
    excluded: "Modules/something"

I just see this warning all the time:

error: Superfluous Disable Command Violation: SwiftLint rule 'use_stroke_colors' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)

Lmk if you want a separate issue instead! Reverting this does fix it though

@marcelofabri
Copy link
Collaborator Author

huh, that's weird. I'll take a look later today and try to fix it forward. If I can't do it today/tomorrow I'll revert this PR. Thanks for letting us know!

u-abyss pushed a commit to u-abyss/SwiftLint that referenced this pull request Dec 16, 2023
u-abyss pushed a commit to u-abyss/SwiftLint that referenced this pull request Dec 16, 2023
MartijnAmbagtsheer pushed a commit to MartijnAmbagtsheer/SwiftLint that referenced this pull request Dec 20, 2023
MartijnAmbagtsheer pushed a commit to MartijnAmbagtsheer/SwiftLint that referenced this pull request Dec 20, 2023
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

Successfully merging this pull request may close these issues.

superfluous_disable_command not triggering for custom rule
6 participants