Добавьте файлы проекта.
This commit is contained in:
50
SQLLinter/Infrastructure/Parser/ViolationFixer.cs
Normal file
50
SQLLinter/Infrastructure/Parser/ViolationFixer.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using SQLLinter.Common;
|
||||
using SQLLinter.Infrastructure.Interfaces;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Parser;
|
||||
|
||||
public class ViolationFixer : IViolationFixer
|
||||
{
|
||||
private readonly Dictionary<string, IRule> Rules;
|
||||
private readonly IList<IRuleViolation> Violations;
|
||||
|
||||
public ViolationFixer(
|
||||
Dictionary<string, IRule> rules,
|
||||
IList<IRuleViolation> violations)
|
||||
{
|
||||
Rules = rules;
|
||||
Violations = violations;
|
||||
}
|
||||
|
||||
public void Fix()
|
||||
{
|
||||
var files = Violations.GroupBy(x => x.FileName);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var fileViolations = file
|
||||
.OrderByDescending(x => x.Line)
|
||||
.ThenByDescending(x => x.Column)
|
||||
.ToList();
|
||||
|
||||
var fileLines = File.ReadAllLines(file.Key).ToList();
|
||||
var fileLineActions = new Common.FileLineActions(fileViolations, fileLines);
|
||||
|
||||
foreach (var violation in fileViolations)
|
||||
{
|
||||
if (Rules.ContainsKey(violation.RuleName))
|
||||
{
|
||||
if (violation.Line == 1 && violation.Column > fileLines[violation.Line - 1].Length + 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var lines = new List<string>(fileLines);
|
||||
//Rules[violation.RuleName].FixViolation(lines, violation, fileLineActions);
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteAllLines(file.Key, fileLines);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user