Skip to content

Conversation

mildm8nnered
Copy link
Collaborator

@mildm8nnered mildm8nnered commented Jan 29, 2023

Adds a new SwiftLint rule: blanket_disable_command

Resolves #4684

This warns (by default) when a SwiftLint rule is disabled, and then never later re-enabled. In many cases this is because the developer forgot to re-enable the rule, or somehow bodged it (e.g. // swftlint:enable some_rule), resulting in stretches of code going unintentionally un-linted.

Violations of this rule are surprisingly common. I found a bunch in the SwiftLint source code, which I've patched in various ways in this PR - some could simply be turned into // swiftlint:disable:next some_rule's and some I suppressed.

There are some rules that it doesn't make sense to re-enable, and that should apply to the whole file. An allowed_rules configuration parameter allows these to be specified. By default, file_length and single_test_class are allowed.

For these and possibly other rules, we may want to disable a particular rule always for the entire file, and to warn if it that rule is disabled with a modifier or re-enabled. The always_blanket_disable configuration parameter allows a set of rules to be specified that should always be warned on anything except a blanket disable. By default the set is empty.

This rule will also warn if you use swiftlint:disable to disable a rule that's already disabled, or swiftlint:enable to enable a rule that isn't disabled.

nonTriggeringExamples:

// swiftlint:disable unused_import
// swiftlint:enable unused_import
// swiftlint:disable unused_import unused_declaration
// swiftlint:enable unused_import
// swiftlint:enable unused_declaration
// swiftlint:disable:this unused_import")
// swiftlint:disable:next unused_import")
// swiftlint:disable:previous unused_import")

triggeringExamples:

// swiftlint:disable unused_import
// swiftlint:disable unused_import unused_declaration
// swiftlint:enable unused_import
// swiftlint:disable unused_import
// swiftlint:disable unused_import
// swiftlint:enable unused_import
// swiftlint:enable unused_import

See #4684

@mildm8nnered mildm8nnered changed the title Mildm8nnered no blanket disables rule Add no blanket disables rule Jan 30, 2023
@SwiftLintBot
Copy link

SwiftLintBot commented Feb 8, 2023

70 Warnings
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/AerialVideo.swift:76:26: warning: Blanket Disable Command Violation: The disabled 'cyclomatic_complexity' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:437:42: warning: Blanket Disable Command Violation: The disabled 'for_where' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:437:42: warning: Blanket Disable Command Violation: The disabled 'for_where' rule was already disabled (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:597:26: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/SourceList.swift:101:26: warning: Blanket Disable Command Violation: The disabled 'for_where' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Sources/CheckboxCellView.swift:10:22: warning: Blanket Disable Command Violation: The disabled 'class_delegate_protocol' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Sources/CheckboxCellView.swift:10:46: warning: Blanket Disable Command Violation: The disabled 'weak_delegate' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/Settings panels/SourcesViewController.swift:222:26: warning: Blanket Disable Command Violation: The disabled 'cyclomatic_complexity' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/Settings panels/TimeViewController.swift:55:26: warning: Blanket Disable Command Violation: The disabled 'cyclomatic_complexity' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/SidebarViewController.swift:430:1: warning: Blanket Disable Command Violation: The disabled '}' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/SidebarViewController.swift:430:1: warning: Blanket Disable Command Violation: The disabled '}*/' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Brave: /Sources/BraveShared/BraveStrings.swift:19:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /Core/APIRequest.swift:26:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /Core/Pixel.swift:221:21: warning: Blanket Disable Command Violation: The enabled 'file_length' rule was not disabled (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /Core/Pixel.swift:24:21: warning: Blanket Disable Command Violation: The enabled 'type_body_length' rule was not disabled (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /Core/PixelEvent.swift:25:22: warning: Blanket Disable Command Violation: The disabled 'type_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/AutofillLoginSettingsListViewController.swift:28:22: warning: Blanket Disable Command Violation: The disabled 'type_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/BrowsingMenu/BrowsingMenuViewController.swift:264:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/DatabaseMigration.swift:77:25: warning: Blanket Disable Command Violation: The enabled 'function_body_length' rule was not disabled (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/HomeMessageViewModelBuilder.swift:82:25: warning: Blanket Disable Command Violation: The enabled 'function_body_length' rule was not disabled (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/TrackerImageCache.swift:107:26: warning: Blanket Disable Command Violation: The disabled 'cyclomatic_complexity' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGo/TrackerImageCache.swift:107:26: warning: Blanket Disable Command Violation: The disabled 'cyclomatic_complexity' rule was already disabled (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/AutofillLoginListViewModelTests.swift:20:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarksExporterTests.swift:131:25: warning: Blanket Disable Command Violation: The enabled 'line_length' rule was not disabled (blanket_disable_command)
⚠️ This PR introduced a violation in DuckDuckGo: /DuckDuckGoTests/BookmarksExporterTests.swift:201:26: warning: Blanket Disable Command Violation: The disabled 'function_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Firefox: /Client/Extensions/UIWindow+Extension.swift:7:22: warning: Blanket Disable Command Violation: The disabled 'first_where' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Firefox: /Client/Frontend/Strings.swift:5:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Firefox: /Tests/XCUITests/DesktopModeTests.swift:7:22: warning: Blanket Disable Command Violation: The disabled 'empty_count' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Kickstarter: /Library/Strings.swift:7:22: warning: Blanket Disable Command Violation: The disabled 'valid_docs' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Kickstarter: /Library/Strings.swift:8:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Kickstarter: /Library/ViewModels/DiscoveryPostcardViewModelTests.swift:7:22: warning: Blanket Disable Command Violation: The disabled 'force_unwrapping' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Kickstarter: /bin/StringsScript/Tests/StringsScriptTests/StringsScriptTests.swift:5:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Moya: /Examples/_shared/GitHubAPI.swift:1:22: warning: Blanket Disable Command Violation: The disabled 'force_unwrapping' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Moya: /Tests/MoyaTests/MoyaProviderSpec.swift:1:34: warning: Blanket Disable Command Violation: The disabled 'type_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in NetNewsWire: /Widget/Resources/Localized.swift:1:22: warning: Blanket Disable Command Violation: The disabled 'all' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Nimble: /Sources/Nimble/DSL.swift:74:25: warning: Blanket Disable Command Violation: The enabled 'line_length' rule was not disabled (blanket_disable_command)
⚠️ This PR introduced a violation in PocketCasts: /podcasts/Strings+Generated.swift:1:22: warning: Blanket Disable Command Violation: The disabled 'all' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in PocketCasts: /podcasts/Strings+L10n.swift:159:22: warning: Blanket Disable Command Violation: The disabled 'convenience_type' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Realm: /Realm/ObjectServerTests/SwiftObjectServerTests.swift:2393:26: warning: Blanket Disable Command Violation: The disabled 'multiple_closures_with_trailing_closure' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Realm: /RealmSwift/Tests/PrimitiveMapTests.swift:23:22: warning: Blanket Disable Command Violation: The disabled 'cyclomatic_complexity' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Realm: /RealmSwift/Tests/QueryTests.swift:23:22: warning: Blanket Disable Command Violation: The disabled 'large_tuple' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Realm: /RealmSwift/Tests/QueryTests.swift:23:34: warning: Blanket Disable Command Violation: The disabled 'vertical_parameter_alignment' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Realm: /RealmSwift/Tests/RealmCollectionTypeTests.swift:19:22: warning: Blanket Disable Command Violation: The disabled 'type_name' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in SourceKitten: /Source/SourceKittenFramework/File.swift:8:34: warning: Blanket Disable Command Violation: The disabled 'type_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in SourceKitten: /Source/SourceKittenFramework/StatementKind.swift:1:22: warning: Blanket Disable Command Violation: The disabled 'identifier_name' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in SourceKitten: /Source/SourceKittenFramework/library_wrapper_Clang_C.swift:7:22: warning: Blanket Disable Command Violation: The disabled 'unused_declaration' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in SourceKitten: /Source/SourceKittenFramework/library_wrapper_SourceKit.swift:10:22: warning: Blanket Disable Command Violation: The disabled 'unused_declaration' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/AutoHashable.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'all' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/Coding.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'vertical_whitespace' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/Coding.generated.swift:3:42: warning: Blanket Disable Command Violation: The disabled 'trailing_newline' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/Description.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'vertical_whitespace' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/Equality.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'vertical_whitespace' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/JSExport.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'vertical_whitespace' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/JSExport.generated.swift:3:42: warning: Blanket Disable Command Violation: The disabled 'trailing_newline' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryRuntime/Sources/Generated/Typed.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'vertical_whitespace' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/Generating/SwiftTemplateSpecs.swift:23:26: warning: Blanket Disable Command Violation: The disabled 'function_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/GeneratorSpec.swift:14:26: warning: Blanket Disable Command Violation: The disabled 'function_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/Models/TypedSpec.generated.swift:13:22: warning: Blanket Disable Command Violation: The disabled 'function_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/Parsing/ComposerSpec.swift:18:22: warning: Blanket Disable Command Violation: The disabled 'type_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/Parsing/ComposerSpec.swift:20:26: warning: Blanket Disable Command Violation: The disabled 'function_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/Parsing/FileParser + MethodsSpec.swift:15:26: warning: Blanket Disable Command Violation: The disabled 'function_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/Parsing/FileParserSpec.swift:14:26: warning: Blanket Disable Command Violation: The disabled 'function_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /SourceryTests/SourcerySpec.swift:15:34: warning: Blanket Disable Command Violation: The disabled 'type_body_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Context/AutoLenses.swift:28:22: warning: Blanket Disable Command Violation: The disabled 'identifier_name' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Generated/AutoHashable.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'all' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Generated/AutoLenses.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'variable_name' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Generated/AutoMockable.generated.swift:3:22: warning: Blanket Disable Command Violation: The disabled 'line_length' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Sourcery: /Templates/Tests/Generated/AutoMockable.generated.swift:4:22: warning: Blanket Disable Command Violation: The disabled 'variable_name' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Wire: /Wire-iOS/Generated/Assets+Generated.swift:1:22: warning: Blanket Disable Command Violation: The disabled 'all' rule should be re-enabled before the end of the file (blanket_disable_command)
⚠️ This PR introduced a violation in Wire: /Wire-iOS/Generated/Strings+Generated.swift:1:22: warning: Blanket Disable Command Violation: The disabled 'all' rule should be re-enabled before the end of the file (blanket_disable_command)
18 Messages
📖 Linting Aerial with this PR took 1.04s vs 1.04s on main (0% slower)
📖 Linting Alamofire with this PR took 1.34s vs 1.34s on main (0% slower)
📖 Linting Brave with this PR took 7.27s vs 7.25s on main (0% slower)
📖 Linting DuckDuckGo with this PR took 3.11s vs 3.1s on main (0% slower)
📖 Linting Firefox with this PR took 9.17s vs 9.12s on main (0% slower)
📖 Linting Kickstarter with this PR took 10.07s vs 10.12s on main (0% faster)
📖 Linting Moya with this PR took 0.52s vs 0.53s on main (1% faster)
📖 Linting NetNewsWire with this PR took 3.02s vs 3.01s on main (0% slower)
📖 Linting Nimble with this PR took 0.6s vs 0.58s on main (3% slower)
📖 Linting PocketCasts with this PR took 7.07s vs 7.07s on main (0% slower)
📖 Linting Quick with this PR took 0.23s vs 0.22s on main (4% slower)
📖 Linting Realm with this PR took 11.32s vs 11.33s on main (0% faster)
📖 Linting SourceKitten with this PR took 0.43s vs 0.43s on main (0% slower)
📖 Linting Sourcery with this PR took 2.18s vs 2.18s on main (0% slower)
📖 Linting Swift with this PR took 4.75s vs 4.75s on main (0% slower)
📖 Linting VLC with this PR took 1.35s vs 1.33s on main (1% slower)
📖 Linting Wire with this PR took 8.22s vs 8.19s on main (0% slower)
📖 Linting WordPress with this PR took 10.98s vs 11.0s on main (0% faster)

Generated by 🚫 Danger

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-no-blanket-disables-rule branch from 5cc14a6 to f370aa7 Compare February 11, 2023 11:19
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-no-blanket-disables-rule branch 2 times, most recently from 16ee74e to 413da97 Compare February 26, 2023 17:07
@SimplyDanny
Copy link
Collaborator

In general, I like this rule a lot! The OSS findings and the findings in SwiftLint itself splendidly show how much SwiftLint misses it.

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-no-blanket-disables-rule branch from 413da97 to 35f25e0 Compare February 28, 2023 22:00
@mildm8nnered
Copy link
Collaborator Author

In general, I like this rule a lot! The OSS findings and the findings in SwiftLint itself splendidly show how much SwiftLint misses it.

Thanks! I just saw so many people just disabling stuff for the remainder of the file to fix one warning that it got annoying - we have a custom Danger script to do (some of) this, but much nicer to just have it baked in. And yes, it does seem to get a lot of hits :-)

Not entirely sure that no_blanket_disable is the best naming. Possibly blanket_disable_command, to echo superfluous_disable_command?

Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, blanket_disable_command sounds better to me. Also, the wording of the violation messages can be improved. I made a few suggestions. Please let me know what you think.

@mildm8nnered
Copy link
Collaborator Author

Indeed, blanket_disable_command sounds better to me. Also, the wording of the violation messages can be improved. I made a few suggestions. Please let me know what you think.

Cool - I went with blanket_disable_command and all your reason suggestions.

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-no-blanket-disables-rule branch from c88f83f to 6b52cb2 Compare March 4, 2023 18:01
Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just found some more points I'd like to discuss. Sorry! 😅

Comment on lines 3 to 4
public private(set) var allowedRuleIdentifiers: Set<String> = ["file_length", "single_test_class"]
public private(set) var alwaysBlanketDisableRuleIdentifiers: Set<String> = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the other way around?

Suggested change
public private(set) var allowedRuleIdentifiers: Set<String> = ["file_length", "single_test_class"]
public private(set) var alwaysBlanketDisableRuleIdentifiers: Set<String> = []
public private(set) var allowedRuleIdentifiers: Set<String> = []
public private(set) var alwaysBlanketDisableRuleIdentifiers: Set<String> = ["file_length", "single_test_class"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually correct - the intention is that by default, the rule will not complain about

// swiftlint:disable file_length, for example, even though it's not re-enabled, because it makes sense to just disable it once for the whole file, and there's no point in doing // swiftlint:enable file_length at the end of the file.

Adding a rule to the alwaysBlanketDisableRuleIdentifiers goes one step further, by warning the user on any SwiftLint command affecting the rule, that is anything other than // swiftlint:disable file_length. I didn't want to enable that by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made one slight modification though - any rules in alwaysBlanketDisableRuleIdentifiers are automatically "allowed"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, got it ... this is tricky, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right behaviour, but maybe the naming isn't quite perfect. I went with allowed_rules and always_blanket_disable, but maybe there's something better, although I don't have any good suggestions.

I've also just added file_header, file_name, and file_name_no_space to the default allowed rules list.

@mildm8nnered
Copy link
Collaborator Author

Just found some more points I'd like to discuss. Sorry! 😅

No worries :-) I'll try and get to these today ...

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-no-blanket-disables-rule branch from 8f50371 to 7f76874 Compare March 5, 2023 15:49
@mildm8nnered mildm8nnered changed the title Add no blanket disables rule Add blanket_disable_command rule Mar 5, 2023
@mildm8nnered
Copy link
Collaborator Author

Just found some more points I'd like to discuss. Sorry! 😅

No worries :-) I'll try and get to these today ...

ok - so I think I've addressed everything from that last batch :-)

return violations
}

private func violation(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indirection really needed for only one saved conversion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in three cases I have a RuleIdentifier (so they use the indirection), and then in two cases, in validateAlwaysBlanketDisable, I have the string.

I couldn't see anyway round that - the indirection felt cleaner than making the three call sites call stringRepresentation themselves.

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-no-blanket-disables-rule branch from 7f76874 to 6455403 Compare March 5, 2023 21:55
@SimplyDanny SimplyDanny merged commit 0bd8a7a into realm:main Mar 7, 2023
@SimplyDanny
Copy link
Collaborator

Well done. Thanks @mildm8nnered!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule Request: no_blanket_disables - disallow disabling SwiftLint rules for the entire file

3 participants