Skip to content

Commit 31926f0

Browse files
committed
add ruleId to PSAvoidAssignmentToAutomaticVariable
Enables suppression for specific variable/parameter. Fix PowerShell#1589
1 parent 19a6a18 commit 31926f0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Rules/AvoidAssignmentToAutomaticVariable.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
6262
if (_readOnlyAutomaticVariables.Contains(variableName, StringComparer.OrdinalIgnoreCase))
6363
{
6464
yield return new DiagnosticRecord(DiagnosticRecordHelper.FormatError(Strings.AvoidAssignmentToReadOnlyAutomaticVariableError, variableName),
65-
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Error, fileName);
65+
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Error, fileName, variableName);
6666
}
6767

6868
if (_readOnlyAutomaticVariablesIntroducedInVersion6_0.Contains(variableName, StringComparer.OrdinalIgnoreCase))
6969
{
7070
var severity = IsPowerShellVersion6OrGreater() ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning;
7171
yield return new DiagnosticRecord(DiagnosticRecordHelper.FormatError(Strings.AvoidAssignmentToReadOnlyAutomaticVariableIntroducedInPowerShell6_0Error, variableName),
72-
variableExpressionAst.Extent, GetName(), severity, fileName);
72+
variableExpressionAst.Extent, GetName(), severity, fileName, variableName);
7373
}
7474

7575
if (_writableAutomaticVariables.Contains(variableName, StringComparer.OrdinalIgnoreCase))
7676
{
7777
yield return new DiagnosticRecord(DiagnosticRecordHelper.FormatError(Strings.AvoidAssignmentToWritableAutomaticVariableError, variableName),
78-
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
78+
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName, variableName);
7979
}
8080
}
8181

@@ -93,20 +93,20 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
9393
if (_readOnlyAutomaticVariables.Contains(variableName, StringComparer.OrdinalIgnoreCase))
9494
{
9595
yield return new DiagnosticRecord(DiagnosticRecordHelper.FormatError(Strings.AvoidAssignmentToReadOnlyAutomaticVariableError, variableName),
96-
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Error, fileName);
96+
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Error, fileName, variableName);
9797
}
9898

9999
if (_readOnlyAutomaticVariablesIntroducedInVersion6_0.Contains(variableName, StringComparer.OrdinalIgnoreCase))
100100
{
101101
var severity = IsPowerShellVersion6OrGreater() ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning;
102102
yield return new DiagnosticRecord(DiagnosticRecordHelper.FormatError(Strings.AvoidAssignmentToReadOnlyAutomaticVariableIntroducedInPowerShell6_0Error, variableName),
103-
variableExpressionAst.Extent, GetName(), severity, fileName);
103+
variableExpressionAst.Extent, GetName(), severity, fileName, variableName);
104104
}
105105

106106
if (_writableAutomaticVariables.Contains(variableName, StringComparer.OrdinalIgnoreCase))
107107
{
108108
yield return new DiagnosticRecord(DiagnosticRecordHelper.FormatError(Strings.AvoidAssignmentToWritableAutomaticVariableError, variableName),
109-
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
109+
variableExpressionAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName, variableName);
110110
}
111111
}
112112
}

0 commit comments

Comments
 (0)