Swiftlint: superfluous_disable_command reports violations on words in comment that are not rules

Created on 1 Feb 2019  路  4Comments  路  Source: realm/SwiftLint

New Issue Checklist

Describe the bug

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.

Complete output when running SwiftLint, including the stack trace and command used
$ 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.

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    0.30.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    Built from source
  • Paste your configuration file:
    base configuration

  • Are you using nested configurations?
    No

  • Which Xcode version are you using (check xcode-select -p)?
    10.1 (10B61)
  • Do you have a sample that shows the issue?
    Yes
// 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

bug

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"

All 4 comments

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"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bourquep picture bourquep  路  3Comments

Den-Ree picture Den-Ree  路  3Comments

mildm8nnered picture mildm8nnered  路  3Comments

mrtj picture mrtj  路  3Comments

ArthurMaroulier picture ArthurMaroulier  路  3Comments