-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1853 from microsoft/bilong-curlyquotescheck
Add CodeFormatter check for curly quotes
- Loading branch information
Showing
16 changed files
with
87 additions
and
34 deletions.
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
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,51 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
function CheckContainsCurlyQuotes { | ||
[CmdletBinding()] | ||
[OutputType([boolean])] | ||
param ( | ||
[Parameter()] | ||
[System.IO.FileInfo] | ||
$FileInfo, | ||
|
||
[Parameter()] | ||
[boolean] | ||
$Save | ||
) | ||
|
||
# Skip this file | ||
if ($FileInfo.FullName -eq "$PSScriptRoot\CheckContainsCurlyQuotes.ps1") { | ||
return $false | ||
} | ||
|
||
$curlyQuotes = $FileInfo | Select-String "‘|’|`“|`”" | ||
if ($curlyQuotes) { | ||
$content = Get-Content -Path $FileInfo.FullName -Raw | ||
if ($Save) { | ||
try { | ||
$content = $content -replace "‘", "'" | ||
$content = $content -replace "’", "'" | ||
$content = $content -replace "`“", '"' | ||
$content = $content -replace "`”", '"' | ||
if ($FileInfo.Extension -eq ".ps1") { | ||
Set-Content -Path $FileInfo.FullName -Value $content.TrimEnd() -Encoding utf8BOM | ||
} else { | ||
Set-Content -Path $FileInfo.FullName -Value $content.TrimEnd() -Encoding utf8NoBOM | ||
} | ||
|
||
Write-Host "Saved with curly quotes replaced: $($FileInfo.FullName)" | ||
$false | ||
} catch { | ||
Write-Warning "Failed to save with curly quotes replaced: $($FileInfo.FullName). Error: $_" | ||
$true | ||
} | ||
} else { | ||
Write-Warning "File contains curly quotes: $($FileInfo.FullName)" | ||
$curlyQuotes | Out-Host | ||
$true | ||
} | ||
} else { | ||
$false | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.