forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cspell.ps1
74 lines (58 loc) · 2.27 KB
/
cspell.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#npm install -g @cspell/dict-java
#cspell link add @cspell/dict-java
$cspellOutput = @{};
$overallTime = Measure-Command {
Start-Process `
-Wait `
-NoNewWindow `
-FilePath 'npx.cmd' `
-ArgumentList 'cspell lint --config .\cspell.json --no-summary --exclude cspell.ps1 **/*' `
-RedirectStandardOutput spelling-errors.txt `
-RedirectStandardError spelling-perf.txt
}
$cspellErrors = Get-Content spelling-errors.txt
$cspellOutput = Get-Content spelling-perf.txt
Write-Host $overallTime
# Add spelling errors to ignore
$spellingErrors = $cspellErrors `
| ForEach-Object {
$line = $_;
$_ -match 'Unknown word \((.*)\)' | Out-Null;
$file = $line.Substring(0, $line.LastIndexOf(':', $line.LastIndexOf(':') - 1));
$word = $Matches[1];
return @{
Line = $line;
File = $file;
Word = $word;
}
}
$filesToIgnore = $spellingErrors | ForEach-Object { $_.File.Substring((Get-Location).Path.Length + 1) }
$uniqueFilesToIgnore = @{}
$filesToIgnore | ForEach-Object { $_.Replace("\", '/') } | ForEach-Object { $uniqueFilesToIgnore[$_] = $null }
$cspellConfig = Get-Content cspell.json | ConvertFrom-Json
$cspellConfig.ignorePaths += $uniqueFilesToIgnore.Keys | Sort-Object
$cspellConfig | ConvertTo-Json | Set-Content cspell.json
$cspellErrors | Set-Content .\spelling-errors.txt
Write-Host "Added $($uniqueFilesToIgnore.Keys.Count) files to list"
# Output Performance Information
$spellingPerf = $cspellOutput `
| Where-Object { $_.Trim().EndsWith('-') -ne $true }
| ForEach-Object {
$line = $_.Trim();
$firstSpace = $line.IndexOf(' ');
$lastSpace = $line.LastIndexOf(' ');
$file = $line.Substring($firstSpace + 1, $lastSpace - $firstSpace - 1);
@{
Progress = $line.Split(' ')[0];
File = $file;
Extension = [System.IO.Path]::GetExtension($file);
Time = $line.Substring($lastSpace + 1, $line.Length - $lastSpace - 3);
}
}
"Progress,File,Extension,Time" | Set-Content spelling-perf.csv
$spellingPerf | ForEach-Object { "$($_.Progress),$($_.File),$($_.Extension),$($_.Time)" } | Add-Content spelling-perf.csv
Import-Csv spelling-perf.csv `
| Group-Object Extension `
| ForEach-Object { [PSCustomObject]@{ Extension = $_.Name; Total = ($_.Group | Measure-Object Time -Sum).Sum } } `
| Sort-Object Total -Descending `
| Format-Table