Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline support, a.k.a. disabling rules based on file name regexps #4908

Conversation

esilverberg
Copy link

This is another approach to implementing the "baseline" functionality that is introduced in this old PR from 2020.

To use it, you simply add to .swiftlint.yml the following section:

disabled_rules_for_files:
  rule_name:
    - filename_regexp

Where rule_name is the name of the rule, and filename_regexp is a regular expression evaluated against a filename to determine if the rule should be skipped on the given file.

In the last comment regarding this kind of functionality from this old PR, this was written:

Looking at this again for the first time in a while, there's a few things I'd like the author(s) to think through before we can consider something like this, which I think overall the concept is a good idea.

  1. Should users be able to specify the baseline file path?
  2. Should baselines apply to analyzer rules, or just lint rules?
  3. Right now the baseline implementation is fairly brittle in the sense that if the line numbers change, the baseline record becomes out of date. Do we want to consider a mechanism to minimize the thrash when say a violation is moved down by a few lines because new code was added above it?
  4. Should there be an easy way to reset the baseline? Right now you have to find the baseline file and delete it.
  5. Can we somehow leverage the lint results cache? We're already saving lint results for faster incremental linting operations, so perhaps snapshotting that would be a new command distinct from swiftlint lint?
  6. Unit tests, documentation and changelog entries would be important to add before considering merging something like this.

I don't think questions 2-6 apply to my new PR, but I'm happy to answer/respond to any additional feedback you may have! Would love to see functionality like this incorporated 🙏

@SwiftLintBot
Copy link

SwiftLintBot commented Apr 18, 2023

1 Warning
⚠️ If this is a user-facing change, please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.
68 Messages
📖 Linting Aerial with this PR took 1.06s vs 1.06s on main (0% slower)
📖 Linting Alamofire with this PR took 1.36s vs 1.37s on main (0% faster)
📖 Linting Brave with this PR took 7.27s vs 7.3s on main (0% faster)
📖 Linting DuckDuckGo with this PR took 3.5s vs 3.5s on main (0% slower)
📖 Linting Firefox with this PR took 9.5s vs 9.51s on main (0% faster)
📖 Linting Kickstarter with this PR took 10.24s vs 10.24s on main (0% slower)
📖 Linting Moya with this PR took 0.54s vs 0.54s on main (0% slower)
📖 Linting NetNewsWire with this PR took 3.06s vs 3.06s on main (0% slower)
📖 Linting Nimble with this PR took 0.62s vs 0.62s on main (0% slower)
📖 Linting PocketCasts with this PR took 7.27s vs 7.25s on main (0% slower)
📖 Linting Quick with this PR took 0.23s vs 0.23s on main (0% slower)
📖 Linting Realm with this PR took 11.02s vs 11.04s on main (0% faster)
📖 Linting SourceKitten with this PR took 0.37s vs 0.38s on main (2% faster)
📖 Linting Sourcery with this PR took 2.22s vs 2.21s on main (0% slower)
📖 Linting Swift with this PR took 4.63s vs 4.65s on main (0% faster)
📖 Linting VLC with this PR took 1.35s vs 1.36s on main (0% faster)
📖 Linting Wire with this PR took 8.3s vs 8.28s on main (0% slower)
📖 Linting WordPress with this PR took 11.32s vs 11.35s on main (0% faster)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:11:1: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly (explicit_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:11:1: warning: Explicit Top Level ACL Violation: Top-level declarations should specify Access Control Level keywords explicitly (explicit_top_level_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:11:1: warning: Required Deinit Violation: Classes should have an explicit deinit method (required_deinit)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:12:1: warning: Vertical Whitespace after Opening Braces Violation: Don't include vertical whitespace (empty line) after opening braces (vertical_whitespace_opening_braces)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:15:5: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly (explicit_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:16:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:16:48: warning: Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:17:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:18:9: warning: Prefer Nimble Violation: Prefer Nimble matchers over XCTAssert functions (prefer_nimble)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:18:9: warning: XCTest Specific Matcher Violation: Prefer the specific matcher 'XCTAssertEqual' instead (xct_specific_matcher)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:21:5: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly (explicit_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:22:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:23:53: warning: Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:25:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:26:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:32:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:34:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:35:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:41:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:42:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:48:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:49:105: warning: Force Unwrapping Violation: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:49:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:50:27: warning: Multiline Arguments Brackets Violation: Multiline arguments should have their surrounding brackets in a new line (multiline_arguments_brackets)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:50:59: warning: Multiline Arguments Violation: Arguments should be either on the same line, or one per line (multiline_arguments)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:51:1: warning: Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:51:56: warning: Multiline Arguments Brackets Violation: Multiline arguments should have their surrounding brackets in a new line (multiline_arguments_brackets)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:56:5: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly (explicit_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:57:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:58:53: warning: Legacy Objective-C Reference Type Violation: Prefer Swift value types to bridged Objective-C reference types (legacy_objc_type)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:5:1: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly (explicit_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:5:1: warning: Explicit Top Level ACL Violation: Top-level declarations should specify Access Control Level keywords explicitly (explicit_top_level_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:5:5: warning: Prefixed Top-Level Constant Violation: Top-level constants should be prefixed by k (prefixed_toplevel_constant)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:60:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:61:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:67:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:69:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:6:1: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly (explicit_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:6:1: warning: Explicit Top Level ACL Violation: Top-level declarations should specify Access Control Level keywords explicitly (explicit_top_level_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:6:5: warning: Prefixed Top-Level Constant Violation: Top-level constants should be prefixed by k (prefixed_toplevel_constant)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:70:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:76:103: warning: Force Unwrapping Violation: Force unwrapping should be avoided (force_unwrapping)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:76:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:77:27: warning: Multiline Arguments Brackets Violation: Multiline arguments should have their surrounding brackets in a new line (multiline_arguments_brackets)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:77:62: warning: Multiline Arguments Violation: Arguments should be either on the same line, or one per line (multiline_arguments)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:78:1: warning: Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:78:56: warning: Multiline Arguments Brackets Violation: Multiline arguments should have their surrounding brackets in a new line (multiline_arguments_brackets)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:81:5: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly (explicit_acl)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:92:13: warning: Explicit Type Interface Violation: Properties should have a type interface (explicit_type_interface)
📖 This PR fixed a violation in SourceKitten: /Tests/SourceKittenFrameworkTests/ModuleTests.swift:93:9: warning: Prefer Nimble Violation: Prefer Nimble matchers over XCTAssert functions (prefer_nimble)

Here's an example of your CHANGELOG entry:

* Baseline support, a.k.a. disabling rules based on file name regexps.  
  [esilverberg](https://github.com/esilverberg)
  [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)

note: There are two invisible spaces after the entry's text.

Generated by 🚫 Danger

@esilverberg esilverberg force-pushed the feature/disable_rules_per_file_in_config branch from bd85d25 to 68c801b Compare April 19, 2023 11:44
@esilverberg esilverberg force-pushed the feature/disable_rules_per_file_in_config branch from 68c801b to d4a143f Compare April 19, 2023 12:13
@SimplyDanny
Copy link
Collaborator

Sorry that this PR has been completely ignored. Meanwhile #5475 has superseded this PR. With that being merged, we now have a baseline functionality experimentally available in SwiftLint. It's different from your approach, but the results ought to be the same.

Thank you for your efforts anyway!

@SimplyDanny SimplyDanny closed this May 1, 2024
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.

3 participants