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

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

Open
2 tasks done
fraioli opened this issue Oct 28, 2024 · 0 comments
Open
2 tasks done
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@fraioli
Copy link
Contributor

fraioli commented Oct 28, 2024

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

fraioli pushed a commit to fraioli/SwiftLint that referenced this issue Oct 28, 2024
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 `require_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 pushed a commit to fraioli/SwiftLint that referenced this issue Oct 29, 2024
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).
@SimplyDanny SimplyDanny added the enhancement Ideas for improvements of existing features and rules. label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

No branches or pull requests

2 participants