-
Notifications
You must be signed in to change notification settings - Fork 660
misc: fix typos #1308
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
Merged
Merged
misc: fix typos #1308
Changes from all commits
Commits
Show all changes
2 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
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 was deleted.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/usr/bin/env pwsh | ||
| <# | ||
| .SYNOPSIS | ||
| Reports (and optionally removes) entries in codespell.txt that codespell no longer flags. | ||
|
|
||
| .DESCRIPTION | ||
| Codespell has no built-in way to detect unused entries in an ignore-words file. | ||
| This script runs codespell against the repo with NO ignore-words file, collects the | ||
| set of words it flags, and reports any suppression in codespell.txt that is not in | ||
| that set (i.e., the suppression is no longer needed). | ||
|
|
||
| The pre-commit hook invocation in .pre-commit-config.yaml is mirrored here so the | ||
| scan covers the same files codespell would normally see. | ||
|
|
||
| .PARAMETER Apply | ||
| Rewrite codespell.txt with the unused entries removed. Without this switch the | ||
| script only reports. | ||
|
|
||
| .PARAMETER CodespellCommand | ||
| Override the codespell executable (default: "codespell"). | ||
| #> | ||
| [CmdletBinding()] | ||
| param( | ||
| [switch]$Apply, | ||
| [string]$CodespellCommand = 'codespell' | ||
| ) | ||
|
|
||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $repoRoot = (& git -C $PSScriptRoot rev-parse --show-toplevel).Trim() | ||
| $suppressionsFile = Join-Path $repoRoot '.github/linters/codespell.txt' | ||
|
|
||
| if (-not (Test-Path $suppressionsFile)) { | ||
| throw "Suppressions file not found: $suppressionsFile" | ||
| } | ||
|
|
||
| # Must match the `exclude:` regex for the codespell hook in .pre-commit-config.yaml. | ||
| $excludeRegex = '^src/Lucene\.Net\.Analysis\.Common/Analysis/../.*\.rslp$|^.*Lucene\.Net\.Tests.*$' | ||
|
|
||
| $suppressions = Get-Content -LiteralPath $suppressionsFile | | ||
| Where-Object { $_ -ne '' } | ||
|
|
||
| Write-Host "Loaded $($suppressions.Count) suppression(s) from $suppressionsFile" | ||
| Write-Host "Enumerating git-tracked files (to match pre-commit's view of the repo)..." | ||
|
|
||
| # pre-commit only feeds tracked files to codespell; running codespell directly would | ||
| # also walk bin/, obj/, and other gitignored output. Drive it with `git ls-files` | ||
| # so the two scans cover the same file set. | ||
| Push-Location $repoRoot | ||
| try { | ||
| $trackedFiles = & git ls-files | ||
| Write-Host "Running codespell on $($trackedFiles.Count) tracked file(s) with NO ignore list..." | ||
|
|
||
| # Write the file list to a temp argsfile and pass it with codespell's "@PATH" | ||
| # syntax. This avoids OS argv length limits on large file lists. | ||
| $argsFile = New-TemporaryFile | ||
| try { | ||
| Set-Content -LiteralPath $argsFile -Value $trackedFiles -Encoding utf8 | ||
| # We don't care about exit code: a non-zero exit just means it found | ||
| # misspellings, which is exactly what we want. | ||
| $rawOutput = & $CodespellCommand "@$argsFile" 2>&1 | ||
| } | ||
| finally { | ||
| Remove-Item -LiteralPath $argsFile -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
| finally { | ||
| Pop-Location | ||
| } | ||
|
|
||
| # Codespell output format: "<path>:<line>: <flagged> ==> <suggestion>" | ||
| # Filter out paths that match the pre-commit exclude regex, then extract the flagged word. | ||
| $flagged = New-Object System.Collections.Generic.HashSet[string] | ||
| foreach ($line in $rawOutput) { | ||
| if ($line -notmatch '^(?<path>[^:]+):\d+:\s+(?<word>\S+)\s+==>') { continue } | ||
| $path = $Matches['path'] | ||
| if ($path -match $excludeRegex) { continue } | ||
| # Suppressions are case-sensitive and matched against the dictionary entry's case. | ||
| [void]$flagged.Add($Matches['word'].ToLowerInvariant()) | ||
| } | ||
|
|
||
| Write-Host "Codespell flagged $($flagged.Count) distinct word(s) (after applying exclude regex)." | ||
|
|
||
| $unused = $suppressions | Where-Object { -not $flagged.Contains($_.ToLowerInvariant()) } | ||
|
|
||
| if (-not $unused) { | ||
| Write-Host "No unused suppressions found. codespell.txt is clean." -ForegroundColor Green | ||
| return | ||
| } | ||
|
|
||
| Write-Host "" | ||
| Write-Host "Unused suppressions ($($unused.Count)):" -ForegroundColor Yellow | ||
| $unused | ForEach-Object { Write-Host " $_" } | ||
|
|
||
| if ($Apply) { | ||
| $keep = $suppressions | Where-Object { $flagged.Contains($_.ToLowerInvariant()) } | ||
| # Preserve trailing newline that codespell.txt currently has. | ||
| Set-Content -LiteralPath $suppressionsFile -Value $keep -Encoding utf8 | ||
| Write-Host "" | ||
| Write-Host "Removed $($unused.Count) unused entr$(if ($unused.Count -eq 1) { 'y' } else { 'ies' }) from codespell.txt." -ForegroundColor Green | ||
| } else { | ||
| Write-Host "" | ||
| Write-Host "Re-run with -Apply to remove these from codespell.txt." | ||
| exit 1 | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.