inline-sql-toolkit 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # Inline SQL Toolkit
2
+
3
+ Inline SQL Toolkit highlights SQL embedded in Python strings and formats selected
4
+ SQL with the bundled `sql-formatter` layout engine. It supports ordinary `.py`
5
+ files, marimo
6
+ (`.mo.py`) programs, and Python cells in Jupyter notebooks. In marimo notebooks
7
+ the `python` and `mo-python` cell languages are supported. SQL-language cells
8
+ and notebook magic commands (`%sql`, `%%sql`, and similar magic syntax) are not
9
+ supported.
10
+
11
+ Requirements are VS Code 1.95 or newer. Formatting is
12
+ manual-only: this extension does not register a formatter provider, format on
13
+ save, format on type, or format ranges automatically. The accompanying CLI is
14
+ likewise an explicit invocation, not an automated background formatter. It never
15
+ executes SQL, validates SQL, infers a SQL dialect, connects to a database, or
16
+ sends source to the network. The formatter is best-effort; an unsafe candidate is
17
+ skipped while other safe candidates may still be edited.
18
+
19
+ In short, SQL is never executed by this extension. SQL is never validated by
20
+ this extension.
21
+
22
+ ## Architecture
23
+
24
+ [![Inline SQL Toolkit architecture](inline-sql-toolkit-architecture.png)](https://hidenobunagai.github.io/inline-sql-toolkit/)
25
+
26
+ [Open the interactive architecture diagram (HTML)](https://hidenobunagai.github.io/inline-sql-toolkit/)
27
+
28
+ ## Quick start
29
+
30
+ Open a supported Python document or notebook cell, place the cursor in one of
31
+ the examples below, and choose a command from the Command Palette.
32
+
33
+ ### Plain string
34
+
35
+ ```python
36
+ query = "SELECT id, name FROM users WHERE active = true"
37
+ ```
38
+
39
+ ### Marker triple-quoted string
40
+
41
+ ```python
42
+ query = """--sql
43
+ select id, name
44
+ from users
45
+ where active = true
46
+ """
47
+ ```
48
+
49
+ Formatting keeps the `--sql` marker directly after the opening quote, indents
50
+ the SQL one level below the literal's base indent, and aligns the closing
51
+ triple quote with the base indent:
52
+
53
+ ```python
54
+ query = """--sql
55
+ select id, name
56
+ from users
57
+ where active = true
58
+ """
59
+ ```
60
+
61
+ A marker on its own line is normalized to the opening quote, so both styles
62
+ produce the same output. With the default `keywordCase: upper`, keywords are
63
+ uppercased.
64
+
65
+ ### Complex f-string
66
+
67
+ ```python
68
+ account_id = get_account_id()
69
+ query = f"""--sql
70
+ SELECT id, name
71
+ FROM users
72
+ WHERE account_id = {account_id}
73
+ AND status = {{'active'}}
74
+ """
75
+ ```
76
+
77
+ The f-string example demonstrates that Python replacement fields and escaped
78
+ braces remain Python source. Only the SQL portions are considered for layout;
79
+ the extension preserves the original f-string expressions and escapes.
80
+
81
+ ## Commands
82
+
83
+ The command IDs are shown for keybindings and automation integrations:
84
+
85
+ - **Inline SQL: Format at Cursor** (`inlineSql.formatAtCursor`) formats the SQL
86
+ candidate containing the cursor.
87
+ - **Inline SQL: Format Selection** (`inlineSql.formatSelection`) formats SQL
88
+ candidates intersecting the current selection.
89
+ - **Inline SQL: Format All** (`inlineSql.formatAll`) formats every detected
90
+ candidate in the current document or notebook cell.
91
+
92
+ Each invocation checks the document version and the expected source text before
93
+ creating one `WorkspaceEdit`, so the operation is one undo step. VS Code does
94
+ not provide an atomic, versioned precondition for an edit that happens after
95
+ that check. Changes observed before the edit are rejected as stale; a change
96
+ that races after the check can still be applied because VS Code provides no
97
+ later atomic precondition.
98
+
99
+ ## Settings
100
+
101
+ - `inlineSql.format.keywordCase`: `upper` (default), `lower`, or `preserve`.
102
+ - `inlineSql.format.indentWidth`: SQL indentation width from 1 to 8 spaces
103
+ (default 2).
104
+ - `inlineSql.format.wrapAfter`: preferred line width from 20 to 500 (default
105
+ 88).
106
+ - `inlineSql.format.useSpaceAroundOperators`: add spaces around operators
107
+ (default `true`).
108
+ - `inlineSql.format.replaceOrdinals`: replace `GROUP BY` / `ORDER BY` ordinal
109
+ numbers (`1`, `2`, ...) with the referenced column names, preferring
110
+ aliases (default `true`).
111
+ - `inlineSql.format.dialect`: SQL dialect used by the formatter (`sql`,
112
+ `mysql`, `postgresql`, or `sqlite`; default `postgresql`).
113
+
114
+ The extension highlights inline SQL with an injected TextMate grammar: SQL
115
+ strings that start with `-- sql` (or a leading SQL keyword) are embedded as
116
+ `meta.embedded.sql` and colored with the theme's SQL rules. The grammar follows
117
+ the same approach as the popular `inline-sql-syntax` extension and works in
118
+ plain files and notebook cells alike. Because the highlighting is grammar-based,
119
+ a language server's semantic tokens can override it; if SQL highlighting
120
+ disappears, disable semantic highlighting for the language server
121
+ (`editor.semanticHighlighting.enabled: false`) or for the server itself.
122
+
123
+ ## Command line (CLI)
124
+
125
+ The `inline-sql-toolkit` command-line tool formats Python files or standard input using the exact same formatting engine and safety checks as the VS Code extension's **Format All** command. Unsafe candidates (such as invalid Python syntax, unsupported literals, or unparseable f-strings) are skipped rather than producing corrupt output.
126
+
127
+ Run directly via `npx` or install with `bun add -d inline-sql-toolkit` (or `npm install -D inline-sql-toolkit`):
128
+
129
+ ```bash
130
+ npx inline-sql-toolkit [options] [files...]
131
+ ```
132
+
133
+ When run without file arguments, the CLI reads Python source from standard input and prints the formatted result to standard output. Notebook files (`.ipynb`) are not supported by the CLI; use the VS Code extension for Jupyter and marimo notebook cell formatting. The CLI supports standard Python source files (`.py`, `.mo.py`) and stdin.
134
+
135
+ ### CLI Options
136
+
137
+ | Option | Description | Default |
138
+ | ----------------------------- | ----------------------------------------------------------------- | -------------------------- |
139
+ | `-w, --write` | Rewrite files in place (no write if unchanged) | off |
140
+ | `--check` | Exit with code 1 if any file would change | off |
141
+ | `--dialect <name>` | SQL dialect: `sql`, `mysql`, `postgresql`, or `sqlite` | `postgresql` |
142
+ | `--keyword-case <case>` | Case for SQL keywords: `upper`, `lower`, or `preserve` | `upper` |
143
+ | `--indent-width <1-8>` | SQL indentation width in spaces | `2` |
144
+ | `--wrap-after <20-500>` | Preferred expression line width | `88` |
145
+ | `--no-space-around-operators` | Keep dense operators | spaced |
146
+ | `--no-ordinals` | Do not replace `GROUP BY` / `ORDER BY` ordinals with column names | replace |
147
+ | `-c, --config <file>` | Configuration JSON file | Nearest `.inline-sql.json` |
148
+ | `-h, --help` | Show usage help | |
149
+ | `--version` | Show version number | |
150
+
151
+ Exit codes: `0` on success, `1` when `--check` finds unformatted files, and `2` on usage, configuration, I/O, or formatting errors.
152
+
153
+ ### Configuration file (`.inline-sql.json`)
154
+
155
+ The CLI automatically searches for a `.inline-sql.json` file in the current working directory and its parent directories. The configuration structure matches VS Code settings:
156
+
157
+ ```json
158
+ {
159
+ "format": {
160
+ "keywordCase": "upper",
161
+ "indentWidth": 2,
162
+ "wrapAfter": 88,
163
+ "useSpaceAroundOperators": true,
164
+ "replaceOrdinals": true,
165
+ "dialect": "postgresql"
166
+ }
167
+ }
168
+ ```
169
+
170
+ Precedence order is **CLI flags > configuration file > default values**.
171
+
172
+ ## Detection and supported syntax
173
+
174
+ Formatter detection is source-level: it examines Python tokens and the literal
175
+ characters in the source, rather than evaluating the string value. A candidate
176
+ is found when either condition holds:
177
+
178
+ 1. The first logical, non-blank line starts with `-- sql` or `--sql` after
179
+ horizontal whitespace. Matching is case-insensitive and the marker text is
180
+ preserved. On format, a marker on its own line moves to sit directly after
181
+ the opening quote (`"""--sql`), so both input styles produce one output.
182
+ 2. After removing only physically present ASCII space, tab, CR, and LF
183
+ characters, the source starts with one of `SELECT`, `WITH`, `INSERT`,
184
+ `UPDATE`, `DELETE`, `MERGE`, `CREATE`, `ALTER`, `DROP`, `TRUNCATE`, or
185
+ `EXPLAIN`, followed by a word boundary. The two source characters `\n` are
186
+ not treated as whitespace.
187
+
188
+ Standalone plain and raw strings, f-strings, and raw f-strings (`f`, `rf`, and
189
+ `fr`, in either case) are supported with single, double, and triple delimiters
190
+ (`'`, `"`, `'''`, and `"""`). A parseable candidate in a supported literal is
191
+ also the candidate used by the syntax highlighting grammar.
192
+
193
+ The following are intentionally skipped: bytes and byte strings (`b`/`rb`),
194
+ implicit or explicit string concatenation, t-strings, invalid Python, dynamic
195
+ or non-literal SQL, and SQL-language cells. A candidate that cannot be restored
196
+ without changing Python source is reported as unsafe and is not edited.
197
+
198
+ ## Trust, privacy, and offline behavior
199
+
200
+ In an untrusted workspace the extension provides highlighting only. The three
201
+ formatting commands remain visible, but formatting is disabled: no analysis
202
+ runs, no Code Actions are offered, and no edits are applied until the
203
+ workspace is trusted. SQL is not written to disk, logged, telemetered, sent
204
+ over the network, passed to a shell/database, or executed. The bundled
205
+ `sql-formatter` code runs offline and is a layout engine, not a SQL validator.
206
+
207
+ ## Troubleshooting
208
+
209
+ - **No candidate found:** confirm the source uses a supported literal and that
210
+ the first logical line has `-- sql`/`--sql`, or that a listed keyword is at
211
+ the source-level start with a word boundary.
212
+ - **Unsupported literal or unsafe f-string:** remove concatenation, bytes or
213
+ t-string syntax, and verify that Python parses the document. Complex f-string
214
+ expressions are skipped when their source spans cannot be restored exactly.
215
+ - **Formatting is unavailable:** use a trusted workspace and check the
216
+ diagnostic reason shown by the extension (`WORKSPACE_UNTRUSTED`,
217
+ `INVALID_CONFIGURATION`, or `PROCESS_FAILED`).
218
+ - **SQL looks different than expected:** formatting does not validate SQL or
219
+ infer a dialect. Adjust the settings above and review the source-level
220
+ candidate before applying the one-step edit.
221
+
222
+ For security reporting, see [SECURITY.md](SECURITY.md). For source-free bug
223
+ reports and diagnostic reason codes, see [SUPPORT.md](SUPPORT.md). Licensing and
224
+ component provenance are in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
package/SECURITY.md ADDED
@@ -0,0 +1,29 @@
1
+ # Security policy
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes are assessed against the latest published release. Use the
6
+ newest version before reporting a vulnerability; older versions may no longer
7
+ receive fixes. The current version is listed in the changelog.
8
+
9
+ ## Private reporting
10
+
11
+ Please do not disclose security vulnerabilities in public issues, discussions,
12
+ or pull requests. Report privately through the repository's configured GitHub
13
+ security advisory UI: **Security → Advisories → Report a vulnerability**. This
14
+ policy intentionally does not publish an email address or invent another
15
+ contact channel.
16
+
17
+ Include the affected version, the smallest reproducible description, impact,
18
+ and any relevant configuration. Do not include credentials, tokens, customer
19
+ data, private source, or other secrets. If source is necessary to reproduce the
20
+ issue, redact it and describe only the smallest safe shape.
21
+
22
+ ## Security boundaries
23
+
24
+ Inline SQL Toolkit is designed to work offline. It does not execute SQL,
25
+ connect to a database, make network requests, run a shell command, collect
26
+ telemetry, or format automatically. In an untrusted workspace it provides
27
+ highlighting only. In a trusted workspace the extension formats the detected
28
+ SQL in-process with the bundled `sql-formatter` layout engine; document text is
29
+ not written to disk or emitted in logs.
package/SUPPORT.md ADDED
@@ -0,0 +1,43 @@
1
+ # Support
2
+
3
+ Use a repository issue for usage questions and reproducible, non-sensitive
4
+ bugs. This project has no guaranteed response time. Do not include SQL source,
5
+ credentials, tokens, customer data, private paths, or other secrets. Reports
6
+ should be source-free: describe the literal shape (for example, plain,
7
+ triple-quoted, or f-string), operation, document/cell kind, and redacted
8
+ settings instead of pasting a query.
9
+
10
+ Include these diagnostic details when available:
11
+
12
+ - Inline SQL Toolkit version (for example, `0.1.0`), VS Code version, and
13
+ operating system.
14
+ - Whether the workspace is trusted, and whether the target is a `.py`, Jupyter
15
+ Python cell, or marimo `python`/`mo-python` cell.
16
+ - The command (`inlineSql.formatAtCursor`, `inlineSql.formatSelection`, or
17
+ `inlineSql.formatAll`), whether the cursor/selection was involved, and the
18
+ relevant non-sensitive setting names and values.
19
+ - The diagnostic reason code shown by the extension. Never include document
20
+ contents merely to provide a reason code.
21
+
22
+ ## Diagnostic reason codes
23
+
24
+ | Code | Meaning |
25
+ | ------------------------- | ------------------------------------------------------- |
26
+ | `WORKSPACE_UNTRUSTED` | Formatting is disabled until trust is granted. |
27
+ | `INVALID_CONFIGURATION` | An `inlineSql.format.*` setting has an invalid value. |
28
+ | `NO_SQL_CANDIDATE` | No supported source-level SQL candidate was found. |
29
+ | `UNSUPPORTED_LITERAL` | The literal shape is outside the supported scope. |
30
+ | `UNSAFE_FSTRING_RESTORE` | An f-string could not be restored byte-for-byte safely. |
31
+ | `UNSAFE_RAW_STRING` | A raw-string edit could not preserve its source safely. |
32
+ | `FORMATTER_FAILED` | The bundled formatter could not produce a safe result. |
33
+ | `RESOURCE_LIMIT_EXCEEDED` | A document, candidate, or request exceeded a guard. |
34
+ | `PROCESS_CANCELLED` | The formatting request was cancelled. |
35
+ | `PROCESS_FAILED` | Formatting failed unexpectedly. |
36
+ | `DOCUMENT_CHANGED` | The document changed before the guarded edit. |
37
+ | `APPLY_EDIT_FAILED` | VS Code rejected the guarded workspace edit. |
38
+ | `PROTOCOL_ERROR` | The result failed an internal consistency check. |
39
+
40
+ Inline SQL Toolkit does not provide database connectivity, SQL validation,
41
+ network services, or telemetry. A support report should therefore focus on the
42
+ source shape, operation, versions, trust state, and reason code rather than a
43
+ database or remote service.
@@ -0,0 +1,56 @@
1
+ # Third-party notices
2
+
3
+ Inline SQL Toolkit includes the third-party components below. Their authors and
4
+ copyright holders retain their rights; this project does not claim ownership of
5
+ their source or license text. Copies of the required notices are packaged in
6
+ the VSIX under `third_party/`.
7
+
8
+ ## `inline-sql-syntax` grammar (highlight-sql-string.json)
9
+
10
+ The injected TextMate grammar in `syntaxes/inline-sql.tmLanguage.json` is
11
+ derived from the `highlight-sql-string.json` grammar of the
12
+ `inline-sql-syntax` extension (MIT license). Exact provenance:
13
+
14
+ - Marketplace: <https://marketplace.visualstudio.com/items?itemName=qufiwefefwoyn.inline-sql-syntax>
15
+ - Source repository: <https://github.com/barklan/inline_sql_syntax>
16
+ - License: MIT, Copyright (c) 2021 Gleb Buzin
17
+
18
+ The complete MIT license and the upstream grammar file are in
19
+ [`third_party/inline-sql-syntax/`](third_party/inline-sql-syntax/) and are
20
+ copied into the packaged VSIX.
21
+
22
+ ## `sql-formatter` npm package (v15.8.2)
23
+
24
+ The formatter engine is the `sql-formatter` package (MIT license). esbuild
25
+ inlines it into `dist/extension.js` and `dist/cli.js`, so no `node_modules` tree
26
+ is packaged and the license text has to travel with the bundle. Exact provenance:
27
+
28
+ - Package: <https://www.npmjs.com/package/sql-formatter/v/15.8.2>
29
+ - Source repository: <https://github.com/sql-formatter-org/sql-formatter>
30
+ - License: MIT, Copyright (c) 2016-2020 ZeroTurnaround LLC, Copyright (c)
31
+ 2020-2021 George Leslie-Waksman and other contributors, Copyright (c)
32
+ 2021-Present inferrinizzard and other contributors
33
+
34
+ The complete MIT license is in
35
+ [`third_party/sql-formatter/`](third_party/sql-formatter/) and is copied into
36
+ the packaged VSIX.
37
+
38
+ ## `nearley` npm package (v2.20.1)
39
+
40
+ `sql-formatter` builds its SQL parser on the `nearley` package (MIT license).
41
+ esbuild inlines `nearley` into `dist/extension.js` and `dist/cli.js` as well.
42
+ Exact provenance:
43
+
44
+ - Package: <https://www.npmjs.com/package/nearley/v/2.20.1>
45
+ - Source repository: <https://github.com/hardmath123/nearley>
46
+ - License: MIT, Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019 Kartik
47
+ Chandra, Tim Radvan
48
+
49
+ The complete MIT license is in [`third_party/nearley/`](third_party/nearley/)
50
+ and is copied into the packaged VSIX.
51
+
52
+ ## Project license
53
+
54
+ The Inline SQL Toolkit source and original documentation are provided under the
55
+ MIT license in [`LICENSE`](LICENSE). This project license does not replace or
56
+ alter the third-party licenses above.