You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varerrorMessagePreFix="Failed to apply AutoFix when writing to file "+scriptPath+Environment.NewLine;
175
+
// we need to catch all exceptions that could be thrown except for ArgumentException and ArgumentNullException because at this stage the file path has already been verified.
176
+
try
177
+
{
178
+
Console.WriteLine($"AutoFix {this.RuleName} by replacing '{textToBeReplaced}' with '{textReplacement}' in line {lineNumber} of file {scriptPath}");
179
+
File.WriteAllLines(scriptPath,originalLines);
180
+
}
181
+
catch(PathTooLongException)
182
+
{
183
+
Console.WriteLine(errorMessagePreFix+"The specified path, file name, or both exceed the system - defined maximum length. "+
184
+
"For example, on Windows - based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.");
185
+
}
186
+
catch(DirectoryNotFoundException)
187
+
{
188
+
Console.WriteLine(errorMessagePreFix+"The specified path is invalid (for example, it is on an unmapped drive).");
189
+
}
190
+
catch(IOException)
191
+
{
192
+
Console.WriteLine(errorMessagePreFix+"An I/O error occurred while opening the file.");
193
+
}
194
+
catch(UnauthorizedAccessException)
195
+
{
196
+
Console.WriteLine(errorMessagePreFix+"Path specified a file that is read-only or this operation is not supported on the current platform or the caller does not have the required permission.");
197
+
}
198
+
catch(SecurityException)
199
+
{
200
+
Console.WriteLine(errorMessagePreFix+"You do not have the required permission to write to the file.");
diagnosticRecords=this.AnalyzeFile(scriptFilePath);// update records with the correct line numbers after fix
1489
+
}
1490
+
}
1491
+
foreach(vardiagnosticRecordindiagnosticRecords)
1481
1492
{
1482
1493
yieldreturndiagnosticRecord;
1483
1494
}
1484
1495
}
1485
1496
}
1486
1497
1498
+
/// <summary>
1499
+
/// Fixes only the first fixable DiagnosticRecord that it encounters because afterwards the other records need to be re-created as their line/column numbers are different then
1500
+
/// </summary>
1501
+
/// <param name="diagnosticRecords"></param>
1502
+
/// <returns>True if it could fix a warning</returns>
0 commit comments