VSCode Extension bq dryrun sql linter is a Visual Studio Code extension that checks SQL code against a BigQuery server using the dry run command. It shows errors returned from the server directly in the editor, helping developers catch issues in their SQL code early.
- Lint SQL files by performing a dry run against a BigQuery server.
- Display errors and warnings inline in the editor.
- Supports
.sql
and.sql.jinja
files. - Activates on startup to ensure seamless integration.
You can install the extension directly from the Visual Studio Marketplace:
- Install from Marketplace:
- Open Visual Studio Code.
- Go to the Extensions view (
Ctrl
+Shift
+X
orCmd
+Shift
+X
). - In the search box, type
BQ Dry Run SQL Linter
. - Find the extension published by
timle
. - Click Install to add the extension to your VS Code.
Alternatively, you can install it directly from the marketplace link:
- Visit the extension page on Visual Studio Marketplace.
- Click Install and follow the prompts to install the extension.
- Open a
.sql
or.sql.jinja
file in Visual Studio Code. - The extension will automatically perform a dry run against the BigQuery server and display any errors or warnings in the Problems panel and inline in the editor.
- Command Palette ->
>BQ Dry Run SQL Linter: Run Linting
- See below
sqlLinter.liveLinting
to enable, along with settings to customize the frequency of BQ server connections to run the dry run process.
- Access to a Google Cloud BigQuery project.
- Properly configured Google Cloud credentials.
If you are running dbt locally, you've already done this. For others, see:
Starting from version 0.0.2, the extension activates on startup (onStartupFinished
). This ensures that the extension is active even when opening a .sql.jinja
file first, resolving previous issues where the extension did not activate unless a .sql
file was opened first.
By default, the extension lints SQL files when they are saved.
Users can enable live linting through the extension settings (sqlLinter.liveLinting
).
When live linting is enabled, debouncing and rate limiting control the number of requests to the BigQuery server, minimizing the number of requests per minute.
- Debounce Interval (
sqlLinter.debounceInterval
): Adjust the debounce interval in milliseconds. - Rate Limit (
sqlLinter.rateLimit
): Set the maximum number of requests per minute. - Language Folders (
sqlLinter.languageFolders
): Specify custom file suffixes and folder paths where linting should be enabled.
By default all files with language type '.sql' will be linted.
Additionally, the sqlLinter.languageFolders
setting allows you to define an array of fileSuffix
and folderPath
pairs to specify where linting should be enabled. This is particularly useful if your project uses custom file extensions or organizes SQL files in specific directories.
Default Value: dbt opinionated:
[
{
"fileSuffix": ".sql",
"folderPath": "target/compiled/"
}
]
Usage Example:
"sqlLinter.languageFolders": [
{
"fileSuffix": ".sql",
"folderPath": "src/queries/"
},
{
"fileSuffix": ".sql.jinja",
"folderPath": "templates/sql/"
}
]
In this example:
- Files ending with
.sql
in thesrc/queries/
directory will be linted. - Files ending with
.sql.jinja
in thetemplates/sql/
directory will also be linted.
This setting provides flexibility to lint SQL files located in various directories and with different file extensions, accommodating diverse project structures.
Configuration Steps:
- Open your VS Code settings (
Ctrl
+Comma
orCmd
+Comma
). - Search for
sqlLinter.languageFolders
. - Edit the setting by adding your desired
fileSuffix
andfolderPath
pairs.
To test and use the extension:
Open the project folder in VS Code:
- You can run
code .
in the terminal from the project directory to open VS Code in the current folder. - Ensure all dependencies are installed (already done with
npm install
).
Launch the extension in a new Extension Development Host window:
- Press
F5
in VS Code. This will compile the extension and open a new window where the extension is running. - In the new window, create or open a
.sql
or.sql.jinja
file and write some SQL code.
As you write, the extension will send your SQL code to BigQuery for a dry run. Any errors returned from BigQuery will be highlighted directly in the editor.
- Run
vsce package
to create a.vsix
package of the extension.
Refer to the Publishing Extension Guide:
- Run
vsce login <publisher id>
to log in. - Run
vsce publish
to publish the extension.
- Currently supports only BigQuery SQL syntax.
- May not handle all types of SQL syntax variations.
- Added activation on startup to support
.sql.jinja
files when opened first.
- Initial release of SQL Linter extension.