From 01f5ecd64a696468f90a1489f8ab1ac9adf0d6ff Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Sat, 26 Oct 2024 14:46:03 +0100 Subject: [PATCH 1/5] Replace `description.identifier` with `identifier` (#5837) --- .../Rules/Lint/CaptureVariableRule.swift | 2 +- .../Rules/Lint/InertDeferRule.swift | 2 +- .../Rules/Lint/TypesafeArrayInitRule.swift | 2 +- .../Rules/Lint/UnusedCaptureListRule.swift | 2 +- .../Rules/Lint/UnusedDeclarationRule.swift | 6 +++--- .../Rules/Lint/UnusedImportRule.swift | 8 ++++---- .../Rules/Style/ExplicitSelfRule.swift | 4 ++-- .../Documentation/RuleDocumentation.swift | 6 +++--- .../Extensions/Configuration+Cache.swift | 2 +- .../Extensions/Configuration+Parsing.swift | 2 +- .../Extensions/Configuration+RulesMode.swift | 2 +- .../Configuration+RulesWrapper.swift | 16 ++++++++-------- .../ChildOptionSeverityConfiguration.swift | 2 +- .../SwiftLintCore/Models/Configuration.swift | 4 ++-- ...shableConfigurationRuleWrapperWrapper.swift | 6 +++--- Source/SwiftLintCore/Models/Linter.swift | 6 +++--- Source/SwiftLintCore/Models/RuleList.swift | 2 +- .../RegexConfiguration.swift | 6 +++--- Source/SwiftLintCore/Rules/CustomRules.swift | 6 +++--- Source/SwiftLintFramework/RulesFilter.swift | 2 +- Tests/CLITests/RulesFilterTests.swift | 10 +++++----- .../CompilerProtocolInitRuleTests.swift | 2 +- .../ComputedAccessorsOrderRuleTests.swift | 2 +- .../ConfigurationAliasesTests.swift | 2 +- .../ConfigurationTests+MultipleConfigs.swift | 18 +++++++++--------- .../ConfigurationTests.swift | 10 +++++----- .../ContainsOverFirstNotNilRuleTests.swift | 2 +- .../CustomRulesTests.swift | 6 +++--- ...yclomaticComplexityConfigurationTests.swift | 2 +- .../DeploymentTargetConfigurationTests.swift | 2 +- .../DeploymentTargetRuleTests.swift | 2 +- .../ExpiringTodoRuleTests.swift | 2 +- ...plicitTypeInterfaceConfigurationTests.swift | 4 ++-- .../FunctionBodyLengthRuleTests.swift | 2 +- .../ImplicitGetterRuleTests.swift | 4 ++-- .../ImplicitReturnConfigurationTests.swift | 2 +- ...lyUnwrappedOptionalConfigurationTests.swift | 2 +- .../IndentationWidthRuleTests.swift | 2 +- .../LineLengthConfigurationTests.swift | 4 ++-- .../ModifierOrderTests.swift | 2 +- .../NameConfigurationTests.swift | 2 +- .../NestingRuleTests.swift | 4 ++-- .../NoEmptyBlockConfigurationTests.swift | 4 ++-- .../RuleConfigurationTests.swift | 10 +++++----- .../TodoRuleTests.swift | 2 +- .../TrailingCommaRuleTests.swift | 2 +- .../VerticalWhitespaceRuleTests.swift | 2 +- .../XCTSpecificMatcherRuleTests.swift | 2 +- Tests/SwiftLintTestHelpers/TestHelpers.swift | 6 +++--- 49 files changed, 102 insertions(+), 102 deletions(-) diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/CaptureVariableRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/CaptureVariableRule.swift index 10c4d6b20a..bbf8d915ff 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/CaptureVariableRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/CaptureVariableRule.swift @@ -264,7 +264,7 @@ private extension SwiftLintFile { let path = self.path, let response = try? Request.index(file: path, arguments: compilerArguments).sendIfNotDisabled() else { - Issue.indexingError(path: path, ruleID: CaptureVariableRule.description.identifier).print() + Issue.indexingError(path: path, ruleID: CaptureVariableRule.identifier).print() return nil } diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/InertDeferRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/InertDeferRule.swift index abecbf32c6..87a8775ebd 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/InertDeferRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/InertDeferRule.swift @@ -2,7 +2,7 @@ import SwiftSyntax // TODO: [12/23/2024] Remove deprecation warning after ~2 years. private let warnDeprecatedOnceImpl: Void = { - Issue.ruleDeprecated(ruleID: InertDeferRule.description.identifier).print() + Issue.ruleDeprecated(ruleID: InertDeferRule.identifier).print() }() private func warnDeprecatedOnce() { diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift index faa619e479..fb353a8ac6 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/TypesafeArrayInitRule.swift @@ -67,7 +67,7 @@ struct TypesafeArrayInitRule: AnalyzerRule { return [] } guard compilerArguments.isNotEmpty else { - Issue.missingCompilerArguments(path: file.path, ruleID: Self.description.identifier).print() + Issue.missingCompilerArguments(path: file.path, ruleID: Self.identifier).print() return [] } return Self.parentRule.validate(file: file) diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift index d8ce4a85be..445aba6edf 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedCaptureListRule.swift @@ -2,7 +2,7 @@ import SwiftSyntax // TODO: [12/22/2024] Remove deprecation warning after ~2 years. private let warnDeprecatedOnceImpl: Void = { - Issue.ruleDeprecated(ruleID: UnusedCaptureListRule.description.identifier).print() + Issue.ruleDeprecated(ruleID: UnusedCaptureListRule.identifier).print() }() private func warnDeprecatedOnce() { diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedDeclarationRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedDeclarationRule.swift index d851ab72c0..33e3d23556 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedDeclarationRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedDeclarationRule.swift @@ -30,18 +30,18 @@ struct UnusedDeclarationRule: AnalyzerRule, CollectingRule { func collectInfo(for file: SwiftLintFile, compilerArguments: [String]) -> Self.FileUSRs { guard compilerArguments.isNotEmpty else { - Issue.missingCompilerArguments(path: file.path, ruleID: Self.description.identifier).print() + Issue.missingCompilerArguments(path: file.path, ruleID: Self.identifier).print() return .empty } guard let index = file.index(compilerArguments: compilerArguments), index.value.isNotEmpty else { - Issue.indexingError(path: file.path, ruleID: Self.description.identifier).print() + Issue.indexingError(path: file.path, ruleID: Self.identifier).print() return .empty } guard let editorOpen = (try? Request.editorOpen(file: file.file).sendIfNotDisabled()) .map(SourceKittenDictionary.init) else { - Issue.fileNotReadable(path: file.path, ruleID: Self.description.identifier).print() + Issue.fileNotReadable(path: file.path, ruleID: Self.identifier).print() return .empty } diff --git a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedImportRule.swift b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedImportRule.swift index 175a6cb40c..6e1951a482 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedImportRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Lint/UnusedImportRule.swift @@ -84,7 +84,7 @@ struct UnusedImportRule: CorrectableRule, AnalyzerRule { private func importUsage(in file: SwiftLintFile, compilerArguments: [String]) -> [ImportUsage] { guard compilerArguments.isNotEmpty else { - Issue.missingCompilerArguments(path: file.path, ruleID: Self.description.identifier).print() + Issue.missingCompilerArguments(path: file.path, ruleID: Self.identifier).print() return [] } @@ -178,7 +178,7 @@ private extension SwiftLintFile { file: path!, offset: token.offset, arguments: compilerArguments ) guard let cursorInfo = (try? cursorInfoRequest.sendIfNotDisabled()).map(SourceKittenDictionary.init) else { - Issue.missingCursorInfo(path: path, ruleID: UnusedImportRule.description.identifier).print() + Issue.missingCursorInfo(path: path, ruleID: UnusedImportRule.identifier).print() continue } if nextIsModuleImport { @@ -213,7 +213,7 @@ private extension SwiftLintFile { func operatorImports(arguments: [String], processedTokenOffsets: Set) -> Set { guard let index = (try? Request.index(file: path!, arguments: arguments).sendIfNotDisabled()) .map(SourceKittenDictionary.init) else { - Issue.indexingError(path: path, ruleID: UnusedImportRule.description.identifier).print() + Issue.indexingError(path: path, ruleID: UnusedImportRule.identifier).print() return [] } @@ -236,7 +236,7 @@ private extension SwiftLintFile { ) guard let cursorInfo = (try? cursorInfoRequest.sendIfNotDisabled()) .map(SourceKittenDictionary.init) else { - Issue.missingCursorInfo(path: path, ruleID: UnusedImportRule.description.identifier).print() + Issue.missingCursorInfo(path: path, ruleID: UnusedImportRule.identifier).print() continue } diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/ExplicitSelfRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/ExplicitSelfRule.swift index 5aa83a05ed..7d86574842 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/ExplicitSelfRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/ExplicitSelfRule.swift @@ -42,7 +42,7 @@ struct ExplicitSelfRule: CorrectableRule, AnalyzerRule { private func violationRanges(in file: SwiftLintFile, compilerArguments: [String]) -> [NSRange] { guard compilerArguments.isNotEmpty else { - Issue.missingCompilerArguments(path: file.path, ruleID: Self.description.identifier).print() + Issue.missingCompilerArguments(path: file.path, ruleID: Self.identifier).print() return [] } @@ -69,7 +69,7 @@ struct ExplicitSelfRule: CorrectableRule, AnalyzerRule { return cursorsMissingExplicitSelf.compactMap { cursorInfo in guard let byteOffset = (cursorInfo["swiftlint.offset"] as? Int64).flatMap(ByteCount.init) else { - Issue.genericWarning("Cannot convert offsets in '\(Self.description.identifier)' rule.").print() + Issue.genericWarning("Cannot convert offsets in '\(Self.identifier)' rule.").print() return nil } diff --git a/Source/SwiftLintCore/Documentation/RuleDocumentation.swift b/Source/SwiftLintCore/Documentation/RuleDocumentation.swift index c47a5d8383..00dd8f35e8 100644 --- a/Source/SwiftLintCore/Documentation/RuleDocumentation.swift +++ b/Source/SwiftLintCore/Documentation/RuleDocumentation.swift @@ -31,10 +31,10 @@ struct RuleDocumentation { var ruleName: String { ruleType.description.name } /// The identifier of the documented rule. - var ruleIdentifier: String { ruleType.description.identifier } + var ruleIdentifier: String { ruleType.identifier } /// The name of the file on disk for this rule documentation. - var fileName: String { "\(ruleType.description.identifier).md" } + var fileName: String { "\(ruleType.identifier).md" } /// The contents of the file for this rule documentation. var fileContents: String { @@ -81,7 +81,7 @@ private func h2(_ text: String) -> String { "## \(text)" } private func detailsSummary(_ rule: some Rule) -> String { let ruleDescription = """ - * **Identifier:** `\(type(of: rule).description.identifier)` + * **Identifier:** `\(type(of: rule).identifier)` * **Enabled by default:** \(rule is any OptInRule ? "No" : "Yes") * **Supports autocorrection:** \(rule is any CorrectableRule ? "Yes" : "No") * **Kind:** \(type(of: rule).description.kind) diff --git a/Source/SwiftLintCore/Extensions/Configuration+Cache.swift b/Source/SwiftLintCore/Extensions/Configuration+Cache.swift index 56debce0ce..c3e575a8b4 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+Cache.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+Cache.swift @@ -60,7 +60,7 @@ extension Configuration { } let cacheRulesDescriptions = rules - .map { rule in [type(of: rule).description.identifier, rule.cacheDescription] } + .map { rule in [type(of: rule).identifier, rule.cacheDescription] } .sorted { $0[0] < $1[0] } let jsonObject: [Any] = [rootDirectory, cacheRulesDescriptions] if let jsonData = try? JSONSerialization.data(withJSONObject: jsonObject) { diff --git a/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift b/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift index 1528591840..54dcf399da 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift @@ -66,7 +66,7 @@ extension Configuration { allRulesWrapped = try ruleList.allRulesWrapped(configurationDict: dict) } catch let RuleListError.duplicatedConfigurations(ruleType) { let aliases = ruleType.description.deprecatedAliases.map { "'\($0)'" }.joined(separator: ", ") - let identifier = ruleType.description.identifier + let identifier = ruleType.identifier throw Issue.genericWarning( "Multiple configurations found for '\(identifier)'. Check for any aliases: \(aliases)." ) diff --git a/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift b/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift index 897fbfe39e..b5540cf3ad 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift @@ -6,7 +6,7 @@ public extension Configuration { /// - returns: The rule for the specified ID, if configured in this configuration. func configuredRule(forID ruleID: String) -> (any Rule)? { rules.first { rule in - if type(of: rule).description.identifier == ruleID { + if type(of: rule).identifier == ruleID { if let customRules = rule as? CustomRules { return customRules.configuration.customRuleConfigurations.isNotEmpty } diff --git a/Source/SwiftLintCore/Extensions/Configuration+RulesWrapper.swift b/Source/SwiftLintCore/Extensions/Configuration+RulesWrapper.swift index 2a947148a1..6e3295d951 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+RulesWrapper.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+RulesWrapper.swift @@ -11,7 +11,7 @@ internal extension Configuration { private var invalidRuleIdsWarnedAbout: Set = [] private var validRuleIdentifiers: Set { - let regularRuleIdentifiers = allRulesWrapped.map { type(of: $0.rule).description.identifier } + let regularRuleIdentifiers = allRulesWrapped.map { type(of: $0.rule).identifier } let configurationCustomRulesIdentifiers = (allRulesWrapped.first { $0.rule is CustomRules }?.rule as? CustomRules)?.customRuleIdentifiers ?? [] return Set(regularRuleIdentifiers + configurationCustomRulesIdentifiers) @@ -42,7 +42,7 @@ internal extension Configuration { customRulesFilter = { onlyRulesRuleIdentifiers.contains($0.identifier) } let onlyRulesRuleIdentifiers = validate(ruleIds: onlyRulesRuleIdentifiers, valid: validRuleIdentifiers) resultingRules = allRulesWrapped.filter { tuple in - onlyRulesRuleIdentifiers.contains(type(of: tuple.rule).description.identifier) + onlyRulesRuleIdentifiers.contains(type(of: tuple.rule).identifier) }.map(\.rule) case var .defaultConfiguration(disabledRuleIdentifiers, optInRuleIdentifiers): @@ -50,7 +50,7 @@ internal extension Configuration { disabledRuleIdentifiers = validate(ruleIds: disabledRuleIdentifiers, valid: validRuleIdentifiers) optInRuleIdentifiers = validate(optInRuleIds: optInRuleIdentifiers, valid: validRuleIdentifiers) resultingRules = allRulesWrapped.filter { tuple in - let id = type(of: tuple.rule).description.identifier + let id = type(of: tuple.rule).identifier return !disabledRuleIdentifiers.contains(id) && (!(tuple.rule is any OptInRule) || optInRuleIdentifiers.contains(id)) }.map(\.rule) @@ -65,7 +65,7 @@ internal extension Configuration { // Sort by name resultingRules = resultingRules.sorted { - type(of: $0).description.identifier < type(of: $1).description.identifier + type(of: $0).identifier < type(of: $1).identifier } // Store & return @@ -82,7 +82,7 @@ internal extension Configuration { case let .onlyConfiguration(onlyRules), let .onlyCommandLine(onlyRules): return validate( ruleIds: Set(allRulesWrapped - .map { type(of: $0.rule).description.identifier } + .map { type(of: $0.rule).identifier } .filter { !onlyRules.contains($0) }), valid: validRuleIdentifiers, silent: true @@ -249,7 +249,7 @@ internal extension Configuration { case var .onlyConfiguration(onlyRules): // Also add identifiers of child custom rules iff the custom_rules rule is enabled // (parent custom rules are already added) - if (onlyRules.contains { $0 == CustomRules.description.identifier }) { + if (onlyRules.contains { $0 == CustomRules.identifier }) { if let childCustomRulesRule = (child.allRulesWrapped.first { $0.rule is CustomRules })?.rule as? CustomRules { onlyRules = onlyRules.union( @@ -279,7 +279,7 @@ internal extension Configuration { .filter { !isOptInRule($0, allRulesWrapped: newAllRulesWrapped) }, - optIn: Set(newAllRulesWrapped.map { type(of: $0.rule).description.identifier } + optIn: Set(newAllRulesWrapped.map { type(of: $0.rule).identifier } .filter { !childDisabled.contains($0) && isOptInRule($0, allRulesWrapped: newAllRulesWrapped) @@ -298,7 +298,7 @@ internal extension Configuration { } let isOptInRule = allRulesWrapped - .first { type(of: $0.rule).description.identifier == identifier }?.rule is any OptInRule + .first { type(of: $0.rule).identifier == identifier }?.rule is any OptInRule Self.isOptInRuleCache[identifier] = isOptInRule return isOptInRule } diff --git a/Source/SwiftLintCore/Models/ChildOptionSeverityConfiguration.swift b/Source/SwiftLintCore/Models/ChildOptionSeverityConfiguration.swift index fb4aed94b8..4f63881029 100644 --- a/Source/SwiftLintCore/Models/ChildOptionSeverityConfiguration.swift +++ b/Source/SwiftLintCore/Models/ChildOptionSeverityConfiguration.swift @@ -23,7 +23,7 @@ public struct ChildOptionSeverityConfiguration: RuleConfiguration, public mutating func apply(configuration: Any) throws { guard let configString = configuration as? String, let optionSeverity = ChildOptionSeverity(rawValue: configString.lowercased()) else { - throw Issue.invalidConfiguration(ruleID: Parent.description.identifier) + throw Issue.invalidConfiguration(ruleID: Parent.identifier) } self.optionSeverity = optionSeverity } diff --git a/Source/SwiftLintCore/Models/Configuration.swift b/Source/SwiftLintCore/Models/Configuration.swift index 944bbb6792..b8169afe11 100644 --- a/Source/SwiftLintCore/Models/Configuration.swift +++ b/Source/SwiftLintCore/Models/Configuration.swift @@ -309,7 +309,7 @@ extension Configuration: Hashable { hasher.combine(checkForUpdates) hasher.combine(basedOnCustomConfigurationFiles) hasher.combine(cachePath) - hasher.combine(rules.map { type(of: $0).description.identifier }) + hasher.combine(rules.map { type(of: $0).identifier }) hasher.combine(fileGraph) } @@ -344,6 +344,6 @@ extension Configuration: CustomStringConvertible { + "- Reporter: \(reporter ?? "default")\n" + "- Cache Path: \(cachePath as Optional)\n" + "- Computed Cache Description: \(computedCacheDescription as Optional)\n" - + "- Rules: \(rules.map { type(of: $0).description.identifier })" + + "- Rules: \(rules.map { type(of: $0).identifier })" } } diff --git a/Source/SwiftLintCore/Models/HashableConfigurationRuleWrapperWrapper.swift b/Source/SwiftLintCore/Models/HashableConfigurationRuleWrapperWrapper.swift index 05ff17312e..1abe3deae2 100644 --- a/Source/SwiftLintCore/Models/HashableConfigurationRuleWrapperWrapper.swift +++ b/Source/SwiftLintCore/Models/HashableConfigurationRuleWrapperWrapper.swift @@ -5,11 +5,11 @@ internal struct HashableConfigurationRuleWrapperWrapper: Hashable { lhs: Self, rhs: Self ) -> Bool { // Only use identifier for equality check (not taking config into account) - type(of: lhs.configurationRuleWrapper.rule).description.identifier - == type(of: rhs.configurationRuleWrapper.rule).description.identifier + type(of: lhs.configurationRuleWrapper.rule).identifier + == type(of: rhs.configurationRuleWrapper.rule).identifier } func hash(into hasher: inout Hasher) { - hasher.combine(type(of: configurationRuleWrapper.rule).description.identifier) + hasher.combine(type(of: configurationRuleWrapper.rule).identifier) } } diff --git a/Source/SwiftLintCore/Models/Linter.swift b/Source/SwiftLintCore/Models/Linter.swift index c87065a557..68f111fdc9 100644 --- a/Source/SwiftLintCore/Models/Linter.swift +++ b/Source/SwiftLintCore/Models/Linter.swift @@ -89,7 +89,7 @@ private extension Rule { return nil } - let ruleID = Self.description.identifier + let ruleID = Self.identifier let violations: [StyleViolation] let ruleTime: (String, Double)? @@ -351,7 +351,7 @@ public struct CollectedLinter { let totalTime = -start.timeIntervalSinceNow let fractionedTime = totalTime / TimeInterval(rules.count) ruleTimes = rules.compactMap { rule in - let id = type(of: rule).description.identifier + let id = type(of: rule).identifier return (id, fractionedTime) } } @@ -414,7 +414,7 @@ public struct CollectedLinter { .configuration.customRuleConfigurations.map { RuleIdentifier($0.identifier) } ?? [] let allRuleIdentifiers = RuleRegistry.shared.list.allValidIdentifiers().map { RuleIdentifier($0) } let allValidIdentifiers = Set(allCustomIdentifiers + allRuleIdentifiers + [.all]) - let superfluousRuleIdentifier = RuleIdentifier(SuperfluousDisableCommandRule.description.identifier) + let superfluousRuleIdentifier = RuleIdentifier(SuperfluousDisableCommandRule.identifier) return regions.flatMap { region in region.disabledRuleIdentifiers.filter({ diff --git a/Source/SwiftLintCore/Models/RuleList.swift b/Source/SwiftLintCore/Models/RuleList.swift index e8dd55b5c8..79dab75ac6 100644 --- a/Source/SwiftLintCore/Models/RuleList.swift +++ b/Source/SwiftLintCore/Models/RuleList.swift @@ -27,7 +27,7 @@ public struct RuleList { var tmpAliases = [String: String]() for rule in rules { - let identifier = rule.description.identifier + let identifier = rule.identifier tmpList[identifier] = rule for alias in rule.description.deprecatedAliases { tmpAliases[alias] = identifier diff --git a/Source/SwiftLintCore/RuleConfigurations/RegexConfiguration.swift b/Source/SwiftLintCore/RuleConfigurations/RegexConfiguration.swift index 65b44876f6..c4d3acf106 100644 --- a/Source/SwiftLintCore/RuleConfigurations/RegexConfiguration.swift +++ b/Source/SwiftLintCore/RuleConfigurations/RegexConfiguration.swift @@ -60,7 +60,7 @@ public struct RegexConfiguration: SeverityBasedRuleConfiguration, public mutating func apply(configuration: Any) throws { guard let configurationDict = configuration as? [String: Any], let regexString = configurationDict[$regex.key] as? String else { - throw Issue.invalidConfiguration(ruleID: Parent.description.identifier) + throw Issue.invalidConfiguration(ruleID: Parent.identifier) } regex = try RegularExpression(pattern: regexString) @@ -92,7 +92,7 @@ public struct RegexConfiguration: SeverityBasedRuleConfiguration, } if let captureGroup = configurationDict["capture_group"] as? Int { guard (0 ... regex.numberOfCaptureGroups).contains(captureGroup) else { - throw Issue.invalidConfiguration(ruleID: Parent.description.identifier) + throw Issue.invalidConfiguration(ruleID: Parent.identifier) } self.captureGroup = captureGroup } @@ -142,7 +142,7 @@ public struct RegexConfiguration: SeverityBasedRuleConfiguration, if let kind = SyntaxKind(shortName: $0) { return kind } - throw Issue.invalidConfiguration(ruleID: Parent.description.identifier) + throw Issue.invalidConfiguration(ruleID: Parent.identifier) } return Set(kinds) } diff --git a/Source/SwiftLintCore/Rules/CustomRules.swift b/Source/SwiftLintCore/Rules/CustomRules.swift index e523c757a7..ec6a4f9000 100644 --- a/Source/SwiftLintCore/Rules/CustomRules.swift +++ b/Source/SwiftLintCore/Rules/CustomRules.swift @@ -90,7 +90,7 @@ struct CustomRules: Rule, CacheDescriptionProvider { func canBeDisabled(violation: StyleViolation, by ruleID: RuleIdentifier) -> Bool { switch ruleID { case let .single(identifier: id): - id == Self.description.identifier + id == Self.identifier ? customRuleIdentifiers.contains(violation.ruleIdentifier) : customRuleIdentifiers.contains(id) && violation.ruleIdentifier == id default: @@ -101,10 +101,10 @@ struct CustomRules: Rule, CacheDescriptionProvider { func isEnabled(in region: Region, for ruleID: String) -> Bool { if !Self.description.allIdentifiers.contains(ruleID), !customRuleIdentifiers.contains(ruleID), - Self.description.identifier != ruleID { + Self.identifier != ruleID { return true } - return !region.disabledRuleIdentifiers.contains(RuleIdentifier(Self.description.identifier)) + return !region.disabledRuleIdentifiers.contains(RuleIdentifier(Self.identifier)) && !region.disabledRuleIdentifiers.contains(RuleIdentifier(ruleID)) && !region.disabledRuleIdentifiers.contains(.all) } diff --git a/Source/SwiftLintFramework/RulesFilter.swift b/Source/SwiftLintFramework/RulesFilter.swift index 9f585f7be4..8a5d1d250e 100644 --- a/Source/SwiftLintFramework/RulesFilter.swift +++ b/Source/SwiftLintFramework/RulesFilter.swift @@ -26,7 +26,7 @@ package final class RulesFilter { let filtered: [any Rule.Type] = allRules.list.compactMap { ruleID, ruleType in let enabledRule = enabledRules.first { rule in - type(of: rule).description.identifier == ruleID + type(of: rule).identifier == ruleID } let isRuleEnabled = enabledRule != nil diff --git a/Tests/CLITests/RulesFilterTests.swift b/Tests/CLITests/RulesFilterTests.swift index 7c2f3fcfa4..8979db66c1 100644 --- a/Tests/CLITests/RulesFilterTests.swift +++ b/Tests/CLITests/RulesFilterTests.swift @@ -23,7 +23,7 @@ final class RulesFilterTests: XCTestCase { XCTAssertEqual( Set(filteredRules.list.keys), - Set([RuleMock2.description.identifier]) + Set([RuleMock2.identifier]) ) } @@ -48,7 +48,7 @@ final class RulesFilterTests: XCTestCase { XCTAssertEqual( Set(filteredRules.list.keys), - Set([RuleMock1.description.identifier, CorrectableRuleMock.description.identifier]) + Set([RuleMock1.identifier, CorrectableRuleMock.identifier]) ) } @@ -73,7 +73,7 @@ final class RulesFilterTests: XCTestCase { XCTAssertEqual( Set(filteredRules.list.keys), - Set([CorrectableRuleMock.description.identifier]) + Set([CorrectableRuleMock.identifier]) ) } @@ -98,7 +98,7 @@ final class RulesFilterTests: XCTestCase { XCTAssertEqual( Set(filteredRules.list.keys), - Set([CorrectableRuleMock.description.identifier]) + Set([CorrectableRuleMock.identifier]) ) } @@ -122,7 +122,7 @@ final class RulesFilterTests: XCTestCase { XCTAssertEqual( Set(filteredRules.list.keys), - Set([CorrectableRuleMock.description.identifier]) + Set([CorrectableRuleMock.identifier]) ) } } diff --git a/Tests/SwiftLintFrameworkTests/CompilerProtocolInitRuleTests.swift b/Tests/SwiftLintFrameworkTests/CompilerProtocolInitRuleTests.swift index bf39d734f5..68460fd73b 100644 --- a/Tests/SwiftLintFrameworkTests/CompilerProtocolInitRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/CompilerProtocolInitRuleTests.swift @@ -2,7 +2,7 @@ import XCTest final class CompilerProtocolInitRuleTests: SwiftLintTestCase { - private let ruleID = CompilerProtocolInitRule.description.identifier + private let ruleID = CompilerProtocolInitRule.identifier func testViolationMessageForExpressibleByIntegerLiteral() throws { let config = try XCTUnwrap(makeConfig(nil, ruleID)) diff --git a/Tests/SwiftLintFrameworkTests/ComputedAccessorsOrderRuleTests.swift b/Tests/SwiftLintFrameworkTests/ComputedAccessorsOrderRuleTests.swift index 9460f22367..1066d61010 100644 --- a/Tests/SwiftLintFrameworkTests/ComputedAccessorsOrderRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/ComputedAccessorsOrderRuleTests.swift @@ -120,7 +120,7 @@ final class ComputedAccessorsOrderRuleTests: SwiftLintTestCase { } private func ruleViolations(_ example: Example, ruleConfiguration: Any? = nil) -> [StyleViolation] { - guard let config = makeConfig(ruleConfiguration, ComputedAccessorsOrderRule.description.identifier) else { + guard let config = makeConfig(ruleConfiguration, ComputedAccessorsOrderRule.identifier) else { return [] } diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationAliasesTests.swift b/Tests/SwiftLintFrameworkTests/ConfigurationAliasesTests.swift index 7f9367dcef..c20e8b90b5 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationAliasesTests.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationAliasesTests.swift @@ -28,7 +28,7 @@ final class ConfigurationAliasesTests: SwiftLintTestCase { // swiftlint:disable:next force_try let configuration = try! Configuration(dict: ["only_rules": ["mock"]], ruleList: testRuleList) let configuredIdentifiers = configuration.rules.map { - type(of: $0).description.identifier + type(of: $0).identifier } XCTAssertEqual(configuredIdentifiers, ["severity_level_mock"]) } diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationTests+MultipleConfigs.swift b/Tests/SwiftLintFrameworkTests/ConfigurationTests+MultipleConfigs.swift index 2c3c742e66..e928221e9b 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationTests+MultipleConfigs.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationTests+MultipleConfigs.swift @@ -55,8 +55,8 @@ extension ConfigurationTests { rulesMode: .defaultConfiguration( disabled: [], optIn: [ - ForceTryRule.description.identifier, - ForceCastRule.description.identifier, + ForceTryRule.identifier, + ForceCastRule.identifier, ] ) ) @@ -78,7 +78,7 @@ extension ConfigurationTests { } func testOnlyRuleMerging() { - let ruleIdentifier = TodoRule.description.identifier + let ruleIdentifier = TodoRule.identifier let onlyRuleConfiguration = Configuration.onlyRuleConfiguration(ruleIdentifier) let emptyDefaultConfiguration = Configuration.emptyDefaultConfiguration() @@ -90,7 +90,7 @@ extension ConfigurationTests { let mergedConfiguration2 = onlyRuleConfiguration.merged(withChild: disabledDefaultConfiguration) XCTAssertTrue(mergedConfiguration2.rules.isEmpty) - let enabledOnlyConfiguration = Configuration.enabledOnlyConfiguration(ForceTryRule.description.identifier) + let enabledOnlyConfiguration = Configuration.enabledOnlyConfiguration(ForceTryRule.identifier) let mergedConfiguration3 = onlyRuleConfiguration.merged(withChild: enabledOnlyConfiguration) XCTAssertEqual(mergedConfiguration3.rules.count, 1) XCTAssertTrue(mergedConfiguration3.rules[0] is TodoRule) @@ -362,7 +362,7 @@ extension ConfigurationTests { XCTAssertEqual(testCases.unique.count, 4 * 4) let ruleType = ImplicitReturnRule.self XCTAssertTrue((ruleType as Any) is any OptInRule.Type) - let ruleIdentifier = ruleType.description.identifier + let ruleIdentifier = ruleType.identifier for testCase in testCases { let parentConfiguration = Configuration(rulesMode: .defaultConfiguration( disabled: testCase.disabledInParent ? [ruleIdentifier] : [], @@ -396,7 +396,7 @@ extension ConfigurationTests { XCTAssertEqual(testCases.unique.count, 2 * 2) let ruleType = BlanketDisableCommandRule.self XCTAssertFalse(ruleType is any OptInRule.Type) - let ruleIdentifier = ruleType.description.identifier + let ruleIdentifier = ruleType.identifier for testCase in testCases { let parentConfiguration = Configuration( rulesMode: .defaultConfiguration(disabled: testCase.disabledInParent ? [ruleIdentifier] : [], optIn: []) @@ -428,7 +428,7 @@ extension ConfigurationTests { XCTAssertEqual(testCases.unique.count, 2 * 2) let ruleType = ImplicitReturnRule.self XCTAssertTrue((ruleType as Any) is any OptInRule.Type) - let ruleIdentifier = ruleType.description.identifier + let ruleIdentifier = ruleType.identifier let parentConfiguration = Configuration(rulesMode: .onlyConfiguration([ruleIdentifier])) for testCase in testCases { let childConfiguration = Configuration(rulesMode: .defaultConfiguration( @@ -635,8 +635,8 @@ extension ConfigurationTests { ) XCTAssertEqual( - configuration1.rules.map { type(of: $0).description.identifier }, - configuration2.rules.map { type(of: $0).description.identifier } + configuration1.rules.map { type(of: $0).identifier }, + configuration2.rules.map { type(of: $0).identifier } ) XCTAssertEqual( diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift index f718aed784..ffca2d57ab 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift @@ -116,7 +116,7 @@ final class ConfigurationTests: SwiftLintTestCase { let config = try Configuration(dict: ["only_rules": only]) let configuredIdentifiers = config.rules.map { - type(of: $0).description.identifier + type(of: $0).identifier }.sorted() XCTAssertEqual(only, configuredIdentifiers) } @@ -178,7 +178,7 @@ final class ConfigurationTests: SwiftLintTestCase { let expectedIdentifiers = Set(RuleRegistry.shared.list.list.keys .filter({ !(["nesting", "todo"] + optInRules).contains($0) })) let configuredIdentifiers = Set(disabledConfig.rules.map { - type(of: $0).description.identifier + type(of: $0).identifier }) XCTAssertEqual(expectedIdentifiers, configuredIdentifiers) } @@ -205,7 +205,7 @@ final class ConfigurationTests: SwiftLintTestCase { let duplicateConfig2 = try? Configuration(dict: ["opt_in_rules": [optInRules.first!, optInRules.first!]]) XCTAssertEqual( - duplicateConfig2?.rules.filter { type(of: $0).description.identifier == optInRules.first! }.count, 1, + duplicateConfig2?.rules.filter { type(of: $0).identifier == optInRules.first! }.count, 1, "duplicate rules should be removed when initializing Configuration" ) @@ -435,14 +435,14 @@ final class ConfigurationTests: SwiftLintTestCase { func testConfiguresCorrectlyFromDict() throws { let ruleConfiguration = [1, 2] - let config = [RuleWithLevelsMock.description.identifier: ruleConfiguration] + let config = [RuleWithLevelsMock.identifier: ruleConfiguration] let rules = try testRuleList.allRulesWrapped(configurationDict: config).map(\.rule) // swiftlint:disable:next xct_specific_matcher XCTAssertTrue(rules == [try RuleWithLevelsMock(configuration: ruleConfiguration)]) } func testConfigureFallsBackCorrectly() throws { - let config = [RuleWithLevelsMock.description.identifier: ["a", "b"]] + let config = [RuleWithLevelsMock.identifier: ["a", "b"]] let rules = try testRuleList.allRulesWrapped(configurationDict: config).map(\.rule) // swiftlint:disable:next xct_specific_matcher XCTAssertTrue(rules == [RuleWithLevelsMock()]) diff --git a/Tests/SwiftLintFrameworkTests/ContainsOverFirstNotNilRuleTests.swift b/Tests/SwiftLintFrameworkTests/ContainsOverFirstNotNilRuleTests.swift index f8691673cd..83c162fba3 100644 --- a/Tests/SwiftLintFrameworkTests/ContainsOverFirstNotNilRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/ContainsOverFirstNotNilRuleTests.swift @@ -21,7 +21,7 @@ final class ContainsOverFirstNotNilRuleTests: SwiftLintTestCase { // MARK: - Private private func violations(_ example: Example, config: Any? = nil) -> [StyleViolation] { - guard let config = makeConfig(config, ContainsOverFirstNotNilRule.description.identifier) else { + guard let config = makeConfig(config, ContainsOverFirstNotNilRule.identifier) else { return [] } diff --git a/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift b/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift index 548fb98db2..4a4f11006c 100644 --- a/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift +++ b/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift @@ -66,7 +66,7 @@ final class CustomRulesTests: SwiftLintTestCase { func testCustomRuleConfigurationThrows() { let config = 17 var customRulesConfig = CustomRulesConfiguration() - checkError(Issue.invalidConfiguration(ruleID: CustomRules.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: CustomRules.identifier)) { try customRulesConfig.apply(configuration: config) } } @@ -106,7 +106,7 @@ final class CustomRulesTests: SwiftLintTestCase { XCTAssertEqual(customRulesConfig.customRuleConfigurations.count, 1) - let identifier = customRulesConfig.customRuleConfigurations.first?.description.identifier + let identifier = customRulesConfig.customRuleConfigurations.first?.identifier XCTAssertEqual(identifier, "my_custom_rule") } @@ -570,7 +570,7 @@ final class CustomRulesTests: SwiftLintTestCase { private extension StyleViolation { func isSuperfluousDisableCommandViolation(for ruleIdentifier: String) -> Bool { - self.ruleIdentifier == SuperfluousDisableCommandRule.description.identifier && + self.ruleIdentifier == SuperfluousDisableCommandRule.identifier && reason.contains("SwiftLint rule '\(ruleIdentifier)' did not trigger a violation") } } diff --git a/Tests/SwiftLintFrameworkTests/CyclomaticComplexityConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/CyclomaticComplexityConfigurationTests.swift index a03337b708..eb9638a82f 100644 --- a/Tests/SwiftLintFrameworkTests/CyclomaticComplexityConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/CyclomaticComplexityConfigurationTests.swift @@ -71,7 +71,7 @@ final class CyclomaticComplexityConfigurationTests: SwiftLintTestCase { var configuration = CyclomaticComplexityConfiguration( length: SeverityLevelsConfiguration(warning: 100, error: 150) ) - checkError(Issue.invalidConfiguration(ruleID: CyclomaticComplexityRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: CyclomaticComplexityRule.identifier)) { try configuration.apply(configuration: badConfig) } } diff --git a/Tests/SwiftLintFrameworkTests/DeploymentTargetConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/DeploymentTargetConfigurationTests.swift index b130557f09..f9edd35491 100644 --- a/Tests/SwiftLintFrameworkTests/DeploymentTargetConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/DeploymentTargetConfigurationTests.swift @@ -139,7 +139,7 @@ final class DeploymentTargetConfigurationTests: SwiftLintTestCase { for badConfig in badConfigs { var configuration = DeploymentTargetConfiguration() - checkError(Issue.invalidConfiguration(ruleID: DeploymentTargetRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: DeploymentTargetRule.identifier)) { try configuration.apply(configuration: badConfig) } } diff --git a/Tests/SwiftLintFrameworkTests/DeploymentTargetRuleTests.swift b/Tests/SwiftLintFrameworkTests/DeploymentTargetRuleTests.swift index 46c8b21066..b101b89b0c 100644 --- a/Tests/SwiftLintFrameworkTests/DeploymentTargetRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/DeploymentTargetRuleTests.swift @@ -35,7 +35,7 @@ final class DeploymentTargetRuleTests: SwiftLintTestCase { } private func violations(_ example: Example, config: Any?) -> [StyleViolation] { - guard let config = makeConfig(config, DeploymentTargetRule.description.identifier) else { + guard let config = makeConfig(config, DeploymentTargetRule.identifier) else { return [] } diff --git a/Tests/SwiftLintFrameworkTests/ExpiringTodoRuleTests.swift b/Tests/SwiftLintFrameworkTests/ExpiringTodoRuleTests.swift index 06f890bdea..a95bb4ec5a 100644 --- a/Tests/SwiftLintFrameworkTests/ExpiringTodoRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/ExpiringTodoRuleTests.swift @@ -191,7 +191,7 @@ final class ExpiringTodoRuleTests: SwiftLintTestCase { ] } - return makeConfig(serializedConfig, ExpiringTodoRule.description.identifier)! + return makeConfig(serializedConfig, ExpiringTodoRule.identifier)! } } diff --git a/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceConfigurationTests.swift index ea362d5228..ec413e59a4 100644 --- a/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/ExplicitTypeInterfaceConfigurationTests.swift @@ -33,14 +33,14 @@ final class ExplicitTypeInterfaceConfigurationTests: SwiftLintTestCase { func testInvalidTypeOfCustomConfiguration() { var config = ExplicitTypeInterfaceConfiguration() - checkError(Issue.invalidConfiguration(ruleID: ExplicitTypeInterfaceRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: ExplicitTypeInterfaceRule.identifier)) { try config.apply(configuration: "invalidKey") } } func testInvalidTypeOfValueInCustomConfiguration() { var config = ExplicitTypeInterfaceConfiguration() - checkError(Issue.invalidConfiguration(ruleID: ExplicitTypeInterfaceRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: ExplicitTypeInterfaceRule.identifier)) { try config.apply(configuration: ["severity": "foo"]) } } diff --git a/Tests/SwiftLintFrameworkTests/FunctionBodyLengthRuleTests.swift b/Tests/SwiftLintFrameworkTests/FunctionBodyLengthRuleTests.swift index 04e9a6cbab..d849b2996d 100644 --- a/Tests/SwiftLintFrameworkTests/FunctionBodyLengthRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/FunctionBodyLengthRuleTests.swift @@ -101,7 +101,7 @@ final class FunctionBodyLengthRuleTests: SwiftLintTestCase { } private func violations(_ example: Example, configuration: Any? = nil) -> [StyleViolation] { - let config = makeConfig(configuration, FunctionBodyLengthRule.description.identifier)! + let config = makeConfig(configuration, FunctionBodyLengthRule.identifier)! return SwiftLintFrameworkTests.violations(example, config: config) } } diff --git a/Tests/SwiftLintFrameworkTests/ImplicitGetterRuleTests.swift b/Tests/SwiftLintFrameworkTests/ImplicitGetterRuleTests.swift index 8a83b92bbe..0905bf01f9 100644 --- a/Tests/SwiftLintFrameworkTests/ImplicitGetterRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/ImplicitGetterRuleTests.swift @@ -3,7 +3,7 @@ import XCTest final class ImplicitGetterRuleTests: SwiftLintTestCase { func testPropertyReason() throws { - let config = try XCTUnwrap(makeConfig(nil, ImplicitGetterRule.description.identifier)) + let config = try XCTUnwrap(makeConfig(nil, ImplicitGetterRule.identifier)) let example = Example(""" class Foo { var foo: Int { @@ -20,7 +20,7 @@ final class ImplicitGetterRuleTests: SwiftLintTestCase { } func testSubscriptReason() throws { - let config = try XCTUnwrap(makeConfig(nil, ImplicitGetterRule.description.identifier)) + let config = try XCTUnwrap(makeConfig(nil, ImplicitGetterRule.identifier)) let example = Example(""" class Foo { subscript(i: Int) -> Int { diff --git a/Tests/SwiftLintFrameworkTests/ImplicitReturnConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/ImplicitReturnConfigurationTests.swift index c6a62deca1..b19dd28e02 100644 --- a/Tests/SwiftLintFrameworkTests/ImplicitReturnConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/ImplicitReturnConfigurationTests.swift @@ -31,7 +31,7 @@ final class ImplicitReturnConfigurationTests: SwiftLintTestCase { var configuration = ImplicitReturnConfiguration() let config = ["included": ["foreach"]] as [String: any Sendable] - checkError(Issue.invalidConfiguration(ruleID: ImplicitReturnRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: ImplicitReturnRule.identifier)) { try configuration.apply(configuration: config) } } diff --git a/Tests/SwiftLintFrameworkTests/ImplicitlyUnwrappedOptionalConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/ImplicitlyUnwrappedOptionalConfigurationTests.swift index 6dca068e61..6ba01c625c 100644 --- a/Tests/SwiftLintFrameworkTests/ImplicitlyUnwrappedOptionalConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/ImplicitlyUnwrappedOptionalConfigurationTests.swift @@ -39,7 +39,7 @@ final class ImplicitlyUnwrappedOptionalConfigurationTests: SwiftLintTestCase { mode: .allExceptIBOutlets ) - checkError(Issue.invalidConfiguration(ruleID: ImplicitlyUnwrappedOptionalRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: ImplicitlyUnwrappedOptionalRule.identifier)) { try configuration.apply(configuration: badConfig) } } diff --git a/Tests/SwiftLintFrameworkTests/IndentationWidthRuleTests.swift b/Tests/SwiftLintFrameworkTests/IndentationWidthRuleTests.swift index 627797f814..b0234978bc 100644 --- a/Tests/SwiftLintFrameworkTests/IndentationWidthRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/IndentationWidthRuleTests.swift @@ -282,7 +282,7 @@ final class IndentationWidthRuleTests: SwiftLintTestCase { configDict["include_compiler_directives"] = includeCompilerDirectives configDict["include_multiline_strings"] = includeMultilineStrings - guard let config = makeConfig(configDict, IndentationWidthRule.description.identifier) else { + guard let config = makeConfig(configDict, IndentationWidthRule.identifier) else { XCTFail("Unable to create rule configuration.", file: (file), line: line) return 0 } diff --git a/Tests/SwiftLintFrameworkTests/LineLengthConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/LineLengthConfigurationTests.swift index 01b59c8c9d..55360aabe8 100644 --- a/Tests/SwiftLintFrameworkTests/LineLengthConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/LineLengthConfigurationTests.swift @@ -71,7 +71,7 @@ final class LineLengthConfigurationTests: SwiftLintTestCase { func testLineLengthConfigurationThrowsOnBadConfig() { let config = ["warning": "unknown"] var configuration = LineLengthConfiguration(length: severityLevels) - checkError(Issue.invalidConfiguration(ruleID: LineLengthRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: LineLengthRule.identifier)) { try configuration.apply(configuration: config) } } @@ -84,7 +84,7 @@ final class LineLengthConfigurationTests: SwiftLintTestCase { for badConfig in badConfigs { var configuration = LineLengthConfiguration(length: severityLevels) - checkError(Issue.invalidConfiguration(ruleID: LineLengthRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: LineLengthRule.identifier)) { try configuration.apply(configuration: badConfig) } } diff --git a/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift b/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift index 4df00865d1..fdcff1f16f 100644 --- a/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift +++ b/Tests/SwiftLintFrameworkTests/ModifierOrderTests.swift @@ -383,7 +383,7 @@ final class ModifierOrderTests: SwiftLintTestCase { } func testViolationMessage() { - let ruleID = ModifierOrderRule.description.identifier + let ruleID = ModifierOrderRule.identifier guard let config = makeConfig(["preferred_modifier_order": ["acl", "final"]], ruleID) else { XCTFail("Failed to create configuration") return diff --git a/Tests/SwiftLintFrameworkTests/NameConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/NameConfigurationTests.swift index 9f7fac7979..fc39b2bf29 100644 --- a/Tests/SwiftLintFrameworkTests/NameConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/NameConfigurationTests.swift @@ -67,7 +67,7 @@ final class NameConfigurationTests: SwiftLintTestCase { minLengthError: 0, maxLengthWarning: 0, maxLengthError: 0) - checkError(Issue.invalidConfiguration(ruleID: RuleMock.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: RuleMock.identifier)) { try nameConfig.apply(configuration: config) } } diff --git a/Tests/SwiftLintFrameworkTests/NestingRuleTests.swift b/Tests/SwiftLintFrameworkTests/NestingRuleTests.swift index 4386d10d4f..435ca660be 100644 --- a/Tests/SwiftLintFrameworkTests/NestingRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/NestingRuleTests.swift @@ -200,7 +200,7 @@ final class NestingRuleTests: SwiftLintTestCase { }) let description = RuleDescription( - identifier: NestingRule.description.identifier, + identifier: NestingRule.identifier, name: NestingRule.description.name, description: NestingRule.description.description, kind: .metrics, @@ -499,7 +499,7 @@ final class NestingRuleTests: SwiftLintTestCase { ]) let description = RuleDescription( - identifier: NestingRule.description.identifier, + identifier: NestingRule.identifier, name: NestingRule.description.name, description: NestingRule.description.description, kind: .metrics, diff --git a/Tests/SwiftLintFrameworkTests/NoEmptyBlockConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/NoEmptyBlockConfigurationTests.swift index 851f358587..22b22f58d6 100644 --- a/Tests/SwiftLintFrameworkTests/NoEmptyBlockConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/NoEmptyBlockConfigurationTests.swift @@ -31,14 +31,14 @@ final class NoEmptyBlockConfigurationTests: SwiftLintTestCase { func testInvalidTypeOfCustomConfiguration() { var config = NoEmptyBlockConfiguration() - checkError(Issue.invalidConfiguration(ruleID: NoEmptyBlockRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: NoEmptyBlockRule.identifier)) { try config.apply(configuration: "invalidKey") } } func testInvalidTypeOfValueInCustomConfiguration() { var config = NoEmptyBlockConfiguration() - checkError(Issue.invalidConfiguration(ruleID: NoEmptyBlockRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: NoEmptyBlockRule.identifier)) { try config.apply(configuration: ["severity": "foo"]) } } diff --git a/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift index db0a56ddb9..f86fca1e21 100644 --- a/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift @@ -37,7 +37,7 @@ final class RuleConfigurationTests: SwiftLintTestCase { func testNestingConfigurationThrowsOnBadConfig() { let config = 17 var nestingConfig = defaultNestingConfiguration - checkError(Issue.invalidConfiguration(ruleID: NestingRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: NestingRule.identifier)) { try nestingConfig.apply(configuration: config) } } @@ -117,7 +117,7 @@ final class RuleConfigurationTests: SwiftLintTestCase { func testRegexConfigurationThrows() { let config = 17 var regexConfig = RegexConfiguration(identifier: "") - checkError(Issue.invalidConfiguration(ruleID: RuleMock.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: RuleMock.identifier)) { try regexConfig.apply(configuration: config) } } @@ -137,7 +137,7 @@ final class RuleConfigurationTests: SwiftLintTestCase { let config = "unknown" var configuration = TrailingWhitespaceConfiguration(ignoresEmptyLines: false, ignoresComments: true) - checkError(Issue.invalidConfiguration(ruleID: TrailingWhitespaceRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: TrailingWhitespaceRule.identifier)) { try configuration.apply(configuration: config) } } @@ -321,7 +321,7 @@ final class RuleConfigurationTests: SwiftLintTestCase { var configuration = ModifierOrderConfiguration() let config = ["severity": "warning", "preferred_modifier_order": ["specialize"]] as [String: any Sendable] - checkError(Issue.invalidConfiguration(ruleID: ModifierOrderRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: ModifierOrderRule.identifier)) { try configuration.apply(configuration: config) } } @@ -329,7 +329,7 @@ final class RuleConfigurationTests: SwiftLintTestCase { func testModifierOrderConfigurationThrowsOnNonModifiableGroup() { var configuration = ModifierOrderConfiguration() let config = ["severity": "warning", "preferred_modifier_order": ["atPrefixed"]] as [String: any Sendable] - checkError(Issue.invalidConfiguration(ruleID: ModifierOrderRule.description.identifier)) { + checkError(Issue.invalidConfiguration(ruleID: ModifierOrderRule.identifier)) { try configuration.apply(configuration: config) } } diff --git a/Tests/SwiftLintFrameworkTests/TodoRuleTests.swift b/Tests/SwiftLintFrameworkTests/TodoRuleTests.swift index 8058742dae..8130bc54cc 100644 --- a/Tests/SwiftLintFrameworkTests/TodoRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/TodoRuleTests.swift @@ -41,7 +41,7 @@ final class TodoRuleTests: SwiftLintTestCase { } private func violations(_ example: Example, config: Any? = nil) -> [StyleViolation] { - let config = makeConfig(config, TodoRule.description.identifier)! + let config = makeConfig(config, TodoRule.identifier)! return SwiftLintFrameworkTests.violations(example, config: config) } } diff --git a/Tests/SwiftLintFrameworkTests/TrailingCommaRuleTests.swift b/Tests/SwiftLintFrameworkTests/TrailingCommaRuleTests.swift index dc26b39ebb..e7b4a8f361 100644 --- a/Tests/SwiftLintFrameworkTests/TrailingCommaRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/TrailingCommaRuleTests.swift @@ -69,7 +69,7 @@ final class TrailingCommaRuleTests: SwiftLintTestCase { } private func trailingCommaViolations(_ example: Example, ruleConfiguration: Any? = nil) -> [StyleViolation] { - let config = makeConfig(ruleConfiguration, TrailingCommaRule.description.identifier)! + let config = makeConfig(ruleConfiguration, TrailingCommaRule.identifier)! return violations(example, config: config) } } diff --git a/Tests/SwiftLintFrameworkTests/VerticalWhitespaceRuleTests.swift b/Tests/SwiftLintFrameworkTests/VerticalWhitespaceRuleTests.swift index 20d725b487..deba0b0844 100644 --- a/Tests/SwiftLintFrameworkTests/VerticalWhitespaceRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/VerticalWhitespaceRuleTests.swift @@ -2,7 +2,7 @@ import XCTest final class VerticalWhitespaceRuleTests: SwiftLintTestCase { - private let ruleID = VerticalWhitespaceRule.description.identifier + private let ruleID = VerticalWhitespaceRule.identifier func testAttributesWithMaxEmptyLines() { // Test with custom `max_empty_lines` diff --git a/Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift b/Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift index d32351bbe2..90c78cfada 100644 --- a/Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/XCTSpecificMatcherRuleTests.swift @@ -181,7 +181,7 @@ final class XCTSpecificMatcherRuleTests: SwiftLintTestCase { } private func violations(_ example: Example) -> [StyleViolation] { - guard let config = makeConfig(nil, XCTSpecificMatcherRule.description.identifier) else { return [] } + guard let config = makeConfig(nil, XCTSpecificMatcherRule.identifier) else { return [] } return SwiftLintFrameworkTests.violations(example, config: config) } diff --git a/Tests/SwiftLintTestHelpers/TestHelpers.swift b/Tests/SwiftLintTestHelpers/TestHelpers.swift index c28f43e055..06b09ac8b5 100644 --- a/Tests/SwiftLintTestHelpers/TestHelpers.swift +++ b/Tests/SwiftLintTestHelpers/TestHelpers.swift @@ -272,7 +272,7 @@ private extension String { public func makeConfig(_ ruleConfiguration: Any?, _ identifier: String, skipDisableCommandTests: Bool = false) -> Configuration? { - let superfluousDisableCommandRuleIdentifier = SuperfluousDisableCommandRule.description.identifier + let superfluousDisableCommandRuleIdentifier = SuperfluousDisableCommandRule.identifier let identifiers: Set = skipDisableCommandTests ? [identifier] : [identifier, superfluousDisableCommandRuleIdentifier] @@ -300,7 +300,7 @@ private func testCorrection(_ correction: (Example, Example), var config = configuration if let correctionConfiguration = correction.0.configuration, case let .onlyConfiguration(onlyRules) = configuration.rulesMode, - let ruleToConfigure = (onlyRules.first { $0 != SuperfluousDisableCommandRule.description.identifier }), + let ruleToConfigure = (onlyRules.first { $0 != SuperfluousDisableCommandRule.identifier }), case let configDict: [_: any Sendable] = ["only_rules": onlyRules, ruleToConfigure: correctionConfiguration], let typedConfiguration = try? Configuration(dict: configDict) { config = configuration.merged(withChild: typedConfiguration, rootDirectory: configuration.rootDirectory) @@ -425,7 +425,7 @@ public extension XCTestCase { for trigger in disabledTriggers { let violationsPartitionedByType = makeViolations(trigger) - .partitioned { $0.ruleIdentifier == SuperfluousDisableCommandRule.description.identifier } + .partitioned { $0.ruleIdentifier == SuperfluousDisableCommandRule.identifier } XCTAssert(violationsPartitionedByType.first.isEmpty, "Violation(s) still triggered although rule was disabled", From f410ea51a7ac242070f3e4e2a88dc2519ea9aabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Wed, 30 Oct 2024 14:24:22 +0100 Subject: [PATCH 2/5] Support Swift version 6.0.2 (#5844) --- Tests/SwiftLintFrameworkTests/SwiftVersionTests.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/SwiftLintFrameworkTests/SwiftVersionTests.swift b/Tests/SwiftLintFrameworkTests/SwiftVersionTests.swift index fb103a7b7e..aff4993cc8 100644 --- a/Tests/SwiftLintFrameworkTests/SwiftVersionTests.swift +++ b/Tests/SwiftLintFrameworkTests/SwiftVersionTests.swift @@ -3,7 +3,9 @@ import XCTest final class SwiftVersionTests: SwiftLintTestCase { func testDetectSwiftVersion() { -#if compiler(>=6.0.1) +#if compiler(>=6.0.2) + let version = "6.0.2" +#elseif compiler(>=6.0.1) let version = "6.0.1" #elseif compiler(>=6.0.0) let version = "6.0.0" From 23d6a7c3f56f2d0815774415a12b5405dfd1d9b0 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Wed, 30 Oct 2024 22:03:54 +0000 Subject: [PATCH 3/5] Added `lenient` command line option (#5801) --- CHANGELOG.md | 5 ++ README.md | 3 + .../Extensions/Configuration+Merging.swift | 1 + .../Extensions/Configuration+Parsing.swift | 2 + .../SwiftLintCore/Models/Configuration.swift | 11 +++ .../LintOrAnalyzeCommand.swift | 26 +++++-- .../ConfigurationTests.swift | 6 ++ .../LintOrAnalyzeOptionsTests.swift | 72 +++++++++++++++++++ 8 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 Tests/SwiftLintFrameworkTests/LintOrAnalyzeOptionsTests.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index b7f2100741..ffb00ebc19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,11 @@ argument `--use-script-input-file-lists`. [BlueVirusX](https://github.com/BlueVirusX) +* Adds a `lenient` configuration file setting, equivalent to the `--lenient` + command line option. + [Martin Redington](https://github.com/mildm8nnered) + [#5801](https://github.com/realm/SwiftLint/issues/5801) + #### Bug Fixes * Run command plugin in whole package if no targets are defined in the diff --git a/README.md b/README.md index 2d37e03326..39b7294f7e 100644 --- a/README.md +++ b/README.md @@ -723,6 +723,9 @@ allow_zero_lintable_files: false # If true, SwiftLint will treat all warnings as errors. strict: false +# If true, SwiftLint will treat all errors as warnings. +lenient: false + # The path to a baseline file, which will be used to filter out detected violations. baseline: Baseline.json diff --git a/Source/SwiftLintCore/Extensions/Configuration+Merging.swift b/Source/SwiftLintCore/Extensions/Configuration+Merging.swift index 05e5dfd490..82a11e342d 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+Merging.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+Merging.swift @@ -26,6 +26,7 @@ extension Configuration { cachePath: cachePath, allowZeroLintableFiles: childConfiguration.allowZeroLintableFiles, strict: childConfiguration.strict, + lenient: childConfiguration.lenient, baseline: childConfiguration.baseline, writeBaseline: childConfiguration.writeBaseline, checkForUpdates: childConfiguration.checkForUpdates diff --git a/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift b/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift index 54dcf399da..c8326c0776 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift @@ -15,6 +15,7 @@ extension Configuration { case analyzerRules = "analyzer_rules" case allowZeroLintableFiles = "allow_zero_lintable_files" case strict = "strict" + case lenient = "lenient" case baseline = "baseline" case writeBaseline = "write_baseline" case checkForUpdates = "check_for_updates" @@ -103,6 +104,7 @@ extension Configuration { pinnedVersion: dict[Key.swiftlintVersion.rawValue].map { ($0 as? String) ?? String(describing: $0) }, allowZeroLintableFiles: dict[Key.allowZeroLintableFiles.rawValue] as? Bool ?? false, strict: dict[Key.strict.rawValue] as? Bool ?? false, + lenient: dict[Key.lenient.rawValue] as? Bool ?? false, baseline: dict[Key.baseline.rawValue] as? String, writeBaseline: dict[Key.writeBaseline.rawValue] as? String, checkForUpdates: dict[Key.checkForUpdates.rawValue] as? Bool ?? false diff --git a/Source/SwiftLintCore/Models/Configuration.swift b/Source/SwiftLintCore/Models/Configuration.swift index b8169afe11..bf5d6d9bc1 100644 --- a/Source/SwiftLintCore/Models/Configuration.swift +++ b/Source/SwiftLintCore/Models/Configuration.swift @@ -38,6 +38,9 @@ public struct Configuration { /// Treat warnings as errors. public let strict: Bool + /// Treat errors as warnings. + public let lenient: Bool + /// The path to read a baseline from. public let baseline: String? @@ -83,6 +86,7 @@ public struct Configuration { cachePath: String?, allowZeroLintableFiles: Bool, strict: Bool, + lenient: Bool, baseline: String?, writeBaseline: String?, checkForUpdates: Bool @@ -97,6 +101,7 @@ public struct Configuration { self.cachePath = cachePath self.allowZeroLintableFiles = allowZeroLintableFiles self.strict = strict + self.lenient = lenient self.baseline = baseline self.writeBaseline = writeBaseline self.checkForUpdates = checkForUpdates @@ -117,6 +122,7 @@ public struct Configuration { cachePath = configuration.cachePath allowZeroLintableFiles = configuration.allowZeroLintableFiles strict = configuration.strict + lenient = configuration.lenient baseline = configuration.baseline writeBaseline = configuration.writeBaseline checkForUpdates = configuration.checkForUpdates @@ -143,6 +149,7 @@ public struct Configuration { /// - parameter allowZeroLintableFiles: Allow SwiftLint to exit successfully when passed ignored or unlintable /// files. /// - parameter strict: Treat warnings as errors. + /// - parameter lenient: Treat errors as warnings. /// - parameter baseline: The path to read a baseline from. /// - parameter writeBaseline: The path to write a baseline to. /// - parameter checkForUpdates: Check for updates to SwiftLint. @@ -160,6 +167,7 @@ public struct Configuration { pinnedVersion: String? = nil, allowZeroLintableFiles: Bool = false, strict: Bool = false, + lenient: Bool = false, baseline: String? = nil, writeBaseline: String? = nil, checkForUpdates: Bool = false @@ -189,6 +197,7 @@ public struct Configuration { cachePath: cachePath, allowZeroLintableFiles: allowZeroLintableFiles, strict: strict, + lenient: lenient, baseline: baseline, writeBaseline: writeBaseline, checkForUpdates: checkForUpdates @@ -304,6 +313,7 @@ extension Configuration: Hashable { hasher.combine(reporter) hasher.combine(allowZeroLintableFiles) hasher.combine(strict) + hasher.combine(lenient) hasher.combine(baseline) hasher.combine(writeBaseline) hasher.combine(checkForUpdates) @@ -325,6 +335,7 @@ extension Configuration: Hashable { lhs.fileGraph == rhs.fileGraph && lhs.allowZeroLintableFiles == rhs.allowZeroLintableFiles && lhs.strict == rhs.strict && + lhs.lenient == rhs.lenient && lhs.baseline == rhs.baseline && lhs.writeBaseline == rhs.writeBaseline && lhs.checkForUpdates == rhs.checkForUpdates && diff --git a/Source/SwiftLintFramework/LintOrAnalyzeCommand.swift b/Source/SwiftLintFramework/LintOrAnalyzeCommand.swift index f9e24151b4..746342c301 100644 --- a/Source/SwiftLintFramework/LintOrAnalyzeCommand.swift +++ b/Source/SwiftLintFramework/LintOrAnalyzeCommand.swift @@ -169,6 +169,7 @@ package struct LintOrAnalyzeCommand { currentViolations = applyLeniency( options: options, strict: builder.configuration.strict, + lenient: builder.configuration.lenient, violations: violationsBeforeLeniency ) visitorMutationQueue.sync { @@ -179,6 +180,7 @@ package struct LintOrAnalyzeCommand { currentViolations = applyLeniency( options: options, strict: builder.configuration.strict, + lenient: builder.configuration.lenient, violations: linter.styleViolations(using: builder.storage) ) } @@ -273,15 +275,16 @@ package struct LintOrAnalyzeCommand { private static func applyLeniency( options: LintOrAnalyzeOptions, strict: Bool, + lenient: Bool, violations: [StyleViolation] ) -> [StyleViolation] { - let strict = (strict && !options.lenient) || options.strict + let leniency = options.leniency(strict: strict, lenient: lenient) - switch (options.lenient, strict) { + switch leniency { case (false, false): return violations - case (true, false): + case (false, true): return violations.map { if $0.severity == .error { return $0.with(severity: .warning) @@ -289,7 +292,7 @@ package struct LintOrAnalyzeCommand { return $0 } - case (false, true): + case (true, false): return violations.map { if $0.severity == .warning { return $0.with(severity: .error) @@ -298,7 +301,7 @@ package struct LintOrAnalyzeCommand { } case (true, true): - queuedFatalError("Invalid command line options: 'lenient' and 'strict' are mutually exclusive.") + queuedFatalError("Invalid command line or config options: 'strict' and 'lenient' are mutually exclusive.") } } @@ -394,8 +397,8 @@ private class LintOrAnalyzeResultBuilder { } } -private extension LintOrAnalyzeOptions { - func writeToOutput(_ string: String) { +extension LintOrAnalyzeOptions { + fileprivate func writeToOutput(_ string: String) { guard let outFile = output else { queuedPrint(string) return @@ -411,6 +414,15 @@ private extension LintOrAnalyzeOptions { Issue.fileNotWritable(path: outFile).print() } } + + typealias Leniency = (strict: Bool, lenient: Bool) + + // Config file settings can be overridden by either `--strict` or `--lenient` command line options. + func leniency(strict configurationStrict: Bool, lenient configurationLenient: Bool) -> Leniency { + let strict = self.strict || (configurationStrict && !self.lenient) + let lenient = self.lenient || (configurationLenient && !self.strict) + return Leniency(strict: strict, lenient: lenient) + } } private actor CorrectionsBuilder { diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift index ffca2d57ab..9fd493a068 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift @@ -56,6 +56,7 @@ final class ConfigurationTests: SwiftLintTestCase { XCTAssertEqual(reporterFrom(identifier: config.reporter).identifier, "xcode") XCTAssertFalse(config.allowZeroLintableFiles) XCTAssertFalse(config.strict) + XCTAssertFalse(config.lenient) XCTAssertNil(config.baseline) XCTAssertNil(config.writeBaseline) XCTAssertFalse(config.checkForUpdates) @@ -458,6 +459,11 @@ final class ConfigurationTests: SwiftLintTestCase { XCTAssertTrue(configuration.strict) } + func testLenient() throws { + let configuration = try Configuration(dict: ["lenient": true]) + XCTAssertTrue(configuration.lenient) + } + func testBaseline() throws { let baselinePath = "Baseline.json" let configuration = try Configuration(dict: ["baseline": baselinePath]) diff --git a/Tests/SwiftLintFrameworkTests/LintOrAnalyzeOptionsTests.swift b/Tests/SwiftLintFrameworkTests/LintOrAnalyzeOptionsTests.swift new file mode 100644 index 0000000000..07ec490791 --- /dev/null +++ b/Tests/SwiftLintFrameworkTests/LintOrAnalyzeOptionsTests.swift @@ -0,0 +1,72 @@ +@testable import SwiftLintFramework +import XCTest + +final class LintOrAnalyzeOptionsTests: XCTestCase { + private typealias Leniency = LintOrAnalyzeOptions.Leniency + + func testLeniency() { + let parameters = [ + Leniency(strict: false, lenient: false), + Leniency(strict: true, lenient: true), + Leniency(strict: true, lenient: false), + Leniency(strict: false, lenient: true), + ] + + for commandLine in parameters { + let options = LintOrAnalyzeOptions(leniency: commandLine) + for configuration in parameters { + let leniency = options.leniency(strict: configuration.strict, lenient: configuration.lenient) + if commandLine.strict { + // Command line takes precedence. + XCTAssertTrue(leniency.strict) + if !commandLine.lenient { + // `--strict` should disable configuration lenience. + XCTAssertFalse(leniency.lenient) + } + } else if commandLine.lenient { + // Command line takes precedence, and should override + // `strict` in the configuration. + XCTAssertTrue(leniency.lenient) + XCTAssertFalse(leniency.strict) + } else if configuration.strict { + XCTAssertTrue(leniency.strict) + } else if configuration.lenient { + XCTAssertTrue(leniency.lenient) + } + } + } + } +} + +private extension LintOrAnalyzeOptions { + init(leniency: Leniency) { + self.init(mode: .lint, + paths: [], + useSTDIN: true, + configurationFiles: [], + strict: leniency.strict, + lenient: leniency.lenient, + forceExclude: false, + useExcludingByPrefix: false, + useScriptInputFiles: false, + useScriptInputFileLists: false, + benchmark: false, + reporter: nil, + baseline: nil, + writeBaseline: nil, + workingDirectory: nil, + quiet: false, + output: nil, + progress: false, + cachePath: nil, + ignoreCache: false, + enableAllRules: false, + onlyRule: [], + autocorrect: false, + format: false, + compilerLogPath: nil, + compileCommands: nil, + checkForUpdates: false + ) + } +} From a7318316d997b8db8ee440fab1b9312a2a4b9287 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:14:54 -0500 Subject: [PATCH 4/5] Bump rexml from 3.3.6 to 3.3.9 (#5842) Bumps the bundler group with 1 update in the / directory: [rexml](https://github.com/ruby/rexml). Updates `rexml` from 3.3.6 to 3.3.9 - [Release notes](https://github.com/ruby/rexml/releases) - [Changelog](https://github.com/ruby/rexml/blob/master/NEWS.md) - [Commits](https://github.com/ruby/rexml/compare/v3.3.6...v3.3.9) --- updated-dependencies: - dependency-name: rexml dependency-type: indirect dependency-group: bundler ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5e6967364c..c0a88b3b3d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -122,8 +122,7 @@ GEM public_suffix (4.0.7) rchardet (1.8.0) redcarpet (3.6.0) - rexml (3.3.6) - strscan + rexml (3.3.9) rouge (4.3.0) ruby-macho (2.5.1) ruby2_keywords (0.0.5) @@ -134,7 +133,6 @@ GEM faraday (>= 0.17.3, < 3) sqlite3 (1.7.3-arm64-darwin) sqlite3 (1.7.3-x86_64-linux) - strscan (3.1.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) typhoeus (1.4.0) From 3344fc6d31b921b333f601b185f2da75e342a567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sun, 10 Nov 2024 15:32:16 +0100 Subject: [PATCH 5/5] Add cache path and directories only when commands accept them (#5851) --- CHANGELOG.md | 5 +++++ .../SwiftLintCommandPlugin.swift | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb00ebc19..cfdf749b3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,11 @@ [SimplyDanny](https://github.com/SimplyDanny) [#5167](https://github.com/realm/SwiftLint/issues/5167) +* Only pass cache path and directory paths to commands that accept these arguments + in the command plugin. + [SimplyDanny](https://github.com/SimplyDanny) + [#5848](https://github.com/realm/SwiftLint/issues/5848) + * Do not throw deprecation warning if deprecated property is not presented in configuration. [chipp](https://github.com/chipp) diff --git a/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift b/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift index d254ff8fdd..e1f562fd18 100644 --- a/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift +++ b/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift @@ -1,6 +1,19 @@ import Foundation import PackagePlugin +private let commandsNotExpectingPaths: Set = [ + "docs", + "generate-docs", + "baseline", + "reporters", + "rules", + "version", +] + +private let commandsWithoutCachPathOption: Set = commandsNotExpectingPaths.union([ + "analyze", +]) + @main struct SwiftLintCommandPlugin: CommandPlugin { func performCommand(context: PluginContext, arguments: [String]) throws { @@ -13,7 +26,7 @@ struct SwiftLintCommandPlugin: CommandPlugin { let targets = targetNames.isEmpty ? context.package.targets : try context.package.targets(named: targetNames) - guard !targets.isEmpty else { + if targets.isEmpty || !commandsNotExpectingPaths.isDisjoint(with: arguments) { try run(with: context, arguments: arguments) return } @@ -34,11 +47,12 @@ struct SwiftLintCommandPlugin: CommandPlugin { process.currentDirectoryURL = URL(fileURLWithPath: context.package.directory.string) process.executableURL = URL(fileURLWithPath: try context.tool(named: "swiftlint").path.string) process.arguments = arguments - if !arguments.contains("analyze") { - // The analyze command does not support the `--cache-path` argument. + if commandsWithoutCachPathOption.isDisjoint(with: arguments) { process.arguments! += ["--cache-path", "\(context.pluginWorkDirectory.string)"] } - process.arguments! += [directory] + if commandsNotExpectingPaths.isDisjoint(with: arguments) { + process.arguments! += [directory] + } try process.run() process.waitUntilExit()