Skip to content

Commit e1bcbf2

Browse files
committed
- added encoding to md file generation
- added ignoring rules md doc - fixed some typos in readme, and added link to new ignore doc
1 parent 4db07ab commit e1bcbf2

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

.github/workflows/generate_docs.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ function New-TableOfContents {
186186
$categories = $RuleObjects | Group-Object { $_.Category } | Sort-Object -Property Key
187187

188188
$StringBuilder = [System.Text.StringBuilder]::new()
189-
[void]$StringBuilder.AppendLine("$spaces")
190189
[void]$StringBuilder.AppendLine("[This document is automatically generated. All changed made to it WILL be lost]: <>$spaces")
191190

192191
[void]$StringBuilder.AppendLine("$spaces")
@@ -209,7 +208,7 @@ function New-TableOfContents {
209208
$FilePath = "$ParentDirectory\docs\"
210209
New-Item -Path $FilePath -Force -ItemType Directory | Out-Null
211210

212-
$StringBuilder.ToString() | Out-File "$FilePath\table_of_contents.md" -Force
211+
$StringBuilder.ToString() | Out-File "$FilePath\table_of_contents.md" -Force -Encoding ascii
213212
}
214213

215214
function New-MdFromRuleObject {
@@ -223,7 +222,6 @@ function New-MdFromRuleObject {
223222

224223
# MD EOL - When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.
225224
$spaces = " " * 2
226-
[void]$StringBuilder.AppendLine("$spaces")
227225
[void]$StringBuilder.AppendLine("[This document is automatically generated. All changed made to it WILL be lost]: <>$spaces")
228226

229227
[void]$StringBuilder.AppendLine("$spaces")
@@ -273,7 +271,7 @@ function New-MdFromRuleObject {
273271
$FilePath = "$ParentDirectory\docs\$($RuleObject.Category)\"
274272
New-Item -Path $FilePath -Force -ItemType Directory | Out-Null
275273

276-
$StringBuilder.ToString() | Out-File "$FilePath\$($RuleObject.RuleId).md" -Force
274+
$StringBuilder.ToString() | Out-File "$FilePath\$($RuleObject.RuleId).md" -Force -Encoding ascii
277275
}
278276

279277
function Publish-Markdown {

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
## Overview
44

5-
Just what it says on the box: A library of SQL best practices as extended [database code analysis rules](https://docs.microsoft.com/en-us/sql/ssdt/overview-of-extensibility-for-database-code-analysis-rules?view=sql-server-ver15) checked at build.
5+
Just what it says on the box: A library of SQL best practices as extended [database code analysis rules](https://docs.microsoft.com/en-us/sql/ssdt/overview-of-extensibility-for-database-code-analysis-rules?view=sql-server-ver15) checked at build. The rules can be installed locally as well as on the build server.
66

7-
For a complete list of the current rules we have implemented see [here](docs/table_of_contents.md)
8-
9-
For example code see [here](https://github.com/microsoft/DACExtensions/tree/master/RuleSamples)
7+
For a complete list of the current rules we have implemented see [here](docs/table_of_contents.md). For example code see [here](https://github.com/microsoft/DACExtensions/tree/master/RuleSamples)
108

119
## Organization
1210

@@ -39,10 +37,12 @@ The build should be installed to the template path
3937
So for Visual Studio 2017 with DAC version 150 the path might be
4038
> `C:\Program Files (x86)\Microsoft Visual Studio\`***`2017`***`\Enterprise\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\`***`150`***`\Extensions\SqlServer.Rules`
4139
40+
An Install.bat is provided that will copy out the rules to all of the appropriate folder destinations.
41+
4242
**NOTES:**
4343

4444
- You will need to copy the binaries to every permutation of Visual Studio version and dac version that you wish to use the rules for.
45-
- When you have code analysis enabled and have compiled the project Visual Studio places a hard lock on the rule binaries. To updates them or remove them you will need to close Visual Studio.
45+
- When you have code analysis enabled and have compiled the project Visual Studio places a hard lock on the rule binaries. To update them or remove them you will need to close Visual Studio.
4646

4747
## Project Configuration
4848

@@ -52,3 +52,4 @@ So for Visual Studio 2017 with DAC version 150 the path might be
5252
- You can also optionally:
5353
- Enable / disable rules.
5454
- Set certain rules as errors so they will actually throw build errors.
55+
- Ignore rules in the sql files. [See](docs/ignoring_rules.md)

SqlServer.Rules.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
5353
EndProject
5454
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{596B2FD7-2684-4DC5-BD46-31EE223C49E4}"
5555
ProjectSection(SolutionItems) = preProject
56+
docs\ignoring_rules.md = docs\ignoring_rules.md
5657
docs\table_of_contents.md = docs\table_of_contents.md
5758
EndProjectSection
5859
EndProject

docs/ignoring_rules.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Ignoring Rules
2+
3+
Certain rules can be ignored within the T-SQL of the object itself. This is useful for whenever you want a rule to continue to run, but you have valid reasons for ignoring it in certain instances. Not all rules are ignorable. Refer to the documentation to determine which ones are.
4+
5+
In those cases you can use:
6+
7+
- IGNORE {RuleId}: Ignores a single occurrence of a rule within the file. Must be placed on, or above the line that violated the rule.
8+
- GLOBAL IGNORE {RuleId}: Ignores all occurrences of that rule within the file.
9+
10+
Ignores must be done in comment syntax using either of these formats:
11+
12+
- -- IGNORE {RuleId}
13+
- /* IGNORE {RuleId} */ - This is the preferred syntax as it will not cause sql to be malformed if the line breaks are removed.
14+
15+
## Examples
16+
17+
For example, for us to ignore the rule [SRD0032](Design/SRD0032.md) (Avoid use of OR in where clause) we can this several ways. This is a very common rule to have to ignore.
18+
19+
To ignore just one of the rules:
20+
21+
```sql
22+
CREATE PROCEDURE dbo.Example AS
23+
BEGIN
24+
SELECT *
25+
FROM dbo.table1
26+
WHERE id1 = 1 OR id2 = 2 /* IGNORE SRD0032 */
27+
28+
29+
SELECT *
30+
FROM dbo.table2
31+
WHERE id1 = 1 OR id2 = 2 -- this will still flag as a violation of SRD0032
32+
END
33+
```
34+
35+
Now you could just add ignores for each occasion of this rule violation, but instead you could use a global ignore to ignore all violations of that rule within the stored procedure.
36+
37+
```sql
38+
CREATE PROCEDURE dbo.Example AS
39+
BEGIN
40+
/* GLOBAL IGNORE SRD0032 */
41+
SELECT *
42+
FROM dbo.table1
43+
WHERE id1 = 1 OR id2 = 2
44+
45+
46+
SELECT *
47+
FROM dbo.table2
48+
WHERE id1 = 1 OR id2 = 2
49+
END
50+
```
51+
52+
## Notes
53+
54+
If you find that you do not want a rule to ever run, you can simply uncheck it from your list of rules in your project properties instead of adding global ignores everywhere.

docs/table_of_contents.md

100 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)