realm / realm/SwiftLint

Add --fail-on-unfixable flag for single-pass fix + validation

Open
#6,450 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

Problem

When using swiftlint --fix, the command always returns exit code 0, even when unfixable violations remain. This forces users to run SwiftLint twice in CI/pre-commit hooks:

swiftlint --fix && swiftlint --strict

This doubles the execution time for files with violations.

Proposed Solution

Add a new flag --fail-on-unfixable (or --strict-fix) that:

  1. Performs auto-correction as usual
  2. Returns non-zero exit code if any violations couldn't be auto-fixed
  3. Optionally outputs the unfixable violations to stderr

Use Case

Pre-commit hooks and CI pipelines that want to:

  • Auto-fix what can be fixed
  • Block commits/builds when manual intervention is required
  • Do this in a single SwiftLint invocation

Current Workaround

Using swiftlint --fix && swiftlint --strict, but this is suboptimal for large codebases and adds unnecessary latency to developer workflows.

Example Usage

# Current (two passes)
swiftlint --fix --config .swiftlint.yml file.swift
swiftlint --strict --config .swiftlint.yml file.swift

# Proposed (single pass)
swiftlint --fix --fail-on-unfixable --config .swiftlint.yml file.swift

Related Issues

  • #5387 - Discussion about --strict --fix behavior

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SwiftLint command-line handling for --fix and compare it with the behavior discussed in related issue #5387. Verify the proposed single-pass invocation against the current two-pass workaround, including the exit status and any output for remaining violations. Done means auto-fixable violations are corrected and unfixable violations produce a non-zero result.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.