Skip to content

Add rules to SARIF exporter - #6502

Merged
SimplyDanny merged 7 commits into
realm:mainfrom
ahmadalfy:main
Feb 23, 2026
Merged

SimplyDanny merged 7 commits into
realm:mainfrom
ahmadalfy:main

Conversation

@ahmadalfy

Copy link
Copy Markdown
Contributor

Summary

This PR enhances the SARIF reporter to include comprehensive rule metadata in the tool.driver.rules array, making the output fully compliant with the SARIF 2.1.0 specification.

Fixes #6499

Changes

  • Added rules array to SARIF output: The tool.driver.rules array now includes metadata for all 248 built-in SwiftLint rules
  • Each rule entry includes:
    • id: Rule identifier (e.g., line_length)
    • shortDescription: Human-readable rule name
    • fullDescription: Detailed rule description
    • helpUri: Direct link to rule documentation at https://realm.github.io/SwiftLint/{rule_id}.html
  • Renamed test reference file: Changed from .json to .sarif extension to follow SARIF naming conventions

Benefits

  1. Better tool integration: SARIF-compatible tools (GitHub Security, Datadog, etc.) can now display rich rule information alongside violations
  2. Improved developer experience: Users viewing SARIF reports get immediate access to rule documentation via helpUri
  3. Specification compliance: Output now conforms to SARIF best practices for static analysis tools

Example Output

{
  "tool": {
    "driver": {
      "name": "SwiftLint",
      "semanticVersion": "0.63.2",
      "informationUri": "https://github.com/realm/SwiftLint/blob/0.63.2/README.md",
      "rules": [
        {
          "id": "line_length",
          "shortDescription": {
            "text": "Line Length"
          },
          "fullDescription": {
            "text": "Lines should not span too many characters."
          },
          "helpUri": "https://realm.github.io/SwiftLint/line_length.html"
        },
        ...
      ]
    }
  },
  "results": [...]
}

Testing

  • All existing reporter tests pass
  • SARIF output validated against SARIF 2.1.0 schema
  • Verified with actual SwiftLint binary on test files
  • Updated test reference file includes all 248 rules

@SwiftLintBot

SwiftLintBot commented Feb 19, 2026 •

Copy link
Copy Markdown
19 Messages
📖 Building this branch resulted in a binary size of 27276.45 KiB vs 27274.32 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.82 s vs 0.81 s on main (1% slower).
📖 Linting Alamofire with this PR took 1.04 s vs 1.03 s on main (0% slower).
📖 Linting Brave with this PR took 7.18 s vs 7.16 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 25.54 s vs 25.45 s on main (0% slower).
📖 Linting Firefox with this PR took 11.76 s vs 11.74 s on main (0% slower).
📖 Linting Kickstarter with this PR took 8.03 s vs 8.02 s on main (0% slower).
📖 Linting Moya with this PR took 0.49 s vs 0.43 s on main (13% slower).
📖 Linting NetNewsWire with this PR took 2.46 s vs 2.43 s on main (1% slower).
📖 Linting Nimble with this PR took 0.71 s vs 0.69 s on main (2% slower).
📖 Linting PocketCasts with this PR took 7.63 s vs 7.59 s on main (0% slower).
📖 Linting Quick with this PR took 0.48 s vs 0.47 s on main (2% slower).
📖 Linting Realm with this PR took 3.02 s vs 3.02 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.87 s vs 1.88 s on main (0% faster).
📖 Linting Swift with this PR took 4.6 s vs 4.59 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.33 s vs 0.35 s on main (5% faster).
📖 Linting VLC with this PR took 1.18 s vs 1.17 s on main (0% slower).
📖 Linting Wire with this PR took 18.46 s vs 18.36 s on main (0% slower).
📖 Linting WordPress with this PR took 12.44 s vs 12.45 s on main (0% faster).

Generated by 🚫 Danger

@SimplyDanny SimplyDanny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! There is a more exhaustive way to get all effective rules though ...

@ahmadalfy

Copy link
Copy Markdown
Contributor Author

The test is failing because of the generated new rule "Foo Bar Baz" identified by 'foo_bar'.

It doesn't exist in the canned output. What do you suggest @SimplyDanny ?

@SimplyDanny

Copy link
Copy Markdown
Collaborator

The test is failing because of the generated new rule "Foo Bar Baz" identified by 'foo_bar'.

It doesn't exist in the canned output. What do you suggest @SimplyDanny ?

Independent of that, I don't like that all rules are now listed in the reference file. They could be omitted and the stringConverter make sure they are filtered out for the comparison. Then we could run a spot check to make sure rules are basically contained. There are easier solutions, but they all would keep the huge reference.

@ahmadalfy

Copy link
Copy Markdown
Contributor Author

Sounds good. I would suggest we test and validate that the rules are created with a valid structure before we remove them. If we just remove the rules array without checking it, we wouldn't be verifying that:

  • Rules are actually being added to the SARIF output
  • They have the correct structure (id, shortDescription, fullDescription, helpUri)
  • All registered rules are included (not an empty array or missing rules)

I will update this PR shortly

@ahmadalfy

Copy link
Copy Markdown
Contributor Author

@SimplyDanny all passed except this

Not sure what it means

@SimplyDanny

SimplyDanny commented Feb 22, 2026 •

Copy link
Copy Markdown
Collaborator

@SimplyDanny all passed except this

Not sure what it means

Danger doesn't like merge commits. Please rebase your branch instead.

@SimplyDanny
SimplyDanny enabled auto-merge (squash) February 22, 2026 21:00
ahmadalfy and others added 5 commits February 23, 2026 02:47
- Access RuleList.list.values instead of mapping RuleList directly
- Sort rules by identifier for consistent output ordering
- Update reference file to include all 250 rules (248 built-in + 2 core rules)
Validate rules array structure and remove it before comparison to keep
the reference file small.
auto-merge was automatically disabled February 23, 2026 00:48

Head branch was pushed to by a user without write access

@ahmadalfy

Copy link
Copy Markdown
Contributor Author

Done, all passed 🎉

Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
@SimplyDanny
SimplyDanny enabled auto-merge (squash) February 23, 2026 09:43
@SimplyDanny
SimplyDanny merged commit 21d66e5 into realm:main Feb 23, 2026
18 checks passed
nadeemnali pushed a commit to nadeemnali/SwiftLint that referenced this pull request Feb 26, 2026
nadeemnali pushed a commit to nadeemnali/SwiftLint that referenced this pull request Feb 26, 2026
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.

SARIF format cannot be imported into SonarQube

3 participants