Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement placeholder replacement #240

Merged
merged 1 commit into from May 28, 2020
Merged

Implement placeholder replacement #240

merged 1 commit into from May 28, 2020

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
1 check passed
@c-w c-w deleted the support-placeholders branch May 28, 2020
@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

nathan-boyd commented Aug 3, 2020

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.

None yet

2 participants