Fix/improve some rule descriptions

This commit is contained in:
Danny Mösch 2022-12-23 20:42:10 +01:00
parent cc44c989b7
commit 74dbd52add
9 changed files with 19 additions and 19 deletions

View File

@ -8,7 +8,8 @@ struct DiscouragedNoneNameRule: SwiftSyntaxRule, OptInRule, ConfigurationProvide
static var description = RuleDescription(
identifier: "discouraged_none_name",
name: "Discouraged None Name",
description: "Discourages name cases/static members `none`, which can conflict with `Optional<T>.none`.",
description: "Enum cases and static members named `none` are discouraged as they can conflict with " +
"`Optional<T>.none`.",
kind: .idiomatic,
nonTriggeringExamples: [
// Should not trigger unless exactly matches "none"

View File

@ -75,7 +75,7 @@ private extension GenericTypeNameRule {
violations.append(
ReasonedRuleViolation(
position: node.positionAfterSkippingLeadingTrivia,
reason: "Generic type name should only contain alphanumeric characters: '\(name)'",
reason: "Generic type name '\(name)' should only contain alphanumeric characters",
severity: .error
)
)
@ -84,13 +84,13 @@ private extension GenericTypeNameRule {
violations.append(
ReasonedRuleViolation(
position: node.positionAfterSkippingLeadingTrivia,
reason: "Generic type name should start with an uppercase character: '\(name)'",
reason: "Generic type name '\(name)' should start with an uppercase character",
severity: .error
)
)
} else if let severity = configuration.severity(forLength: name.count) {
let reason = "Generic type name should be between \(configuration.minLengthThreshold) and " +
"\(configuration.maxLengthThreshold) characters long: '\(name)'"
let reason = "Generic type name '\(name)' should be between \(configuration.minLengthThreshold) and " +
"\(configuration.maxLengthThreshold) characters long"
violations.append(
ReasonedRuleViolation(
position: node.positionAfterSkippingLeadingTrivia,

View File

@ -101,21 +101,21 @@ private extension TypeNameRule {
if !allowedSymbols.isSuperset(of: CharacterSet(charactersIn: name)) {
return ReasonedRuleViolation(
position: identifier.positionAfterSkippingLeadingTrivia,
reason: "Type name should only contain alphanumeric characters: '\(name)'",
reason: "Type name '\(name)' should only contain alphanumeric characters",
severity: .error
)
} else if nameConfiguration.validatesStartWithLowercase &&
name.first?.isLowercase == true {
return ReasonedRuleViolation(
position: identifier.positionAfterSkippingLeadingTrivia,
reason: "Type name should start with an uppercase character: '\(name)'",
reason: "Type name '\(name)' should start with an uppercase character",
severity: .error
)
} else if let severity = nameConfiguration.severity(forLength: name.count) {
return ReasonedRuleViolation(
position: identifier.positionAfterSkippingLeadingTrivia,
reason: "Type name should be between \(nameConfiguration.minLengthThreshold) and " +
"\(nameConfiguration.maxLengthThreshold) characters long: '\(name)'",
reason: "Type name '\(name)' should be between \(nameConfiguration.minLengthThreshold) and " +
"\(nameConfiguration.maxLengthThreshold) characters long",
severity: severity
)
}

View File

@ -8,7 +8,7 @@ struct DuplicatedKeyInDictionaryLiteralRule: SwiftSyntaxRule, ConfigurationProvi
static var description = RuleDescription(
identifier: "duplicated_key_in_dictionary_literal",
name: "Duplicated Key in Dictionary Literal",
description: "Dictionary literals with duplicated keys will crash in runtime",
description: "Dictionary literals with duplicated keys will crash at runtime",
kind: .lint,
nonTriggeringExamples: [
Example("""

View File

@ -8,7 +8,7 @@ struct RawValueForCamelCasedCodableEnumRule: SwiftSyntaxRule, OptInRule, Configu
static let description = RuleDescription(
identifier: "raw_value_for_camel_cased_codable_enum",
name: "Raw Value for Camel Cased Codable Enum",
description: "Camel cased cases of Codable String enums should have raw value",
description: "Camel cased cases of Codable String enums should have raw values",
kind: .lint,
nonTriggeringExamples: [
Example("""

View File

@ -6,7 +6,7 @@ struct FunctionBodyLengthRule: SwiftSyntaxRule, ConfigurationProviderRule {
static let description = RuleDescription(
identifier: "function_body_length",
name: "Function Body Length",
description: "Functions bodies should not span too many lines",
description: "Function bodies should not span too many lines",
kind: .metrics
)

View File

@ -49,15 +49,14 @@ struct IdentifierNameRule: ASTRule, ConfigurationProviderRule {
StyleViolation(ruleDescription: description,
severity: .error,
location: Location(file: file, byteOffset: offset),
reason: "\(type) name should only contain alphanumeric " +
"characters: '\(name)'")
reason: "\(type) name '\(name)' should only contain alphanumeric characters")
]
}
if let severity = severity(forLength: name.count) {
let reason = "\(type) name should be between " +
let reason = "\(type) name '\(name)' should be between " +
"\(configuration.minLengthThreshold) and " +
"\(configuration.maxLengthThreshold) characters long: '\(name)'"
"\(configuration.maxLengthThreshold) characters long"
return [
StyleViolation(ruleDescription: Self.description,
severity: severity,
@ -75,7 +74,7 @@ struct IdentifierNameRule: ASTRule, ConfigurationProviderRule {
let requiresCaseCheck = configuration.validatesStartWithLowercase
if requiresCaseCheck &&
kind != .varStatic && name.isViolatingCase && !name.isOperator {
let reason = "\(type) name should start with a lowercase character: '\(name)'"
let reason = "\(type) name '\(name)' should start with a lowercase character"
return [
StyleViolation(ruleDescription: description,
severity: .error,

View File

@ -9,7 +9,7 @@ struct LetVarWhitespaceRule: ConfigurationProviderRule, OptInRule {
static let description = RuleDescription(
identifier: "let_var_whitespace",
name: "Variable Declaration Whitespace",
description: "Let and var should be separated from other statements by a blank line",
description: "Variable declarations should be separated from other statements by a blank line",
kind: .style,
nonTriggeringExamples: [
Example("let a = 0\nvar x = 1\n\nx = 2\n"),

View File

@ -131,7 +131,7 @@ struct LiteralExpressionEndIdentationRule: Rule, ConfigurationProviderRule, OptI
private func styleViolation(for violation: Violation, in file: SwiftLintFile) -> StyleViolation {
let reason = "\(Self.description.description); " +
"expected \(violation.indentationRanges.expected.length), " +
"expected indentation of \(violation.indentationRanges.expected.length), " +
"got \(violation.indentationRanges.actual.length)"
return StyleViolation(ruleDescription: Self.description,