jcberquist / commandbox-cfformat

A CommandBox module for formatting CFML component files.
MIT License
22 stars 10 forks source link

cfquery in tag islands with conditional cfqueryparams #87

Open TheRealAgentK opened 4 years ago

TheRealAgentK commented 4 years ago

I found another cfquery-inside-of-tag-islands problem.

This is what I have pre-formatting:

        <cfquery name="fghfgf" datasource="#dsn#">
            UPDATE fghfghfg
            SET
                memberUUID = memberUUID
                <cfif structKeyExists( arguments.memberKeys, "fghfghfgh" ) and not arguments.doSomething>
                    ,fghfghfgh = <cfqueryparam cfsqltype="cf_sql_varchar" value="#left(htmlEditFormat( arguments.memberKeys.fghfghfgh ),30)#">
                </cfif>
                <cfif structKeyExists( arguments.memberKeys, "fghfghfghfgfg" )>
                    ,fghfghfghfgfg = getDate()
                </cfif>
                ...

The outcome I get is:

        <cfquery name="fghfgf" datasource="#dsn#">
            UPDATE fghfghfg
            SET
                memberUUID = memberUUID
                <cfif structKeyExists( arguments.memberKeys, "fghfghfgh" ) and not arguments.doSomething>
                    ,fghfghfgh = <cfqueryparam
            cfsqltype="cf_sql_varchar"
            value="#left(
                htmlEditFormat( arguments.memberKeys.fghfghfgh ),
                30
            )#"
        >
                </cfif>
                <cfif structKeyExists( arguments.memberKeys, "fghfghfghfgfg" )>
                    ,fghfghfghfgfg = getDate()
                </cfif>

It seems it has an issue with the correct indentation of the nested cfqueryparam tag.

What the outcome probably should be from my point of view is:

        <cfquery name="fghfgf" datasource="#dsn#">
            UPDATE fghfghfg
            SET
                memberUUID = memberUUID
                <cfif structKeyExists( arguments.memberKeys, "fghfghfgh" ) and not arguments.doSomething>
                    ,fghfghfgh = <cfqueryparam
                        cfsqltype="cf_sql_varchar"
                        value="#left(
                            htmlEditFormat( arguments.memberKeys.fghfghfgh ),
                            30
                        )#"
                    >
                </cfif>
                <cfif structKeyExists( arguments.memberKeys, "fghfghfghfgfg" )>
                    ,fghfghfghfgfg = getDate()
                </cfif>
jcberquist commented 4 years ago

Thanks for the report. This is a tricky situation (as things stand now). Inside of cfquery tags, cformat endeavors to preserve the white space formatting that is already in place. It does not up the indent level inside the body of tags within the cfquery, but preserves what you already have in place. So when it decides to render the cfqueryparam over multiple lines, it just uses an indent level of "cfquery + 1" to indent the attributes of the param. I don't currently have a good way to compute the "actual" indent level of tags inside of the cfquery (i.e. how nested they are), while keeping the rendered indent level unchanged. The only nested tag tracking done is done by the indent level, and that does not change inside of a cfquery tag (currently).

I will keep thinking about possible solutions for this.

TheRealAgentK commented 4 years ago

Ah ok, I understand.

For now I'm working around it using the ignore statements to leave the formatting as it is in my first sample, so it's not terrible at the moment :)