最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - SQL formatting inside an XML not working in Spotless using Prettier - Stack Overflow

programmeradmin4浏览0评论

I am trying to use Spotless formatter to format XML that have SQL in it. Like this

<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
    xmlns:xsi=";
    xmlns=";
    xsi:schemaLocation="
        .9.xsd">
    <changeSet id="0195ed19-d3c2-7eb4-9322-55ace4932598">
        <sql splitStatements="true">
            <![CDATA[
            CREATE TABLE IF NOT EXISTS students
            (
                id character varying(18) NOT NULL,
                name character varying(32) NOT NULL
            )
            ]]>
        </sql>
        <rollback>
            <sql splitStatements="true">
                <![CDATA[
                DROP TABLE IF EXISTS students
                ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>

I am using following configuration

    format("xml") {
        target("tt.xml")
        toggleOffOn()
        prettier().config(mapOf("parser" to "html", "tabWidth" to 4))
        withinBlocks("SQL Statements", "<![CDATA[", "]]>") {
            prettier(mapOf("prettier" to "3.5.3", "prettier-plugin-sql" to "0.18.0")).config(
                mapOf(
                    "parser" to "sql",
                    "language" to "sql",
                    "tabWidth" to 4,
                ),
            )
        }
    }

But I am getting this error

There were 1 lint error(s), they must be fixed or suppressed.
  tt.xml:LINE_UNDEFINED toggle(com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException) Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: ConfigError: Couldn't resolve parser "sql".) (...)
  Resolve these lints or suppress with `suppressLintsFor`

Is there anyway to fix this error?

I am trying to use Spotless formatter to format XML that have SQL in it. Like this

<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
    xmlns:xsi="http://www.w3./2001/XMLSchema-instance"
    xmlns="http://www.liquibase./xml/ns/dbchangelog"
    xsi:schemaLocation="http://www.liquibase./xml/ns/dbchangelog
        https://www.liquibase./xml/ns/dbchangelog/dbchangelog-4.9.xsd">
    <changeSet id="0195ed19-d3c2-7eb4-9322-55ace4932598">
        <sql splitStatements="true">
            <![CDATA[
            CREATE TABLE IF NOT EXISTS students
            (
                id character varying(18) NOT NULL,
                name character varying(32) NOT NULL
            )
            ]]>
        </sql>
        <rollback>
            <sql splitStatements="true">
                <![CDATA[
                DROP TABLE IF EXISTS students
                ]]>
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>

I am using following configuration

    format("xml") {
        target("tt.xml")
        toggleOffOn()
        prettier().config(mapOf("parser" to "html", "tabWidth" to 4))
        withinBlocks("SQL Statements", "<![CDATA[", "]]>") {
            prettier(mapOf("prettier" to "3.5.3", "prettier-plugin-sql" to "0.18.0")).config(
                mapOf(
                    "parser" to "sql",
                    "language" to "sql",
                    "tabWidth" to 4,
                ),
            )
        }
    }

But I am getting this error

There were 1 lint error(s), they must be fixed or suppressed.
  tt.xml:LINE_UNDEFINED toggle(com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException) Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: ConfigError: Couldn't resolve parser "sql".) (...)
  Resolve these lints or suppress with `suppressLintsFor`

Is there anyway to fix this error?

Share Improve this question asked Mar 31 at 17:00 nicholasnetnicholasnet 2,2874 gold badges25 silver badges54 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

in the configurations try to load both prettier and SQL plugging's globally.

prettier(mapOf("prettier" to "3.5.3", "prettier-plugin-sql" to "0.18.0")).config(mapOf("parser" to "html", "tabWidth" to 4))

发布评论

评论列表(0)

  1. 暂无评论