Swiftlint reports violations for extraneous words in the same comment that follow the swiftlint rule. Many of our team have written disables that look like the one below in the example. Swiftlint should not report a violation for words that it finds that are not known rules.
The example below also reports the correct violation 79 times when I would expect only one. In combination this results in excessive reporting in some situations with the 7 lines of code below reporting 869 violations which is 11 full repeats.
$ swiftlint lint
Linting Swift files at paths
Linting 'File.swift' (1/1)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'no_indentation_spaces' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'no_indentation_spaces' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'no_indentation_spaces' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
...
[deleted 813 lines]
...
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'no_indentation_spaces' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'no_indentation_spaces' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'no_indentation_spaces' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:1:73: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'as' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'this' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'doesn't' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'expected' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
File.swift:6:42: warning: Superfluous Disable Command Violation: SwiftLint rule 'work' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
Done linting! Found 869 violations, 0 serious in 1 file.
swiftlint version to be sure)?Paste your configuration file:
base configuration
Are you using nested configurations?
No
xcode-select -p)?// swiftlint:disable no_indentation_spaces this doesn't work as expected
func loggingFunctionTest(_ message: @autoclosure () -> String,
file: StaticString = #file,
function: StaticString = #function,
line: UInt = #line) {
// swiftlint:enable no_indentation_spaces
}
Full Output:
output.txt
This is intentional as you can disable/enable several rules with the same command. It shouldn't warn several times for the same violation though.
See #2348.
We're migrating from 0.26 version. We have a lot of comments why we disable some rules in code. For example:
swiftlint:disable file_length Big class by design. Business logic is too sophisticated.
What options do we have to keep annotations on disabled rules?
We're migrating from 0.26 version. We have a lot of comments why we disable some rules in code. For example:
swiftlint:disable file_length Big class by design. Business logic is too sophisticated.What options do we have to keep annotations on disabled rules?
You can move the comment to a new line before or after the disable command.
Would a PR adding a delimiter be considered / possible? " - " comes to mind as a way to express "this is now documentation, not a new rule"
Most helpful comment
Would a PR adding a delimiter be considered / possible? " - " comes to mind as a way to express "this is now documentation, not a new rule"