-
I apply the formatter for our custom SQL-like language, and it does a good job. But in our dialect, we have a version data type with values like 3.14.5, and the latest versions of formatter throw an error:
Is there any possibility of extending the formatter with additional data types? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can define a custom dialect. See: https://github.com/sql-formatter-org/sql-formatter/blob/master/docs/dialect.md#custom-dialect-configuration-experimental There's no real way of defining a custom data-type per se, but you can make the formatter treat it as a string, by defining a regex to match it: tokenizerOptions: {
stringTypes: [
"''", // the string types of the SQL dialect you're extending
{ regex: "\d+.\d+.\d+" }, // regex to match version numbers
],
} |
Beta Was this translation helpful? Give feedback.
Hmm... yeah, it happens that the tokenizer tries to match NUMBER token before STRING, so it ends up matching
4.36
as a NUMBER.But I think you can instead use
identTypes
(to treat it as an identifier), which gets matched before number.