-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
[TypeSpecValidation] Add suppression mechanism specific to TSV-All #30324
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aabab64
Extract helper function "Get-Suppressions"
mikeharder c36632a
Add helper "Get-FirstSuppression"
mikeharder 135f49b
Rename to Get-FirstSuppression for consistency
mikeharder f7761fd
Rename to Get-Suppression
mikeharder ab1fe90
Add suppressions to TypeSpecValidationAll
mikeharder db00e49
Add switch "DryRun"
mikeharder 4f81f27
Prevent array collapse
mikeharder e2438c9
Add trailing newline
mikeharder 7740eb6
Revert accident
mikeharder 8390b97
Remove unnecessary leading spaces
mikeharder 735f909
Rename private function to avoid naming collision
mikeharder 7ffc43a
Merge branch 'main' into tsv-all-suppress
mikeharder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<# | ||
.DESCRIPTION | ||
Returns the suppressions for a tool applicable to a path. Walks up the directory tree to find all files named | ||
"suppressions.yaml", parses and validates the contents, and returns the suppressions matching the tool and path. | ||
Suppressions are ordered by file (closest to path is first), then within the file (closest to top is first). | ||
|
||
.PARAMETER Tool | ||
Name of tool. Matched against property "tool" in suppressions.yaml. | ||
|
||
.PARAMETER Path | ||
Path to file or directory under analysis. | ||
|
||
.OUTPUTS | ||
Hashtable[] | ||
Array of suppressions matching tool and path (may be empty). See the "get-suppressions" tool for the definition | ||
of the suppression object. | ||
#> | ||
function Get-Suppressions { | ||
param ( | ||
[string]$Tool, | ||
[string]$Path | ||
) | ||
|
||
# -NoEnumerate to prevent single-element arrays from being collapsed to a single object | ||
# -AsHashtable is closer to raw JSON than PSCustomObject | ||
$suppressions = npm exec --no -- get-suppressions $Tool $Path | ConvertFrom-Json -NoEnumerate -AsHashtable | ||
|
||
if ($LASTEXITCODE -ne 0) { | ||
throw "Failure running 'npm exec get-suppressions'" | ||
} | ||
|
||
return $suppressions; | ||
} | ||
|
||
<# | ||
.DESCRIPTION | ||
Returns the first suppression for a tool applicable to a path. Walks up the directory tree to find all files named | ||
"suppressions.yaml", parses and validates the contents, and returns the first suppression matching the tool and path. | ||
Suppressions are ordered by file (closest to path is first), then within the file (closest to top is first). | ||
|
||
.PARAMETER Tool | ||
Name of tool. Matched against property "tool" in suppressions.yaml. | ||
|
||
.PARAMETER Path | ||
Path to file or directory under analysis. | ||
|
||
.OUTPUTS | ||
Hashtable | ||
First suppressions matching tool and path (may be null). See the "get-suppressions" tool for the definition | ||
of the suppression object. | ||
#> | ||
function Get-Suppression { | ||
param ( | ||
[string]$Tool, | ||
[string]$Path | ||
) | ||
|
||
$suppressions = @(Get-Suppressions $Tool $Path) | ||
return $suppressions ? $suppressions[0] : $null; | ||
} |
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it is worth putting this default into the core suppression tool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean because it's a little bit of duplicate code. However, I think it's a tricky question, how much the core
get-suppressions
tool (both the CLI and the JS function) should respect what's actually insuppressions.yaml
, versus adding defaults like areason
text if none is specified.For now, I think leave it to clients, what to do if the
reason
is unspecified. If we wanted to make any change in this area, we could consider requiringreason
in thesuppressions.yaml
, so spec authors always need to set some reason string. It's currently optional (but strongly recommended).