Rule request: AvoidUsingBacktickLineTerminator
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 58/100
Piste de recherche
Commencez par examiner les implémentations existantes de ITokenRule et le point d’entrée AnalyzeTokens décrit dans l’issue, en particulier TokenKind.LineContinuation et le message de diagnostic dans Strings. Confirmez comment les règles comparables sont enregistrées et testées. Le travail est considéré comme terminé lorsque les tokens de continuation de ligne avec backticks produisent des diagnostics informatifs avec le nom de la règle et l’étendue source, sans signaler les tokens sans rapport.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- C#
- Étoiles
- 2.2k
- Forks
- 415
- Merge moyen
- 13 h 1 min
- PR mergées (30 j)
- 2
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de PowerShell/PSScriptAnalyzer
-
Up-for-Grabs
Difficulté 1/5 1-3 heures Accessibilité débutants 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
PowerShell/PSScriptAnalyzer#2217 · 1 commentaire ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 70/100
PowerShell/PSScriptAnalyzer#2210 ·
Toutes les issues de PowerShell/PSScriptAnalyzer
Issues similaires
-
Documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
cake-build/cake#5024 ·
-
Gå gjennom ESLint-suppressions OuverteFrontend status/draft TechnicalDebt
Difficulté 2/5 1-2 jours Accessibilité débutants 75/100
Altinn/altinn-auth#4143 ·
-
.NET Flaky Test Testing Tests
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
getsentry/sentry-dotnet#5617 · 1 commentaire ·
-
Add more to the documentation Ouverte:watch: Not Triaged dotnet-fsharp/svc
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
-
Client customer-reported needs-team-attention question Service Attention WebPubSub
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Azure/azure-sdk-for-net#63292 · 3 commentaires · 1 réaction ·