From b532c2ae889f4a89efc0729efb8c455d34059972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 18 May 2024 16:24:37 +0200 Subject: [PATCH] Print only file path when reporting a correction Omit exact line and column information. Keep the internal logic available for a while in case people complain for good reasons. Then the change can be reverted easily. Reasons behind this change: * What is the position of a correction actually? The position where the rule triggered? The position of the transformed node? * If there's more than a single fix, it's highly likely that all positions (except for the first) are wrong no matter what the answer to the first question is. * Getting the positions right in a rewriter is hard. And there is always the feeling that something is wrong with them - probably because it is. * Even if you get the positions right in a single rule: One run collects positions for all rules that apply to a file and so rewrites in other rules might draw existing positions wrong. * We already have checks for more than one correction position disabled in tests due to these issues. --- CHANGELOG.md | 9 ++++++++- Source/SwiftLintCore/Models/Correction.swift | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 376c93f074c..56f69eb8bfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,14 @@ #### Breaking -* None. +* When SwiftLint corrects violations automatically (`swiftlint lint --fix`) + it doesn't report the exact location of the fix any longer. The new format + is `: Correcting ` without line and column numbers. + Reason: Correction positions are likely just incorrect, especially when + multiple rules apply their rewrites. Fixing that is not trivial and likely + not worth the effort also considering that there haven't been any bug + reports about wrong correction positions so far. + [SimplyDanny](https://github.com/SimplyDanny) #### Experimental diff --git a/Source/SwiftLintCore/Models/Correction.swift b/Source/SwiftLintCore/Models/Correction.swift index 1dcfa0842f7..44d9fa22d39 100644 --- a/Source/SwiftLintCore/Models/Correction.swift +++ b/Source/SwiftLintCore/Models/Correction.swift @@ -7,7 +7,7 @@ public struct Correction: Equatable, Sendable { /// The console-printable description for this correction. public var consoleDescription: String { - return "\(location) Corrected \(ruleDescription.name)" + return "\(location.file ?? ""): Corrected \(ruleDescription.name)" } /// Memberwise initializer.