Skip to content

Commit

Permalink
Rename severity configuration to allow its name to be inferred
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny committed Mar 25, 2024
1 parent 299042a commit cabe12b
Show file tree
Hide file tree
Showing 119 changed files with 174 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct FileNameNoSpaceRule: OptInRule, SourceKitFreeRule {
}

return [StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: filePath, line: 1))]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct FileNameRule: OptInRule, SourceKitFreeRule {
}

return [StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: filePath, line: 1))]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private extension GenericTypeNameRule {
reason: """
Generic type name '\(name)' should only contain alphanumeric and other allowed characters
""",
severity: configuration.unallowedSymbolsSeverity.severity
severity: configuration.unallowedSymbolsSeverity.violationSeverity
)
)
} else if let caseCheckSeverity = configuration.validatesStartWithLowercase.severity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct RedundantTypeAnnotationRule: OptInRule, SubstitutionCorrectableRule {
return violationRanges(in: file).map { range in
StyleViolation(
ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, characterOffset: range.location)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct SyntacticSugarRule: CorrectableRule, SourceKitFreeRule {
flattenViolations(visitor.violations)
}.map { violation in
return StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, byteOffset: ByteCount(violation.position)),
reason: violation.type.violationReason)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private extension TypeNameRule {
return ReasonedRuleViolation(
position: identifier.positionAfterSkippingLeadingTrivia,
reason: "Type name '\(name)' should only contain alphanumeric and other allowed characters",
severity: nameConfiguration.unallowedSymbolsSeverity.severity
severity: nameConfiguration.unallowedSymbolsSeverity.violationSeverity
)
}
if let caseCheckSeverity = nameConfiguration.validatesStartWithLowercase.severity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct AccessibilityLabelForImageRule: ASTRule, OptInRule {

violations.append(
StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, byteOffset: offset))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct AccessibilityTraitForButtonRule: ASTRule, OptInRule {

violations.append(
StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, byteOffset: offset))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct BlanketDisableCommandRule: Rule, SourceKitFreeRule {
) -> StyleViolation {
StyleViolation(
ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: command.location(of: ruleIdentifier, in: file),
reason: reason
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct CaptureVariableRule: AnalyzerRule, CollectingRule {
.filter { capturedVariable in collectedInfo.values.contains { $0.contains(capturedVariable.usr) } }
.map {
StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, byteOffset: $0.offset))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct CommentSpacingRule: SourceKitFreeRule, SubstitutionCorrectableRule {
return violationRanges(in: file).map { range in
StyleViolation(
ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, characterOffset: range.location)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ struct ExpiringTodoRule: OptInRule {
private func severity(for violationLevel: ExpiryViolationLevel) -> ViolationSeverity? {
switch violationLevel {
case .approachingExpiry:
return configuration.approachingExpirySeverity.severity
return configuration.approachingExpirySeverity.violationSeverity
case .expired:
return configuration.expiredSeverity.severity
return configuration.expiredSeverity.violationSeverity
case .badFormatting:
return configuration.badFormattingSeverity.severity
return configuration.badFormattingSeverity.violationSeverity
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct InvalidSwiftLintCommandRule: Rule, SourceKitFreeRule {
let character = command.startingCharacterPosition(in: file)
return StyleViolation(
ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file.path, line: command.line, character: character),
reason: reason
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct PeriodSpacingRule: SourceKitFreeRule, OptInRule, SubstitutionCorrectableR
return violationRanges(in: file).map { range in
StyleViolation(
ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, characterOffset: range.location)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct QuickDiscouragedCallRule: OptInRule {

return violationOffsets(in: dictionary.enclosedArguments).map {
StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, byteOffset: $0),
reason: "Discouraged call inside a '\(name)' block")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct UnusedDeclarationRule: AnalyzerRule, CollectingRule {
allReferencedUSRs: allReferencedUSRs)
.map {
StyleViolation(ruleDescription: Self.description,
severity: configuration.severityConfiguration.severity,
severity: configuration.severity.violationSeverity,
location: Location(file: file, byteOffset: $0))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct UnusedImportRule: CorrectableRule, AnalyzerRule {
func validate(file: SwiftLintFile, compilerArguments: [String]) -> [StyleViolation] {
return importUsage(in: file, compilerArguments: compilerArguments).map { importUsage in
StyleViolation(ruleDescription: Self.description,
severity: configuration.severity,
severity: configuration.violationSeverity,
location: Location(file: file, characterOffset: importUsage.violationRange?.location ?? 1),
reason: importUsage.violationReason)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct AttributesConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = AttributesRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "attributes_with_arguments_always_on_line_above")
private(set) var attributesWithArgumentsAlwaysOnNewLine = true
@ConfigurationElement(key: "always_on_same_line")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct BlanketDisableCommandConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = BlanketDisableCommandRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "allowed_rules")
private(set) var allowedRuleIdentifiers: Set<String> = [
"file_header",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct CollectionAlignmentConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = CollectionAlignmentRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "align_colons")
private(set) var alignColons = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct ColonConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = ColonRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "flexible_right_spacing")
private(set) var flexibleRightSpacing = false
@ConfigurationElement(key: "apply_to_dictionaries")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct ComputedAccessorsOrderConfiguration: SeverityBasedRuleConfiguration {
}

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "order")
private(set) var order = Order.getSet
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct ConditionalReturnsOnNewlineConfiguration: SeverityBasedRuleConfiguration
typealias Parent = ConditionalReturnsOnNewlineRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "if_only")
private(set) var ifOnly = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ struct DeploymentTargetConfiguration: SeverityBasedRuleConfiguration {
private(set) var tvOSDeploymentTarget = Version(platform: .tvOS, major: 9)
private(set) var tvOSAppExtensionDeploymentTarget = Version(platform: .tvOSApplicationExtension, major: 9)

private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)

private let targets: [String: Version]

var parameterDescription: RuleConfigurationDescription? {
severityConfiguration
severity
for (platform, target) in targets.sorted(by: { $0.key < $1.key }) {
platform => .symbol(target.stringValue)
}
Expand All @@ -135,7 +135,7 @@ struct DeploymentTargetConfiguration: SeverityBasedRuleConfiguration {
}
for (key, value) in configuration {
if key == "severity", let value = value as? String {
try severityConfiguration.apply(configuration: value)
try severity.apply(configuration: value)
continue
}
guard let target = targets[key] else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct DiscouragedDirectInitConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = DiscouragedDirectInitRule

@ConfigurationElement(key: "severity")
var severityConfiguration = SeverityConfiguration<Parent>(.warning)
var severity = SeverityConfiguration<Parent>(.warning)

@ConfigurationElement(
key: "types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct EmptyCountConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = EmptyCountRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.error)
private(set) var severity = SeverityConfiguration<Parent>(.error)
@ConfigurationElement(key: "only_after_dot")
private(set) var onlyAfterDot = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct ExplicitInitConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = ExplicitInitRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "include_bare_init")
private(set) var includeBareInit = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ExplicitTypeInterfaceConfiguration: SeverityBasedRuleConfiguration {
}

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "excluded")
private(set) var excluded = [VariableKind]()
@ConfigurationElement(key: "allow_redundancy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct FileHeaderConfiguration: SeverityBasedRuleConfiguration {
[.anchorsMatchLines, .dotMatchesLineSeparators]

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "required_string")
private var requiredString: String?
@ConfigurationElement(key: "required_pattern")
Expand Down Expand Up @@ -60,8 +60,8 @@ struct FileHeaderConfiguration: SeverityBasedRuleConfiguration {
}
}

if let severityString = configuration[$severityConfiguration.key] {
try severityConfiguration.apply(configuration: severityString)
if let severityString = configuration[$severity.key] {
try severity.apply(configuration: severityString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct FileNameConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = FileNameRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "excluded")
private(set) var excluded: Set = ["main.swift", "LinuxMain.swift"]
@ConfigurationElement(key: "prefix_pattern")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct FileNameNoSpaceConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = FileNameNoSpaceRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>.warning
private(set) var severity = SeverityConfiguration<Parent>.warning
@ConfigurationElement(key: "excluded")
private(set) var excluded = Set<String>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct FileTypesOrderConfiguration: SeverityBasedRuleConfiguration {
}

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "order")
private(set) var order: [[FileType]] = [
[.supportingType],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct ForWhereConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = ForWhereRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "allow_for_as_filter")
private(set) var allowForAsFilter = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct ImplicitReturnConfiguration: SeverityBasedRuleConfiguration {
static let defaultIncludedKinds = Set(ReturnKind.allCases)

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "included")
private(set) var includedKinds = Self.defaultIncludedKinds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ImplicitlyUnwrappedOptionalConfiguration: SeverityBasedRuleConfiguration
}

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>.warning
private(set) var severity = SeverityConfiguration<Parent>.warning
@ConfigurationElement(key: "mode")
private(set) var mode = ImplicitlyUnwrappedOptionalModeConfiguration.allExceptIBOutlets
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct InclusiveLanguageConfiguration: SeverityBasedRuleConfiguration {
]

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "additional_terms")
private(set) var additionalTerms: Set<String>?
@ConfigurationElement(key: "override_terms")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct IndentationWidthConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = IndentationWidthRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>.warning
private(set) var severity = SeverityConfiguration<Parent>.warning
@ConfigurationElement(
key: "indentation_width",
postprocessor: { if $0 < 1 { throw Issue.invalidConfiguration(ruleID: Parent.identifier) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct ModifierOrderConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = ModifierOrderRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "preferred_modifier_order")
private(set) var preferredModifierOrder: [SwiftDeclarationAttributeKind.ModifierGroup] = [
.override,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct MultilineArgumentsConfiguration: SeverityBasedRuleConfiguration {
}

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "first_argument_location")
private(set) var firstArgumentLocation = FirstArgumentLocation.anyLine
@ConfigurationElement(key: "only_enforce_after_first_closure_on_first_line")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct MultilineParametersConfiguration: SeverityBasedRuleConfiguration {
typealias Parent = MultilineParametersRule

@ConfigurationElement(key: "severity")
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var severity = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "allows_single_line")
private(set) var allowsSingleLine = true
}
Loading

0 comments on commit cabe12b

Please sign in to comment.