-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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_types_order false positive for file only containing extensions #2749
Comments
@samrayner Actually this was the intended behavior as file_type_order was designed with expecting "file_name" being turned on as well. But that is not documented and is probably not a good idea given your code example anyways. So making an exception for cases when the file only contains extensions might be a good idea. I think the easiest solution to this is to add an early return in this line when none of the @samrayner Would you be up to implement this yourself and post a PR? I've tried to lay out how this could be tackled. Just make sure to write a failing-test with your above example first before fixing it so we can ensure this doesn't reappear sometime in the future. Also don't forget to update the Changelog. :) |
An attempt to prevent files only containing extensions being flagges by the file_types_order rule
Prevents extensions being flagged as in the wrong order when a file only contains extensions and nothing else (enums, classes, structs). In this case it's not intuitive that the longest extension be considered the "main" one so the file can be considered as having no "main" type.
Prevents extensions being flagged as in the wrong order when a file only contains extensions and nothing else (enums, classes, structs). In this case it's not intuitive that the longest extension be considered the "main" one so the file can be considered as having no "main" type.
Thanks @Dschee! Pull request here: #2754 |
Prevents extensions being flagged as in the wrong order when a file only contains extensions and nothing else (enums, classes, structs). In this case it's not intuitive that the longest extension be considered the "main" one so the file can be considered as having no "main" type.
Prevents extensions being flagged as in the wrong order when a file only contains extensions and nothing else (enums, classes, structs). In this case it's not intuitive that the longest extension be considered the "main" one so the file can be considered as having no "main" type.
…tensions #2749 Fix file_types_order in extension-only files
New Issue Checklist
Describe the bug
A file containing only extensions is flagged as placed amongst the file type(s) 'main_type'.
Complete output when running SwiftLint, including the stack trace and command used
NOTE: This only occurs with the above simplified example if the file name is different to the first extended type. Renaming Test.swift to Foo.swift fixes both warnings.
Environment
swiftlint version
to be sure)?0.32.0
Homebrew
No
xcode-select -p
)?10.2.1
Non-trivial example that triggers the warning twice (first two extensions):
The text was updated successfully, but these errors were encountered: