-
Notifications
You must be signed in to change notification settings - Fork 56
(GH-538) Add VS Code keywords, vocabulary, and dialect to dsc-lib-jsonschema
#1276
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
Open
michaeltlombardi
wants to merge
3
commits into
PowerShell:main
Choose a base branch
from
michaeltlombardi:gh-538/main/vscode_keywords
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,76 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| using module ../../build.helpers.psm1 | ||
|
|
||
| BeforeDiscovery { | ||
| $tomls = Get-ChildItem $PSScriptRoot/../../en-us.toml -Recurse -File | ||
| # Limit the folders to recursively search for rust i18n translation strings | ||
| $rootFolders = @( | ||
| 'adapters' | ||
| 'dsc' | ||
| 'extensions' | ||
| 'grammars' | ||
| 'lib' | ||
| 'pal' | ||
| 'resources' | ||
| 'tools' | ||
| 'y2j' | ||
| ) | ||
| $localeFolders = $rootFolders | ForEach-Object -Process { | ||
| Get-ChildItem $PSScriptRoot/../../$_/locales -Recurse -Directory | ||
| } | ||
|
|
||
| $projects = @() | ||
| $tomls | ForEach-Object { | ||
| $projectName = (Split-Path $_ -Parent | Split-Path -Parent) | ||
| $projects += @{ project = $projectName; toml = $_ } | ||
| $localeFolders | ForEach-Object -Process { | ||
| $projects += @{ | ||
| project = Split-Path $_ -Parent | ||
| translationInfo = [DscProjectRustTranslationInfo]::new($_) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Describe 'Internationalization tests' { | ||
| It 'Project <project> uses i18n strings from <toml>' -TestCases $projects { | ||
| param($project, $toml) | ||
|
|
||
| $i18n = [System.Collections.Hashtable]::new([System.StringComparer]::Ordinal) | ||
| $prefix = '' | ||
| Get-Content -Path $toml | ForEach-Object { | ||
| if ($_ -match '\[(?<prefix>.*?)\]') { | ||
| $prefix = $Matches['prefix'] | ||
| } | ||
| elseif ($_ -match '^(?<key>\w+)\s?=\s?"(?<value>.*?)"') { | ||
| $key = $prefix + '.' + $Matches['key'] | ||
| $i18n[$key] = 0 | ||
| Context '<project>' -ForEach $projects { | ||
| It 'Uses translation strings' { | ||
| $check = @{ | ||
| Not = $true | ||
| BeNullOrEmpty = $true | ||
| Because = "'$project' defines at least one translation file" | ||
| } | ||
| $translationInfo.UsedTranslations | Should @check | ||
| } | ||
| It 'Does not define any duplicate translation strings' { | ||
| $check = @{ | ||
| BeNullOrEmpty = $true | ||
| Because = (@( | ||
| "The following translation keys are defined more than once:" | ||
| $translationInfo.DuplicateTranslations | ConvertTo-Json -Depth 2 | ||
| ) -join ' ') | ||
| } | ||
|
|
||
| $patterns = @{ | ||
| t = '(?s)\bt\!\(\s*"(?<key>.*?)".*?\)' | ||
| panic_t = '(?s)\bpanic_t\!\(\s*"(?<key>.*?)".*?\)' | ||
| assert_t = '(?s)\bassert_t\!\(\s*.*?,\s*"(?<key>.*?)".*?\)' | ||
| $translationInfo.DuplicateTranslations | Should @check | ||
| } | ||
|
|
||
| $missing = @() | ||
| Get-ChildItem -Recurse -Path $project -Include *.rs -File | ForEach-Object { | ||
| $content = Get-Content -Path $_ -Raw | ||
| foreach ($pattern in $patterns.keys) { | ||
| ($content | Select-String -Pattern $patterns[$pattern] -AllMatches).Matches | ForEach-Object { | ||
| # write-verbose -verbose "Line: $_" | ||
| if ($null -ne $_) { | ||
| $key = $_.Groups['key'].Value | ||
| if ($i18n.ContainsKey($key)) { | ||
| $i18n[$key] = 1 | ||
| } | ||
| else { | ||
| $missing += $key | ||
| } | ||
| } | ||
| } | ||
| It 'Uses every defined translation string' { | ||
| $check = @{ | ||
| BeNullOrEmpty = $true | ||
| Because = (@( | ||
| "The following translation keys are defined but not used:" | ||
| $translationInfo.UnusedTranslations | ConvertTo-Json -Depth 2 | ||
| ) -join ' ') | ||
| } | ||
| $translationInfo.UnusedTranslations | Should @check | ||
| } | ||
|
|
||
| $missing | Should -BeNullOrEmpty -Because "The following i18n keys are missing from $toml :`n$($missing | Out-String)" | ||
| $unused = $i18n.GetEnumerator() | Where-Object { $_.Value -eq 0 } | ForEach-Object { $_.Key } | ||
| $unused | Should -BeNullOrEmpty -Because "The following i18n keys are unused in the project:`n$($unused | Out-String)" | ||
| It 'Defines every used translation string' { | ||
| $check = @{ | ||
| BeNullOrEmpty = $true | ||
| Because = (@( | ||
| "The following translation keys are used but not defined:" | ||
| $translationInfo.MissingTranslations | ConvertTo-Json -Depth 2 | ||
| ) -join ' ') | ||
| } | ||
| $translationInfo.MissingTranslations | Should @check | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| doc-valid-idents = ["IntelliSense", ".."] |
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
Oops, something went wrong.
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.
Is this used anywhere outside of the i18n tests? If not, would prefer to keep that code together in the test ps1 rather than creating a dependency on the helper module for that test
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 put it here for easier access to checking translations during normal development workflow, since the i18n tests are in the
dscproject - when working locally I was testing against thedsc-lib-jsonschemaanddsc-libcrates independently.Happy to move it though if that's preferable.
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.
My preference would be to move it since someone reading this in the future wouldn't be aware of the separation of the code. If it was used across multiple scripts, then it would make more sense to me to have it centralized here.