Skip to content

Implement placeholder replacement#240

Merged
nathan-boyd merged 1 commit intotsqllint:masterfrom
c-w:support-placeholders
May 28, 2020
Merged

Implement placeholder replacement#240
nathan-boyd merged 1 commit intotsqllint:masterfrom
c-w:support-placeholders

Conversation

@c-w
Copy link
Contributor

@c-w c-w commented May 27, 2020

Many tools in the SQL ecosystem (e.g. Invoke-Sqlcmd) support placeholders to inject variables into SQL scripts as shown in the example below:

SELECT * FROM foo WHERE bar = $(MyPlaceholder);

Currently TSQLLint throws a syntax error for files containing placeholders. This change adds support to TSQLLint for placeholder syntax by dereferencing any placeholders with values from environment variables before applying linting rules which enables use-cases like this:

Set-Content -Path query.sql -Value 'SELECT * FROM foo WHERE bar = $(MyPlaceholder);'

$env:MyPlaceholder = '123'

# this will run linting on the query SELECT * FROM foo WHERE bar = 123;
tsqllint query.sql

Many tools in the SQL ecosystem (e.g. Invoke-Sqlcmd [1]) support
placeholders to inject variables into SQL scripts as shown in the
example below:

```sql
SELECT * FROM foo WHERE bar = $(MyPlaceholder);
```

Currently TSQLLint throws a syntax error for files containing
placeholders. This change adds support to TSQLLint for placeholder
syntax by dereferencing any placeholders with values from environment
variables before applying linting rules which enables use-cases like
this:

```pwsh
Set-Content `
  -Path query.sql `
  -Value 'SELECT * FROM foo WHERE bar = $(MyPlaceholder);'

$env:MyPlaceholder = '123'

<# this will run linting on the query
SELECT * FROM FOO WHERE BAR = 123; #>

tsqllint query.sql
```

[1] https://docs.microsoft.com/en-us/powershell/module/sqlserver/invoke-sqlcmd
@nathan-boyd nathan-boyd merged commit 745de5a into tsqllint:master May 28, 2020
@c-w c-w deleted the support-placeholders branch May 28, 2020 13:41
@c-w
Copy link
Contributor Author

c-w commented May 31, 2020

Thanks for the review and merge @nathan-boyd. Would it also be possible to get this pushed up to NPM via a new release? Would love to start using this feature soon!

@nathan-boyd
Copy link
Member

Yes, I'm planning a release this weekend 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants