Skip to content

file_name rule does not consider fully qualified names of nested types #5840

@fraioli

Description

@fraioli

New Issue Checklist

Bug Description

When declaring a nested type in its own file, the file_name rule sees a violation if the file is named according to that nested type's fully qualified name. For example, naming the following file Nested.MyType.swift is a violation:

// Nested.MyType.swift

enum Nested {
    struct MyType {
    }
}
$ swiftlint --config config.yaml Nested.MyType.swift     
Linting Swift files at paths Nested.MyType.swift
Linting 'Nested.MyType.swift' (1/1)
/tmp/Nested.MyType.swift:1:1: warning: File Name Violation: File name should match a type or extension declared in the file (if any). (file_name)
Done linting! Found 1 violation, 0 serious in 1 file.

The file_name rule only allows the above file to be named Nested.swift or MyType.swift.

Environment

  • SwiftLint version: 0.57.0
  • Xcode version: Xcode 16.0, Build version 16A242d
  • Installation method used: Homebrew as well as building from source
  • Configuration file:
opt_in_rules:
  - file_name

Are you using nested configurations? No

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIdeas for improvements of existing features and rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions