Swiftlint: Superfluous Disable Command Violation buggy

Created on 31 Aug 2017  路  6Comments  路  Source: realm/SwiftLint

New Issue Checklist

Bug Report

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'foo.swift' (1/1)
~/test-swiftlint/foo.swift:1:33: error: Superfluous Disable Command Violation: SwiftLint rule 'file_header' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)
Done linting! Found 1 violation, 1 serious in 1 file.

Environment

  • SwiftLint version (run swiftlint version to be sure)?

    • 0.22.0

  • Installation method used (Homebrew, CocoaPods, building from source, etc)?

    • Homebrew

  • Paste your configuration file:
opt_in_rules:
  - file_header
  • Are you using nested configurations?

    • No

  • Which Xcode version are you using (check xcode-select -p)?

    • Xcode 8.3.3

  • Do you have a sample that shows the issue?
// swiftlint:disable file_header
// Copyright 2017 XXXXXX

If I remove the line with the disable command as told I do get a warning, meaning that the disable was not superfluous:

$ swiftlint lint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'foo.swift' (1/1)
~/test-swiftlint/foo.swift:1:4: warning: File Header Violation: Header comments should be consistent with project patterns. (file_header)
Done linting! Found 1 violation, 0 serious in 1 file.
bug

Most helpful comment

I'm getting the same thing. This was working in 0.21.0

All 6 comments

I'm getting the same thing. This was working in 0.21.0

I've opened #1816 that should fix the issue. It'd be awesome if some of you could try it.

I managed to compile #1816 and the incorrect error is indeed not displayed anymore.

However, to compile #1816 I had to modify the Yams projects (in Carthage/Checkouts/Yams and Carthage/Checkouts/SourceKitten/Carthage/Checkouts/Yams) to not run swiftlint because with SwiftLint 0.22 installed, an error stopped the build:

SwiftLint/Carthage/Checkouts/Yams/Sources/Yams/Node.swift:271: error: Superfluous Disable Command Violation: SwiftLint rule 'file_length' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)

Thanks for looking at this! It appears to be working for our project.

I noticed that the swiftlint:disable command needs to come before the file header comment. If the file header comment comes first, and you put // swiftlint:disable file_header at the end, I'm getting violations for both file_header and superfluous_disable_command, which is unexpected.

Does disable only work when it's at the beginning of the file?

@danj-stripe You're right, // swiftlint:disable <id> disables that rule until an // swiftlint:enable <id> is found (or the file ends). You can use // swiftlint:disable:previous to disable a previous violation.

Of course, my mistake!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcarroll-mediafly picture jcarroll-mediafly  路  3Comments

mrtj picture mrtj  路  3Comments

Den-Ree picture Den-Ree  路  3Comments

ArthurMaroulier picture ArthurMaroulier  路  3Comments

mildm8nnered picture mildm8nnered  路  3Comments