From bac27b1c17d169fe09715b71fe42736b8112e01d Mon Sep 17 00:00:00 2001 From: ASVLCII <308706627+ASVLCII@users.noreply.github.com> Date: Mon, 31 Aug 2026 21:06:42 +0700 Subject: [PATCH] Add formatter check for backtick line continuation Co-authored-by: OpenAI Codex --- .../CheckBacktickLineContinuation.ps1 | 35 +++++++++++++++++++ .build/Invoke-CodeFormatterOnFiles.ps1 | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 .build/CodeFormatterChecks/CheckBacktickLineContinuation.ps1 diff --git a/.build/CodeFormatterChecks/CheckBacktickLineContinuation.ps1 b/.build/CodeFormatterChecks/CheckBacktickLineContinuation.ps1 new file mode 100644 index 0000000000..ef899ce02e --- /dev/null +++ b/.build/CodeFormatterChecks/CheckBacktickLineContinuation.ps1 @@ -0,0 +1,35 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +function CheckBacktickLineContinuation { + [CmdletBinding()] + [OutputType([boolean])] + param ( + [Parameter()] + [System.IO.FileInfo] + $FileInfo, + + [Parameter()] + [boolean] + $Save + ) + + if ($FileInfo.Extension -ne ".ps1" -and $FileInfo.Extension -ne ".psm1") { + return $false + } + + $content = Get-Content -Path $FileInfo.FullName -Raw + $errorsReturned = $null + $tokens = [System.Management.Automation.PSParser]::Tokenize($content, [ref]$errorsReturned) + if ($errorsReturned.Count -gt 0) { + Write-Warning "Failed to tokenize script: $($FileInfo.FullName)." + return $true + } + + $lineContinuations = @($tokens | Where-Object { $_.Type -eq "LineContinuation" }) + foreach ($token in $lineContinuations) { + Write-Warning "Backtick line continuation at line $($token.StartLine) in file $($FileInfo.FullName)." + } + + return $lineContinuations.Count -gt 0 +} diff --git a/.build/Invoke-CodeFormatterOnFiles.ps1 b/.build/Invoke-CodeFormatterOnFiles.ps1 index ecdfead484..22fa37e8cc 100644 --- a/.build/Invoke-CodeFormatterOnFiles.ps1 +++ b/.build/Invoke-CodeFormatterOnFiles.ps1 @@ -5,6 +5,7 @@ . $PSScriptRoot\Load-Module.ps1 . $PSScriptRoot\CodeFormatterChecks\CheckContainsCurlyQuotes.ps1 +. $PSScriptRoot\CodeFormatterChecks\CheckBacktickLineContinuation.ps1 . $PSScriptRoot\CodeFormatterChecks\CheckFileHasNewlineAtEndOfFile.ps1 . $PSScriptRoot\CodeFormatterChecks\CheckMarkdownFileHasNoBOM.ps1 . $PSScriptRoot\CodeFormatterChecks\CheckMultipleEmptyLines.ps1 @@ -59,6 +60,7 @@ function Invoke-CodeFormatterOnFiles { $errorCount += (CheckTokenTypeCasing $fileInfo $Save "Operator") ? 1 : 0 $errorCount += (CheckMultipleEmptyLines $fileInfo $Save) ? 1 : 0 $errorCount += (CheckContainsCurlyQuotes $fileInfo $Save) ? 1 : 0 + $errorCount += (CheckBacktickLineContinuation $fileInfo $Save) ? 1 : 0 $results = @(CheckScriptFormat $fileInfo $Save) if ($results.Length -gt 0 -and $results[0] -eq $true) {