Implement placeholder replacement#240
Merged
nathan-boyd merged 1 commit intotsqllint:masterfrom May 28, 2020
c-w:support-placeholders
Merged
Implement placeholder replacement#240nathan-boyd merged 1 commit intotsqllint:masterfrom c-w:support-placeholders
nathan-boyd merged 1 commit intotsqllint:masterfrom
c-w:support-placeholders
Conversation
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
approved these changes
May 28, 2020
Contributor
Author
|
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! |
Member
|
Yes, I'm planning a release this weekend 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Many tools in the SQL ecosystem (e.g. Invoke-Sqlcmd) support placeholders to inject variables into SQL scripts as shown in the example below:
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: