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

Incorrect removal of return keyword within for-loop #1960

Open
Shiaulis opened this issue Jan 9, 2025 · 3 comments
Open

Incorrect removal of return keyword within for-loop #1960

Shiaulis opened this issue Jan 9, 2025 · 3 comments

Comments

@Shiaulis
Copy link

Shiaulis commented Jan 9, 2025

Hey 👋🏾
For some reason latest version of swiftformat started suggesting this change. Can you help to understand why? Or is it a bug?

image

@nicklockwood
Copy link
Owner

This looks like a bug - it's treating the for loop as an expression maybe? But that's only valid for if/switch and only in certain places.

@nicklockwood
Copy link
Owner

@Shiaulis I've not been able to reproduce this with the code sample you provided. Can you provide a standalone code snippet that reproduces the issue? Also if you are using a custom config that may be relevant.

@Shiaulis
Copy link
Author

this is the whole function:

func selectedRow() -> Int? {
        var selectedItem: NSManagedObjectID?

        guard let selection = selectedFilterSourceBlock?() as? UserDataSourceSelection else {
            return nil
        }

        switch selection {
        case .user(let managedObjectID):
            selectedItem = managedObjectID
        case .noValue:
            return nil
        }

        if includeEveryone && selectedItem == nil {
            return 0
        }

        for (i, item) in _items.enumerated() where item.objectID == selectedItem {
            return i >= _limit ? _limit : i + (includeEveryone ? 1 : 0)
        }

        return nil
    }

This is our contig:

# Options
--allman false
--elseposition nextline
--empty void
--ifdef no-indent
--indent 4
--hexliteralcase lowercase
--nospaceoperators
--semicolons never
--stripunusedargs closure-only
--swiftversion 5.7
--trimwhitespace always
--xcodeindentation enabled
--decimalgrouping 3,5

# Rules
--rules anyObjectProtocol,assertionFailures,blankLinesAroundMark,blankLinesBetweenScopes,blankLinesBetweenImports,braces,consecutiveBlankLines,consecutiveSpaces,duplicateImports,emptyBraces,indent,initCoderUnavailable,leadingDelimiters,linebreakAtEndOfFile,numberFormatting,redundantBackticks,redundantBreak,redundantClosure,redundantExtensionACL,redundantFileprivate,redundantGet,redundantInit,redundantLet,redundantLetError,redundantNilInit,redundantObjc,redundantParens,redundantPattern,redundantRawValues,redundantReturn,redundantVoidReturnType,semicolons,spaceAroundBraces,spaceAroundBrackets,spaceAroundComments,spaceAroundGenerics,spaceAroundParens,spaceAroundOperators,spaceInsideBraces,spaceInsideBrackets,spaceInsideComments,spaceInsideGenerics,spaceInsideParens,trailingClosures,trailingCommas,trailingSpace,typeSugar,unusedArguments,void,yodaConditions,modifierOrder,elseOnSameLine,opaqueGenericParameters,blankLineAfterImports,redundantOptionalBinding,enumNamespaces,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants