From 07ae785257eff641912efddbf70a5b942e796534 Mon Sep 17 00:00:00 2001 From: Shub Date: Thu, 16 Oct 2025 20:18:48 +0530 Subject: [PATCH 1/2] feat: #889 support json schema --- json-schema/schema.json | 134 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 json-schema/schema.json diff --git a/json-schema/schema.json b/json-schema/schema.json new file mode 100644 index 000000000..6e8321842 --- /dev/null +++ b/json-schema/schema.json @@ -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": "To allow for :name, @name and/or $name syntax for named placholders.", + "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"] } } +} From 068787e8b98d6bb8238914155ef75a4184abff4c Mon Sep 17 00:00:00 2001 From: Shub Date: Thu, 16 Oct 2025 22:37:22 +0530 Subject: [PATCH 2/2] fix: custom description, add readme desc --- README.md | 8 ++++++++ json-schema/schema.json => schema.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) rename json-schema/schema.json => schema.json (97%) diff --git a/README.md b/README.md index 70146990e..6c7023b8c 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/json-schema/schema.json b/schema.json similarity index 97% rename from json-schema/schema.json rename to schema.json index 6e8321842..07b8bd39f 100644 --- a/json-schema/schema.json +++ b/schema.json @@ -103,7 +103,7 @@ } }, "custom": { - "description": "To allow for :name, @name and/or $name syntax for named placholders.", + "description": "An option to implement custom syntax for parameter placeholders", "type": "array", "items": { "type": "object",