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 line break on assignment of function #508

Closed
matthargett opened this issue Jul 26, 2022 · 1 comment · Fixed by #545
Closed

incorrect line break on assignment of function #508

matthargett opened this issue Jul 26, 2022 · 1 comment · Fixed by #545
Labels
bug Something isn't working

Comments

@matthargett
Copy link

exports.ScalarLeafsRule = function(context)
        return {
                Field = function(_self, node)
                        local type_ = context:getType()
                        local selectionSet = node.selectionSet
                        if type_ then
                                if isLeafType(getNamedType(type_)) then
                                        if selectionSet then
                                                local fieldName = node.name.value
                                                local typeStr = inspect(type_)
                                                context:reportError(
                                                        GraphQLError.new(
                                                                ('Field "%s" must not have a selection since type "%s" has no subfields.'):format(
                                                                        fieldName,
                                                                        typeStr
                                                                ),
                                                                selectionSet
                                                        )
                                                )
                                        end
                                elseif not selectionSet then
                                        local fieldName = node.name.value
                                        local typeStr = inspect(type_)
                                        context:reportError(
                                                GraphQLError.new(
                                                        ('Field "%s" of type "%s" must have a selection of subfields. Did you mean "%s { ... }"?'):format(
                                                                fieldName,
                                                                typeStr,
                                                                fieldName
                                                        ),
                                                        node
                                                )
                                        )
                                end
                        end
                end,
        }
end

image

@JohnnyMorganz
Copy link
Owner

[Copying message from offline]
The reason this is hanging is because it produces less lines...
That is because of this expression

context:reportError(
    GraphQLError.new(
        ('Field "%s" of type "%s" must have a selection of subfields. Did you mean "%s { ... }"?'):format(
            fieldName,
            typeStr,
            fieldName
        ),
        node
    )
)

Because, when we hang at the equals token, the block gets indented a level further, and the extra indentation causes a re-formatting to

context:reportError(
    GraphQLError.new(
        (
            'Field "%s" of type "%s" must have a selection of subfields. Did you mean "%s { ... }"?'
        ):format(fieldName, typeStr, fieldName),
        node
    )
)

which... technically has less lines

The reason it only gets reformatted when the block is indented is because the parentheses expression finishes just before the char limit, and when we indent it now goes over it.
image


One potential fix we could do here is to just prevent the expression ("str"):call from ever expanding the parentheses, as it provides no added benefit. It doesn't fix the underlying cause, but it should stop this from hanging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants