Skip to content

Commit b382add

Browse files
committed
Inline the 2 overloads of GetDiagnosticRecord to their individual call sites
It made it cumbersome to pass a different number of arguments to the string.Format call and didn't seem necessary
1 parent a9898a6 commit b382add

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

Rules/UseCorrectCasing.cs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,19 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
103103

104104
if (!commandName.Equals(correctlyCasedCommandName, StringComparison.Ordinal))
105105
{
106-
yield return GetDiagnosticRecord(commandAst, fileName, correctlyCasedCommandName, Strings.UseCorrectCasingError);
106+
var extent = GetCommandExtent(commandAst);
107+
yield return new DiagnosticRecord(
108+
string.Format(
109+
CultureInfo.CurrentCulture,
110+
Strings.UseCorrectCasingError,
111+
commandName,
112+
correctlyCasedCommandName),
113+
extent,
114+
GetName(),
115+
DiagnosticSeverity.Information,
116+
fileName,
117+
correctlyCasedCommandName,
118+
GetCorrectionExtent(commandAst, extent, correctlyCasedCommandName));
107119
}
108120

109121
var commandParameterAsts = commandAst.FindAll(
@@ -129,15 +141,27 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
129141
var correctlyCasedParameterName = parameterMetaData.Name;
130142
if (!parameterName.Equals(correctlyCasedParameterName, StringComparison.Ordinal))
131143
{
132-
yield return GetDiagnosticRecord(commandParameterAst, fileName, correctlyCasedParameterName, Strings.UseCorrectCasingError);
144+
var message = string.Format(
145+
CultureInfo.CurrentCulture,
146+
Strings.UseCorrectCasingParameterError,
147+
commandParameterAst.Extent.Text,
148+
commandName,
149+
correctlyCasedParameterName);
150+
yield return new DiagnosticRecord(
151+
message,
152+
commandParameterAst.Extent,
153+
GetName(),
154+
DiagnosticSeverity.Information,
155+
fileName,
156+
correctlyCasedParameterName,
157+
GetCorrectionExtent(commandParameterAst, commandParameterAst.Extent, correctlyCasedParameterName));
133158
}
134159
}
135160
}
136161
}
137162
}
138163
}
139164

140-
141165
/// <summary>
142166
/// For a command like "gci -path c:", returns the extent of "gci" in the command
143167
/// </summary>
@@ -197,32 +221,6 @@ private DiagnosticRecord GetDiagnosticRecord(Token token, string fileName, strin
197221
suggestedCorrections: extents);
198222
}
199223

200-
private DiagnosticRecord GetDiagnosticRecord(Ast ast, string fileName, string correction, string message)
201-
{
202-
var extent = ast is CommandAst ? GetCommandExtent((CommandAst)ast) : ast.Extent;
203-
return new DiagnosticRecord(
204-
string.Format(CultureInfo.CurrentCulture, message, extent.Text, correction),
205-
extent,
206-
GetName(),
207-
DiagnosticSeverity.Information,
208-
fileName,
209-
correction,
210-
suggestedCorrections: GetCorrectionExtent(ast, extent, correction));
211-
}
212-
213-
private DiagnosticRecord GetDiagnosticRecord(CommandParameterAst ast, string fileName, string correction, string message)
214-
{
215-
var extent = ast.Extent;
216-
return new DiagnosticRecord(
217-
string.Format(CultureInfo.CurrentCulture, message, extent.Text, correction),
218-
extent,
219-
GetName(),
220-
DiagnosticSeverity.Information,
221-
fileName,
222-
correction,
223-
suggestedCorrections: GetCorrectionExtent(ast, extent, correction));
224-
}
225-
226224
/// <summary>
227225
/// GetName: Retrieves the name of this rule.
228226
/// </summary>

0 commit comments

Comments
 (0)