Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ This makes SQL Formatter available as a global variable `window.sqlFormatter`.
- [Vim extension](https://github.com/fannheyward/coc-sql/)
- [Prettier plugin](https://github.com/un-ts/prettier/tree/master/packages/sql)

We provide **JSON Schema** for `.sql-formatter.json` configuration file, enabling autocompletion and IntelliSense support in editors.

- [JSON Schema link](https://raw.githubusercontent.com/sql-formatter-org/sql-formatter/refs/heads/master/schema.json)
- **Usage Guides:**
- [Using the schema in VSCode](https://code.visualstudio.com/docs/languages/json#_mapping-in-the-user-settings)
- [Using the schema in Zed](https://zed.dev/docs/languages/json#schema-specification-via-settings)


### Usage as ESLint plugin

- Inside `eslint-plugin-sql` by using the rule [eslint-plugin-sql#format](https://github.com/gajus/eslint-plugin-sql#format).
Expand Down
134 changes: 134 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"description": "Configuration files for sql-formatter",
"title": "SQL Formatter",
"additionalProperties": false,
"type": "object",
"properties": {
"dataTypeCase": {
"description": "Converts data types to upper- or lowercase.",
"$ref": "#/$defs/casing"
},
"denseOperators": {
"description": "Toggles spacing around SQL operators. (Does not apply to logical operators (AND, OR, XOR))",
"type": "boolean",
"default": false
},
"expressionWidth": {
"description": "Determines maximum length of parenthesized expressions.",
"type": "number",
"default": 50,
"exclusiveMinimum": 0
},
"functionCase": {
"description": "Converts function names to upper- or lowercase.",
"$ref": "#/$defs/casing"
},
"identifierCase": {
"description": "[Experimental] Converts identifiers to upper- or lowercase. Only unquoted identifiers are converted.",
"$ref": "#/$defs/casing"
},
"keywordCase": {
"description": "Converts reserved keywords to upper- or lowercase.",
"$ref": "#/$defs/casing"
},
"language": {
"description": "Specifies the SQL dialect to use.",
"enum": [
"sql",
"bigquery",
"db2",
"db2i",
"duckdb",
"hive",
"mariadb",
"mysql",
"tidb",
"n1ql",
"plsql",
"postgresql",
"redshift",
"singlestoredb",
"snowflake",
"spark",
"sqlite",
"transactsql",
"trino"
]
},
"linesBetweenQueries": {
"description": "Decides how many empty lines to leave between SQL statements.",
"type": "number",
"default": 1,
"exclusiveMinimum": 0
},
"logicalOperatorNewline": {
"description": "Decides newline placement before or after logical operators (AND, OR, XOR).",
"enum": ["before", "after"],
"default": "before"
},
"newlineBeforeSemicolon": {
"description": "Whether to place query separator (;) on a separate line.",
"type": "boolean",
"default": false
},
"paramTypes": {
"description": "Specifies parameter types to support when parsing SQL prepared statements.",
"type": "object",
"additionalProperties": false,
"properties": {
"positional": {
"description": "True to enable ? placeholders, false to disable them.",
"type": "boolean"
},
"numbered": {
"description": "To allow for ?1, :2 and/or $3 syntax for numbered placholders",
"type": "array",
"items": {
"enum": ["?", ":", "$"]
}
},
"named": {
"description": "To allow for :name, @name and/or $name syntax for named placholders.",
"type": "array",
"items": {
"enum": [":", "@", "$"]
}
},
"quoted": {
"description": "To allow for :\"name\", @\"name\" and/or $\"name\" syntax for quoted placholders.",
"type": "array",
"items": {
"enum": [":", "@", "$"]
}
},
"custom": {
"description": "An option to implement custom syntax for parameter placeholders",
"type": "array",
"items": {
"type": "object",
"properties": {
"regex": {
"type": "string"
}
},
"required": ["regex"]
}
}
},
"examples": [{ "positional": true, "numbered": [], "named": [":", "@"] }]
},
"tabWidth": {
"description": "Specifies amount of spaces to be used for indentation.",
"type": "integer",
"exclusiveMinimum": 0
},
"useTabs": {
"description": "Uses TAB characters for indentation. `tabWidth` will be ignored",
"type": "boolean",
"default": false
}
},
"required": ["language"],
"$defs": { "casing": { "enum": ["preserve", "upper", "lower"] } }
}