Skip to content

oss-check writes an invalid config for projects that keep their own .swiftlint.yml #6933

Open

Description

@lechuckcaptain

New Issue Checklist

Bug Description

On a pull request that changes only rule files, the Danger step fails with exit status 2. It posts no comment. #6870 is an example.

This is what happens:

  1. tools/oss-check adds an only_rules list to each project's .swiftlint.yml.
  2. Brigade and SwiftLintPerformanceTests keep their own config. Both use opt_in_rules. SwiftLint does not accept both keys in one file, so it uses its default configuration:
    warning: 'disabled_rules' or 'opt_in_rules' cannot be used in combination with 'only_rules' – Falling back to default configuration
    
  3. The default configuration has no excluded: list. So SwiftLint lints Brigade's Reproducers/ directory, which Brigade excludes on purpose.
  4. A release build crashes on Reproducers/SIGILL-IdenticalOperands.swift. The report is empty.
  5. oss-check parses the empty report and crashes:
    JSON::ParserError: unexpected end of input at line 1 column 1
    	from tools/oss-check:286:in 'block in Object#diff_and_report_changes_to_danger'
    

Reproduction

With a release build of swiftlint, on my machine:

git clone --depth 1 https://github.com/Brett-Best/Brigade && cd Brigade
printf 'only_rules:\n  - no_magic_numbers\n' >> .swiftlint.yml
swiftlint lint --no-cache --reporter json > report.json; echo "exit $?"   # exit 132
wc -c < report.json                                                       # 0

Cause

Why some pull requests passed

#6870 passed Danger on 10 August. #6904 passed on 3 September. Both came after #6866. I could not find what changed on CI since then. This is what I know:

So the crash most likely depends on the machine that runs it. The fix below does not depend on this.

Suggested fix

  1. Pass --only-rule on the command line instead of editing the config. This flag ignores only_rules, opt_in_rules and disabled_rules, so it cannot conflict. Each project also keeps its excluded: list.
  2. Check each report before parsing it. If it is empty, show a warning with the project name.

Environment

  • SwiftLint main at d5156105b, release build with Bazel
  • Xcode 26.5, macOS 26.6, Apple Silicon

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions