Rule request: AvoidUsingBacktickLineTerminator
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 58/100
調査の方向性
まず、既存の ITokenRule 実装と issue で説明されている AnalyzeTokens エントリポイントを調べます。特に TokenKind.LineContinuation と Strings 内の診断メッセージを確認してください。比較対象となるルールがどのように登録され、テストされているかを確認します。バックティックの行継続トークンが、ルール名とソース範囲を含む情報診断を生成し、無関係なトークンにはフラグを付けないことが完了条件です。
索引モデルが issue の本文から書いたものです。
説明
Summary of the new feature
As a code reviewer, I want script/module writers to receive automated informational warnings about backtick usage so that my review time isn't consumed by catching maintainability issues that tooling should prevent upfront.
Problem Statement:
The backtick (`) character is commonly used for line continuation in PowerShell, but it's considered poor practice for several reasons:
- Hard to see: Backticks are nearly invisible and easily missed during code review
- Poor readability: Makes code harder to read and understand
- Maintenance issues: Easy to accidentally remove or misplace during editing
- Non-intuitive: New PowerShell users often struggle with backtick usage
PowerShell offers better alternatives like parameter splatting and natural line breaks after operators/pipelines that are more readable and less error-prone.
Proposed technical implementation details
Rule Name: PSAvoidUsingBacktickLineTerminator
Severity: Information
Behavior:
- Flag any usage of backtick (`) character used for line continuation
- Suggest appropriate alternatives based on context
Recommended alternatives to suggest:
- Parameter Splatting: For commands with multiple parameters
- Natural line breaks: After pipeline operators (
|), logical operators (-and,-or), comparison operators - Parentheses grouping: For complex expressions
Example violations:
# Backtick line continuation - Flagged
Get-Process -Name notepad `
-ErrorAction SilentlyContinue `
| Where-Object CPU -gt 100
# Complex command with backticks - Flagged
$result = Get-ChildItem -Path C:\Temp `
-Filter "*.txt" `
-Recurse `
-ErrorAction SilentlyContinue
Technical Implementation:
- I plan on taking this issue if approved.
- Simple class that inherits ITokenRule:
public IEnumerable<DiagnosticRecord> AnalyzeTokens(Token[] tokens, string fileName)
{
if (tokens == null) throw new ArgumentNullException(Strings.NullTokensErrorMessage);
var lineContinuationTokens = tokens.Where(token => token.Kind == TokenKind.LineContinuation);
foreach (var tokenNode in lineContinuationTokens)
{
yield return new DiagnosticRecord(
string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingBacktickLineTerminatorError),
tokenNode.Extent,
GetName(),
DiagnosticSeverity.Information,
fileName
);
}
}
What is the latest version of PSScriptAnalyzer at the point of writing
1.24.0
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 415
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PowerShell/PSScriptAnalyzer のほかの issue
-
Up-for-Grabs
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
PowerShell/PSScriptAnalyzer#2213 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
PowerShell/PSScriptAnalyzer#2217 · コメント 1 件 ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) オープン
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
PowerShell/PSScriptAnalyzer#2216 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks オープン
難易度 3/5 1〜2日 初心者へのやさしさ 70/100
PowerShell/PSScriptAnalyzer#2210 ·
PowerShell/PSScriptAnalyzer の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
azurenoops/spin_agent#975 ·
-
:watch: Not Triaged 11.0 fundamentals/subsvc
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
dotnet/AspNetCore.Docs#37699 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
SubtitleEdit/subtitleedit#15108 · コメント 1 件 ·
-
area/docs-content Bug pulumi/docs
難易度 1/5 1〜3時間 初心者へのやさしさ 94/100