8000 custom_rules violations are not reported in a deterministic order · Issue #6058 · realm/SwiftLint · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

custom_rules violations are not reported in a deterministic order #6058

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

Open
2 tasks done
mildm8nnered opened this issue Apr 22, 2025 · 0 comments · May be fixed by #6057
Open
2 tasks done

custom_rules violations are not reported in a deterministic order #6058

mildm8nnered opened this issue Apr 22, 2025 · 0 comments · May be fixed by #6057
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@mildm8nnered
Copy link
Collaborator

New Issue Checklist

Bug Description

Given two custom rules, named aaa and bbb, with regexs matching their names (config follows below), and the following input:

let a = "aaa"
let b = "bbb"

and the following command:

$ swiftlint --quiet --config testconfig.yml test.swift --no-cache

The order that the violations are reported in is not deterministic:

% swiftlint --quiet --config testconfig.yml test.swift --no-cache
/Users/someone/Documents/Source/Scratch/test.swift:2:10: error: bbb Violation: No bbb allowed (bbb)
/Users/someone/Documents/Source/Scratch/test.swift:1:10: error: aaa Violation: No aaa allowed (aaa)
% swiftlint --quiet --config testconfig2.yml t3.swift --no-cache
/Users/someone/Documents/Source/Scratch/test.swift:1:10: error: aaa Violation: No aaa allowed (aaa)
/Users/someone/Documents/Source/Scratch/test.swift:2:10: error: bbb Violation: No bbb allowed (bbb)

It looks like the root of the problem is that custom_rules are stored in a dictionary, so the ordering from the configuration files is lost.

In CustomRules.swift, we build up the list of custom rules by iterating over a dictionary:

    mutating func apply(configuration: Any) throws {
        guard let configurationDict = configuration as? [String: Any] else {
            throw Issue.invalidConfiguration(ruleID: Parent.identifier)
        }

        for (key, value) in configurationDict {
            var ruleConfiguration = RegexConfiguration<Parent>(identifier: key)

            do {
                try ruleConfiguration.apply(configuration: value)
            } catch {
                Issue.invalidConfiguration(ruleID: key).print()
                continue
            }

            customRuleConfigurations.append(ruleConfiguration)
        }
    }

We should probably sort by name here, to match the way other rules are treated, which is a bit weird.

Environment

  • SwiftLint version (run swiftlint version to be sure)

0.59.1

  • Xcode version (run xcodebuild -version to be sure)
Xcode 16.1
Build version 16B40
  • Installation method used (Homebrew, CocoaPods, building from source, etc)

homebrew

  • Configuration file:
only_rules:
  - custom_rules

custom_rules:
  aaa:
    included: ".*.swift"
    name: aaa
    message: No aaa allowed
    regex: aaa
    severity: error
  bbb:
    included: ".*.swift"
    name: bbb
    message: No bbb allowed
    regex: bbb
    severity: error    

Are you using nested configurations?

No

@SimplyDanny SimplyDanny added the enhancement Ideas for improvements of existing features and rules. label Apr 23, 2025
@SimplyDanny SimplyDanny linked a pull request Apr 23, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0