realm / realm/SwiftLint

Rules disabled by configuration file cannot be enabled inline

Open
#3,662 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
  • Updated SwiftLint to the latest version
  • I searched for existing GitHub issues (apologies if I didn't do a good job here)
Describe the bug

This isn't really a bug as much as a feature request, but this template felt closer to the discussion I'm hoping this starts than the one for rule requests.

It appears that rules explicitly disabled via the configuration file cannot be temporarily re-enabled inline via a // swiftlint:enable annotation. Another way of phrasing my issue is that rules cannot be disabled by default, but re-enabled on an inline basis.

My specific use case is something similar to the rule requested in https://github.com/realm/SwiftLint/pull/3505, which we're choosing to implement as a simple regex custom_rule for the default keyword. However, my codebase doesn't want this rule to be enforced on all switches, and we'd prefer to the rule to be disabled by default. We'd then choose to enable the rule inline on a case-by-case basis where we think it could provide some benefits.

The issue is that the configuration choices for the rule are as follows:

  • enable the rule across the board: this is at ends with our preference for being disabled by default
  • disable the rule in the configuration file: this disables the rule by default, but this means we can't enable it inline
  • enable for specific files: since we're using a custom rule, we can define a list of files to apply the rule to using the "include" option. this adds a little friction to applying the rule to new call-sites, and is a bit brittle in that renaming the file removes the linter check.

Ideally, we could enable otherwise disabled rules inline via comments. Another option might be to define a set of rules in the configuration file that have this behavior of being "enable-able but disabled by default".

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Linting Swift files in current working directory
Linting 'File.swift' (1/1)
Done linting! Found 0 violations, 0 serious in 1 file.
Environment
  • SwiftLint version (run swiftlint version to be sure)? 0.43.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
  • Paste your configuration file:
disabled_rules:
  - type_name
  • Are you using nested configurations? No
  • Which Xcode version are you using (check xcodebuild -version)? Xcode 12.5
  • Do you have a sample that shows the issue? Adjust the command here using the paths relevant to your file/configuration file
swiftlint lint --path File.swift --no-cache --config .swiftlint.yml

File.swift

// swiftlint:enable type_name
struct VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName { }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running swiftlint lint --path File.swift --no-cache --config .swiftlint.yml with type_name under disabled_rules and the inline enable annotation shown in the issue. Trace how configuration-level disabled rules and inline annotations are handled. Done means a rule disabled in .swiftlint.yml can be enabled for a specific inline scope and the sample violation is reported.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.