Swiftlint: Can't disable file_name in a single file

Created on 3 Jul 2018  路  12Comments  路  Source: realm/SwiftLint

New Issue Checklist

Bug Report

If you try to disable the rule within the file with //swiflint:disable file_name you'll get the Superfluous Disable Command Violation.

Most helpful comment

If you're like me and would prefer to disable the rule in the file, try:
// swiftlint:disable:this file_name.
on the first line of the file.

Works for me.

All 12 comments

Have same problem

@jpsim

//swiflint:disable file_name only disables the rule after the command. Have you tried adding //swiflint:disable:previous file_name on the first line?

I think, u should just use excluded option in swiftlint.yml
like this:

file_name: 
  excluded: ["MapUtils.swift", "MapTransforms.swift", "DateUtils.swift", "Utils.swift"]

@MortMerr that's also another option which IMO is even better in most cases.

hey @marcelofabri I'm also hitting this issue (where I have a few short classes in the same file that all present a certain type of Thing so my file is called Things.swift but inside it there is no class called Things.

I tried your suggestion of // swiftlint:disable:previous on the first line and the lint warning still triggers.

(I'm using SwiftLint 0.26.0 and Xcode 9.4.1)

Same issue, I have a few files named like "SOMETHING+Extensions".
Using // swiftlint:disable:previous file_name on the first line does not remove lint warnings.

Ended up with using excluded option as @MortMerr suggested.

(SwiftLint 0.27.0 and Xcode 10 beta 5)

It's the same here, I think that the rule can be disabled when the filename contains "Extension"

You could use the new prefix_pattern and suffix_pattern options that were added to 0.27.0 to configure the rule as you want.

If you're like me and would prefer to disable the rule in the file, try:
// swiftlint:disable:this file_name.
on the first line of the file.

Works for me.

@andris-zalitis solution worked for me :) thanks man!

@andris-zalitis 's answer is correct, // swiftlint:disable:this file_name on the first line of the file.

I'm closing this ticket because this is behaving as expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Den-Ree picture Den-Ree  路  3Comments

castus picture castus  路  3Comments

SolaWing picture SolaWing  路  3Comments

muzamilhassan1987 picture muzamilhassan1987  路  3Comments

Tableau-David-Potter picture Tableau-David-Potter  路  3Comments