Prepend `warning: ` to error messages (#4927)
This commit is contained in:
parent
a7bc9e20c7
commit
71b89e66de
|
@ -43,6 +43,10 @@
|
||||||
subclasses.
|
subclasses.
|
||||||
[AndrewDMontgomery](https://github.com/andrewdmontgomery)
|
[AndrewDMontgomery](https://github.com/andrewdmontgomery)
|
||||||
[#4875](https://github.com/realm/SwiftLint/pull/4875)
|
[#4875](https://github.com/realm/SwiftLint/pull/4875)
|
||||||
|
|
||||||
|
* Prepend `warning: ` to error messages so that they show in Xcode.
|
||||||
|
[whiteio](https://github.com/whiteio)
|
||||||
|
[#4923](https://github.com/realm/SwiftLint/issues/4923)
|
||||||
|
|
||||||
#### Bug Fixes
|
#### Bug Fixes
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import SwiftSyntax
|
||||||
|
|
||||||
private let warnDeprecatedOnceImpl: Void = {
|
private let warnDeprecatedOnceImpl: Void = {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
The `anyobject_protocol` rule is now deprecated and will be completely removed in a future release.
|
warning: The `anyobject_protocol` rule is now deprecated and will be completely removed in a future release.
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -264,7 +264,7 @@ private extension SwiftLintFile {
|
||||||
let response = try? Request.index(file: path, arguments: compilerArguments).sendIfNotDisabled()
|
let response = try? Request.index(file: path, arguments: compilerArguments).sendIfNotDisabled()
|
||||||
else {
|
else {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Could not index file at path '\(self.path ?? "...")' with the \
|
warning: Could not index file at path '\(self.path ?? "...")' with the \
|
||||||
\(CaptureVariableRule.description.identifier) rule.
|
\(CaptureVariableRule.description.identifier) rule.
|
||||||
""")
|
""")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,8 +2,8 @@ import SwiftSyntax
|
||||||
|
|
||||||
private let warnDeprecatedOnceImpl: Void = {
|
private let warnDeprecatedOnceImpl: Void = {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
The `\(InertDeferRule.description.identifier)` rule is now deprecated and will be completely \
|
warning: The `\(InertDeferRule.description.identifier)` rule is now deprecated and will be \
|
||||||
removed in a future release due to an equivalent warning issued by the Swift compiler.
|
completely removed in a future release due to an equivalent warning issued by the Swift compiler.
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct TypesafeArrayInitRule: AnalyzerRule, ConfigurationProviderRule {
|
||||||
}
|
}
|
||||||
guard compilerArguments.isNotEmpty else {
|
guard compilerArguments.isNotEmpty else {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Attempted to lint file at path '\(file.path ?? "...")' with the \
|
warning: Attempted to lint file at path '\(file.path ?? "...")' with the \
|
||||||
\(Self.description.identifier) rule without any compiler arguments.
|
\(Self.description.identifier) rule without any compiler arguments.
|
||||||
""")
|
""")
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -2,7 +2,7 @@ import SwiftSyntax
|
||||||
|
|
||||||
private let warnDeprecatedOnceImpl: Void = {
|
private let warnDeprecatedOnceImpl: Void = {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
The `\(UnusedCaptureListRule.description.identifier)` rule is now deprecated and will be completely \
|
warning: The `\(UnusedCaptureListRule.description.identifier)` rule is now deprecated and will be completely \
|
||||||
removed in a future release due to an equivalent warning issued by the Swift compiler.
|
removed in a future release due to an equivalent warning issued by the Swift compiler.
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
|
@ -35,7 +35,7 @@ struct UnusedDeclarationRule: ConfigurationProviderRule, AnalyzerRule, Collectin
|
||||||
func collectInfo(for file: SwiftLintFile, compilerArguments: [String]) -> UnusedDeclarationRule.FileUSRs {
|
func collectInfo(for file: SwiftLintFile, compilerArguments: [String]) -> UnusedDeclarationRule.FileUSRs {
|
||||||
guard compilerArguments.isNotEmpty else {
|
guard compilerArguments.isNotEmpty else {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Attempted to lint file at path '\(file.path ?? "...")' with the \
|
warning: Attempted to lint file at path '\(file.path ?? "...")' with the \
|
||||||
\(Self.description.identifier) rule without any compiler arguments.
|
\(Self.description.identifier) rule without any compiler arguments.
|
||||||
""")
|
""")
|
||||||
return .empty
|
return .empty
|
||||||
|
@ -43,7 +43,7 @@ struct UnusedDeclarationRule: ConfigurationProviderRule, AnalyzerRule, Collectin
|
||||||
|
|
||||||
guard let index = file.index(compilerArguments: compilerArguments), index.value.isNotEmpty else {
|
guard let index = file.index(compilerArguments: compilerArguments), index.value.isNotEmpty else {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Could not index file at path '\(file.path ?? "...")' with the \
|
warning: Could not index file at path '\(file.path ?? "...")' with the \
|
||||||
\(Self.description.identifier) rule.
|
\(Self.description.identifier) rule.
|
||||||
""")
|
""")
|
||||||
return .empty
|
return .empty
|
||||||
|
@ -52,7 +52,7 @@ struct UnusedDeclarationRule: ConfigurationProviderRule, AnalyzerRule, Collectin
|
||||||
guard let editorOpen = (try? Request.editorOpen(file: file.file).sendIfNotDisabled())
|
guard let editorOpen = (try? Request.editorOpen(file: file.file).sendIfNotDisabled())
|
||||||
.map(SourceKittenDictionary.init) else {
|
.map(SourceKittenDictionary.init) else {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Could not open file at path '\(file.path ?? "...")' with the \
|
warning: Could not open file at path '\(file.path ?? "...")' with the \
|
||||||
\(Self.description.identifier) rule.
|
\(Self.description.identifier) rule.
|
||||||
""")
|
""")
|
||||||
return .empty
|
return .empty
|
||||||
|
|
|
@ -86,7 +86,7 @@ struct UnusedImportRule: CorrectableRule, ConfigurationProviderRule, AnalyzerRul
|
||||||
private func importUsage(in file: SwiftLintFile, compilerArguments: [String]) -> [ImportUsage] {
|
private func importUsage(in file: SwiftLintFile, compilerArguments: [String]) -> [ImportUsage] {
|
||||||
guard compilerArguments.isNotEmpty else {
|
guard compilerArguments.isNotEmpty else {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Attempted to lint file at path '\(file.path ?? "...")' with the \
|
warning: Attempted to lint file at path '\(file.path ?? "...")' with the \
|
||||||
\(Self.description.identifier) rule without any compiler arguments.
|
\(Self.description.identifier) rule without any compiler arguments.
|
||||||
""")
|
""")
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -67,7 +67,7 @@ struct NameConfiguration: RuleConfiguration, Equatable {
|
||||||
self.validatesStartWithLowercase = validatesStartWithLowercase
|
self.validatesStartWithLowercase = validatesStartWithLowercase
|
||||||
} else if let validatesStartWithLowercase = configurationDict["validates_start_lowercase"] as? Bool {
|
} else if let validatesStartWithLowercase = configurationDict["validates_start_lowercase"] as? Bool {
|
||||||
self.validatesStartWithLowercase = validatesStartWithLowercase
|
self.validatesStartWithLowercase = validatesStartWithLowercase
|
||||||
queuedPrintError("\"validates_start_lowercase\" configuration was renamed to " +
|
queuedPrintError("warning: \"validates_start_lowercase\" configuration was renamed to " +
|
||||||
"\"validates_start_with_lowercase\" and will be removed in a future release.")
|
"\"validates_start_with_lowercase\" and will be removed in a future release.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ struct NestingConfiguration: RuleConfiguration, Equatable {
|
||||||
} else if let statementLevelConfiguration = configurationDict["statement_level"] {
|
} else if let statementLevelConfiguration = configurationDict["statement_level"] {
|
||||||
queuedPrintError(
|
queuedPrintError(
|
||||||
"""
|
"""
|
||||||
'statement_level' has been renamed to 'function_level' and will be completely removed in a future \
|
warning: 'statement_level' has been renamed to 'function_level' and will be completely removed \
|
||||||
release.
|
in a future release.
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
try functionLevel.apply(configuration: statementLevelConfiguration)
|
try functionLevel.apply(configuration: statementLevelConfiguration)
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct ExplicitSelfRule: CorrectableRule, ConfigurationProviderRule, AnalyzerRul
|
||||||
private func violationRanges(in file: SwiftLintFile, compilerArguments: [String]) -> [NSRange] {
|
private func violationRanges(in file: SwiftLintFile, compilerArguments: [String]) -> [NSRange] {
|
||||||
guard compilerArguments.isNotEmpty else {
|
guard compilerArguments.isNotEmpty else {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Attempted to lint file at path '\(file.path ?? "...")' with the \
|
warning: Attempted to lint file at path '\(file.path ?? "...")' with the \
|
||||||
\(Self.description.identifier) rule without any compiler arguments.
|
\(Self.description.identifier) rule without any compiler arguments.
|
||||||
""")
|
""")
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -109,7 +109,7 @@ extension Configuration {
|
||||||
return indentationStyle
|
return indentationStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
queuedPrintError("Invalid configuration for '\(Key.indentation)'. Falling back to default.")
|
queuedPrintError("warning: Invalid configuration for '\(Key.indentation)'. Falling back to default.")
|
||||||
return .default
|
return .default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ extension Configuration {
|
||||||
|
|
||||||
// Deprecation warning for "whitelist_rules"
|
// Deprecation warning for "whitelist_rules"
|
||||||
if dict[Key.whitelistRules.rawValue] != nil {
|
if dict[Key.whitelistRules.rawValue] != nil {
|
||||||
queuedPrintError("'\(Key.whitelistRules.rawValue)' has been renamed to " +
|
queuedPrintError("warning: '\(Key.whitelistRules.rawValue)' has been renamed to " +
|
||||||
"'\(Key.onlyRules.rawValue)' and will be completely removed in a " +
|
"'\(Key.onlyRules.rawValue)' and will be completely removed in a " +
|
||||||
"future release.")
|
"future release.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,9 @@ internal extension Configuration.FileGraph.FilePath {
|
||||||
|
|
||||||
private mutating func handleFileWriteFailure(urlString: String, cachedFilePath: String?) throws -> String {
|
private mutating func handleFileWriteFailure(urlString: String, cachedFilePath: String?) throws -> String {
|
||||||
if let cachedFilePath {
|
if let cachedFilePath {
|
||||||
queuedPrintError("Unable to cache remote config from \"\(urlString)\". Using cached version as a fallback.")
|
queuedPrintError(
|
||||||
|
"warning: Unable to cache remote config from \"\(urlString)\". Using cached version as a fallback."
|
||||||
|
)
|
||||||
self = .existing(path: cachedFilePath)
|
self = .existing(path: cachedFilePath)
|
||||||
return cachedFilePath
|
return cachedFilePath
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -134,7 +134,7 @@ public struct Configuration {
|
||||||
) {
|
) {
|
||||||
if let pinnedVersion, pinnedVersion != Version.current.value {
|
if let pinnedVersion, pinnedVersion != Version.current.value {
|
||||||
queuedPrintError(
|
queuedPrintError(
|
||||||
"Currently running SwiftLint \(Version.current.value) but " +
|
"warning: Currently running SwiftLint \(Version.current.value) but " +
|
||||||
"configuration specified version \(pinnedVersion)."
|
"configuration specified version \(pinnedVersion)."
|
||||||
)
|
)
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Foundation
|
||||||
import SourceKittenFramework
|
import SourceKittenFramework
|
||||||
|
|
||||||
private let warnSourceKitFailedOnceImpl: Void = {
|
private let warnSourceKitFailedOnceImpl: Void = {
|
||||||
queuedPrintError("SourceKit-based rules will be skipped because sourcekitd has failed.")
|
queuedPrintError("warning: SourceKit-based rules will be skipped because sourcekitd has failed.")
|
||||||
}()
|
}()
|
||||||
|
|
||||||
private func warnSourceKitFailedOnce() {
|
private func warnSourceKitFailedOnce() {
|
||||||
|
@ -245,8 +245,8 @@ public struct CollectedLinter {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (deprecatedIdentifier, identifier) in deprecatedToValidIdentifier {
|
for (deprecatedIdentifier, identifier) in deprecatedToValidIdentifier {
|
||||||
queuedPrintError("'\(deprecatedIdentifier)' rule has been renamed to '\(identifier)' and will be " +
|
queuedPrintError("warning: '\(deprecatedIdentifier)' rule has been renamed to '\(identifier)' and " +
|
||||||
"completely removed in a future release.")
|
"will be completely removed in a future release.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free some memory used for this file's caches. They shouldn't be needed after this point.
|
// Free some memory used for this file's caches. They shouldn't be needed after this point.
|
||||||
|
@ -288,7 +288,7 @@ public struct CollectedLinter {
|
||||||
|
|
||||||
if let parserDiagnostics = file.parserDiagnostics, parserDiagnostics.isNotEmpty {
|
if let parserDiagnostics = file.parserDiagnostics, parserDiagnostics.isNotEmpty {
|
||||||
queuedPrintError(
|
queuedPrintError(
|
||||||
"Skipping correcting file because it produced Swift parser errors: \(file.path ?? "<nopath>")"
|
"warning: Skipping correcting file because it produced Swift parser errors: \(file.path ?? "<nopath>")"
|
||||||
)
|
)
|
||||||
queuedPrintError(toJSON(["diagnostics": parserDiagnostics]))
|
queuedPrintError(toJSON(["diagnostics": parserDiagnostics]))
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -56,7 +56,7 @@ public struct RuleList {
|
||||||
initializedWithNonEmptyConfiguration: isConfigured
|
initializedWithNonEmptyConfiguration: isConfigured
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
queuedPrintError("Invalid configuration for '\(identifier)'. Falling back to default.")
|
queuedPrintError("warning: Invalid configuration for '\(identifier)'. Falling back to default.")
|
||||||
rules[identifier] = (ruleType.init(), false)
|
rules[identifier] = (ruleType.init(), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ struct CustomRulesConfiguration: RuleConfiguration, Equatable, CacheDescriptionP
|
||||||
do {
|
do {
|
||||||
try ruleConfiguration.apply(configuration: value)
|
try ruleConfiguration.apply(configuration: value)
|
||||||
} catch {
|
} catch {
|
||||||
queuedPrintError("Invalid configuration for custom rule '\(key)'.")
|
queuedPrintError("warning: Invalid configuration for custom rule '\(key)'.")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ extension SwiftLint {
|
||||||
var subPage = ""
|
var subPage = ""
|
||||||
if let ruleID {
|
if let ruleID {
|
||||||
if RuleRegistry.shared.rule(forID: ruleID) == nil {
|
if RuleRegistry.shared.rule(forID: ruleID) == nil {
|
||||||
queuedPrintError("There is no rule named '\(ruleID)'. Opening rule directory instead.")
|
queuedPrintError("warning: There is no rule named '\(ruleID)'. Opening rule directory instead.")
|
||||||
subPage = "rule-directory.html"
|
subPage = "rule-directory.html"
|
||||||
} else {
|
} else {
|
||||||
subPage = ruleID + ".html"
|
subPage = ruleID + ".html"
|
||||||
|
|
|
@ -155,7 +155,7 @@ extension Configuration {
|
||||||
let collected = await counter.next()
|
let collected = await counter.next()
|
||||||
if skipFile {
|
if skipFile {
|
||||||
queuedPrintError("""
|
queuedPrintError("""
|
||||||
Skipping '\(outputFilename)' (\(collected)/\(total)) \
|
warning: Skipping '\(outputFilename)' (\(collected)/\(total)) \
|
||||||
because its compiler arguments could not be found
|
because its compiler arguments could not be found
|
||||||
""")
|
""")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -273,7 +273,7 @@ private class LintOrAnalyzeResultBuilder {
|
||||||
do {
|
do {
|
||||||
try Data().write(to: URL(fileURLWithPath: outFile))
|
try Data().write(to: URL(fileURLWithPath: outFile))
|
||||||
} catch {
|
} catch {
|
||||||
queuedPrintError("Could not write to file at path \(outFile)")
|
queuedPrintError("warning: Could not write to file at path \(outFile)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ private extension LintOrAnalyzeOptions {
|
||||||
fileUpdater.write(Data((string + "\n").utf8))
|
fileUpdater.write(Data((string + "\n").utf8))
|
||||||
fileUpdater.closeFile()
|
fileUpdater.closeFile()
|
||||||
} catch {
|
} catch {
|
||||||
queuedPrintError("Could not write to file at path \(outFile)")
|
queuedPrintError("warning: Could not write to file at path \(outFile)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue