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

Update file_name rule to match fully-qualified names of nested types #5841

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fraioli
Copy link

@fraioli fraioli commented Oct 28, 2024

This PR is aimed to address Issue #5840. It does the following:

  1. Allows the file_name rule to match nested types when using fully-qualified names, meaning naming the following file Nested.MyType.swift is no longer a violation:
// Nested.MyType.swift

enum Nested {
    struct MyType {
    }
}
  1. Introduces a new option fully_qualified to have the file_name rule enforce using fully-qualified names, meaning naming the above file MyType.swift instead of Nested.MyType.swift would become a violation where it wasn't before (naming the file Nested.swift would still not be a violation).

@@ -21,6 +22,8 @@ final class FileNameRuleTests: SwiftLintTestCase {
rule = try FileNameRule(configuration: ["suffix_pattern": suffixPattern])
} else if let nestedTypeSeparator {
rule = try FileNameRule(configuration: ["nested_type_separator": nestedTypeSeparator])
} else if let fullyQualified {
rule = try FileNameRule(configuration: ["fully_qualified": fullyQualified])
Copy link
Author

Choose a reason for hiding this comment

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

Open to other names here such as require_fully_qualified, require_fully_qualified_names, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the last one most.

@SwiftLintBot
Copy link

SwiftLintBot commented Oct 28, 2024

37 Messages
📖 Linting Aerial with this PR took 0.93s vs 0.93s on main (0% slower)
📖 Linting Alamofire with this PR took 1.27s vs 1.27s on main (0% slower)
📖 Linting Brave with this PR took 7.2s vs 7.22s on main (0% faster)
📖 Linting DuckDuckGo with this PR took 5.12s vs 5.11s on main (0% slower)
📖 Linting Firefox with this PR took 10.74s vs 10.68s on main (0% slower)
📖 Linting Kickstarter with this PR took 9.84s vs 9.94s on main (1% faster)
📖 Linting Moya with this PR took 0.53s vs 0.53s on main (0% slower)
📖 Linting NetNewsWire with this PR took 2.87s vs 2.87s on main (0% slower)
📖 Linting Nimble with this PR took 0.77s vs 0.78s on main (1% faster)
📖 Linting PocketCasts with this PR took 8.57s vs 8.65s on main (0% faster)
📖 Linting Quick with this PR took 0.44s vs 0.45s on main (2% faster)
📖 Linting Realm with this PR took 4.53s vs 4.53s on main (0% slower)
📖 Linting Sourcery with this PR took 2.32s vs 2.31s on main (0% slower)
📖 Linting Swift with this PR took 4.55s vs 4.54s on main (0% slower)
📖 Linting VLC with this PR took 1.28s vs 1.26s on main (1% slower)
📖 Linting Wire with this PR took 17.92s vs 17.9s on main (0% slower)
📖 Linting WordPress with this PR took 11.43s vs 11.44s on main (0% faster)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/AppLock/AppLockController.Config.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/AppLock/AppLockController.PasscodeKeychainItem.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/AppLock/AppLockController.State.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/AppLock/Feature.AppLock.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/ConferenceCalling/Feature.ConferenceCalling.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/ConversationGuestLinks/Feature.ConversationGuestLinks.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/FileSharing/Feature.FileSharing.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/MLS/Feature.MLS.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/MLS/Feature.MLSMigration.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Model/FeatureConfig/SelfDeletingMessages/Feature.SelfDeletingMessages.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-data-model/Source/Notifications/NotificationDispatcher.OperationMode.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios-sync-engine/Source/UserSession/ZMUserSession/ZMUserSession.Configuration.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Tests/Mocks/AppLock/AppLockModule.MockApplicationStateProvider.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Tests/Mocks/AppLock/AppLockModule.MockAuthenticationTypeDetector.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Tests/Mocks/AppLock/AppLockModule.MockInteractor.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Tests/Mocks/AppLock/AppLockModule.MockPresenter.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Tests/Mocks/AppLock/AppLockModule.MockRouter.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Tests/Mocks/AppLock/AppLockModule.MockSession.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Tests/Mocks/AppLock/AppLockModule.MockView.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)
📖 This PR fixed a violation in Wire: /wire-ios/Wire-iOS/Sources/UserInterface/App Lock/AppLockModule.View.LockView.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any) (file_name)

Generated by 🚫 Danger

This PR is aimed to address Issue realm#5840. It does the following:

1. Allows the `file_name` rule to match nested types when using fully-qualified names, meaning naming the following file `Nested.MyType.swift` is no longer a violation:

```
// Nested.MyType.swift

enum Nested {
    struct MyType {
    }
}
```

2. Introduces a new option `fully_qualified` to have the `file_name` rule enforce using fully-qualified names, meaning naming the above file `MyType.swift` instead of `Nested.MyType.swift` would become a violation where it wasn't before (naming the file `Nested.swift` would still not be a violation).
@fraioli fraioli force-pushed the File-Name-Rule-Violations-With-Nested-Types branch from 9399bc9 to 904bad2 Compare October 29, 2024 22:03
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.

I like the extension of the rule. Thanks for the contribution!

Please find a few remarks as separate inline comment.

CHANGELOG.md Outdated Show resolved Hide resolved
Tests/SwiftLintFrameworkTests/FileNameRuleTests.swift Outdated Show resolved Hide resolved
extension StructDeclSyntax: TypeNameCollectible {}
extension TypeAliasDeclSyntax: TypeNameCollectible {}
extension EnumDeclSyntax: TypeNameCollectible {}
extension ProtocolDeclSyntax: TypeNameCollectible {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a lot of overhead only to spare one more method. Honestly, I'd prefer to go with a visit(name:String) and a visit(node:NamedDeclSyntax). The latter can just redirect to the first after extracting the name. And visit(_: ExtensionDeclSyntax) can call it directly.

names.insert(name)
}

ancestorNames.push(node.typeName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ancestorNames.push(node.typeName)
ancestorNames.push(name)

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