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

[prettier-plugin-sql] Invalid paramTypes value. Expected , but received { named: [":"] }. #233

Closed
nick-keller opened this issue Oct 27, 2022 · 10 comments · Fixed by #301
Closed
Labels

Comments

@nick-keller
Copy link

Hello and thanks for this awesome plugin.

I am trying to configure the paramTypes option as defined in sql-formatter, but when I do:

{
  "prettier": {
    "paramTypes": {
      "named": [
        ":"
      ]
    }
  }
}

I get the following error when running prettier:

[error] Invalid paramTypes value. Expected , but received { named: [":"] }.

I am not sure why or how to fix it.

@JounQin
Copy link
Member

JounQin commented Oct 27, 2022

Did you try https://github.com/sql-formatter-org/sql-formatter itself? This plugin is just a simple wrapper of it.

I don't have much time for OSS due to business these days, so PR welcome.

@JounQin
Copy link
Member

JounQin commented Oct 27, 2022

paramTypes: {
since: '0.11.0',
category: 'Config',
type: 'choice',
description:
'Specifies parameter types to support when parsing SQL prepared statements for `sql-formatter`.',
choices: [
{
value: Object,
description:
'Specifies parameter types to support when parsing SQL prepared statements.',
},
],
},

It seems the definition is incorrect.

@ewhauser
Copy link
Contributor

Running into the same issue. it does appear that this is a valid config for that option: https://github.com/sql-formatter-org/sql-formatter/blob/master/docs/paramTypes.md#option-value.

I'm trying to configure via .prettierrc:

 {
      "overrides": [
         {
             "files": "*.sql",
             "options": {
                 "language": "postgresql",
                 "paramTypes": {
                     "numbered": ["$"],
                     "named": ["@"]
                 }
             }
         }
     ]
}

If I remove the paramTypes property, then it is configured as expected.

@nick-keller
Copy link
Author

Hey @JounQin ,
It looks correct to me, but I have no experience in developing prettier plugins, could you please point to some resources?

@chmaltsp
Copy link

Also seeing this error.. any updates here?

@nick-keller
Copy link
Author

For anyone still looking for a solution, I removed prettier-plugin-sql and did this.
It's less elegant as it is not a prettier plugin, but it works.

@JounQin
Copy link
Member

JounQin commented Apr 8, 2023

blocked by prettier/prettier#14671

@rdsedmundo
Copy link

I used pnpm's package patch functionality to force the options to be passed manually here as a temporary workaround:

index.cjs

        let formatted = typeof value === 'string' ? format(value, options) : parser.sqlify(value, { type, database })

->

                let formatted = typeof value === 'string'
                    ? format(value, { ...options,
                        paramTypes: {
                          numbered: ['$'],
                          named: [':'],
                        }
                      })
                    : parser.sqlify(value, { type, database });

@gaving
Copy link

gaving commented May 22, 2023

Burned by this myself, just gonna use the patch above..

@JounQin
Copy link
Member

JounQin commented Nov 9, 2023

I got an idea that we can parse string config instead and JSON.parse it back, or even jsox for simpler usage. PR welcome if anyone what to try.

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

Successfully merging a pull request may close this issue.

6 participants