Skip to content

Commit 300bf77

Browse files
g-markSteven Grosmarkyegorsch
authored
Improve file_length warnings when excluding comments (realm#3654)
* Improve `file_length` warnings when excluding comments * Update changelog * Update Source/SwiftLintFramework/Rules/Metrics/FileLengthRule.swift Co-authored-by: Yegor Chsherbatykh <[email protected]> Co-authored-by: Steven Grosmark <[email protected]> Co-authored-by: Yegor Chsherbatykh <[email protected]>
1 parent 147f43c commit 300bf77

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
[Kane Cheshire](https://github.com/kanecheshire)
3131
[#3624](https://github.com/realm/SwiftLint/issues/3624)
3232

33+
* Improve language and positioning of `file_length` warnings when
34+
`ignore_comment_only_lines: true`.
35+
[Steven Grosmark](https://github.com/g-mark)
36+
[#3654](https://github.com/realm/SwiftLint/pull/3654)
37+
3338
#### Bug Fixes
3439

3540
* Fix false positives in `empty_enum_arguments` rule when comparing values

Source/SwiftLintFramework/Rules/Metrics/FileLengthRule.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public struct FileLengthRule: ConfigurationProviderRule {
1515
],
1616
triggeringExamples: [
1717
Example(repeatElement("print(\"swiftlint\")\n", count: 401).joined()),
18-
Example((repeatElement("print(\"swiftlint\")\n", count: 400) + ["//\n"]).joined())
18+
Example((repeatElement("print(\"swiftlint\")\n", count: 400) + ["//\n"]).joined()),
19+
Example(repeatElement("print(\"swiftlint\")\n\n", count: 201).joined())
1920
]
2021
)
2122

@@ -38,11 +39,12 @@ public struct FileLengthRule: ConfigurationProviderRule {
3839
}
3940

4041
for parameter in configuration.severityConfiguration.params where lineCount > parameter.value {
41-
let reason = "File should contain \(configuration.severityConfiguration.warning) lines or less: " +
42-
"currently contains \(lineCount)"
42+
let reason = "File should contain \(configuration.severityConfiguration.warning) lines or less" +
43+
(configuration.ignoreCommentOnlyLines ? " excluding comments and whitespaces" : "") +
44+
": currently contains \(lineCount)"
4345
return [StyleViolation(ruleDescription: Self.description,
4446
severity: parameter.severity,
45-
location: Location(file: file.path, line: lineCount),
47+
location: Location(file: file.path, line: file.lines.count),
4648
reason: reason)]
4749
}
4850

Tests/SwiftLintFrameworkTests/FileLengthRuleTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class FileLengthRuleTests: XCTestCase {
1313
]
1414
let nonTriggeringExamples = [
1515
Example((repeatElement("print(\"swiftlint\")\n", count: 400) + ["//\n"]).joined()),
16-
Example(repeatElement("print(\"swiftlint\")\n", count: 400).joined())
16+
Example(repeatElement("print(\"swiftlint\")\n", count: 400).joined()),
17+
Example(repeatElement("print(\"swiftlint\")\n\n", count: 201).joined())
1718
]
1819

1920
let description = FileLengthRule.description

0 commit comments

Comments
 (0)