69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using SQLLinter.Common;
|
|
using SQLLinter.Common.Helpers;
|
|
using SQLLinter.Core.Interfaces;
|
|
using SQLLinter.Infrastructure.Interfaces;
|
|
using SQLLinter.Infrastructure.Parser;
|
|
using SQLLinter.Infrastructure.Plugins;
|
|
|
|
namespace SQLLinter;
|
|
|
|
public class Linter
|
|
{
|
|
private readonly IReporter _reporter;
|
|
private readonly IConfig _config;
|
|
|
|
private IPluginHandler _pluginHandler;
|
|
private ISqlFileProcessor _fileProcessor;
|
|
|
|
public Linter(IConfig config, IReporter reporter)
|
|
: this(config
|
|
, reporter
|
|
, new FragmentBuilder(reporter, config.CompatibilityLevel)
|
|
, new SqlStreamReaderBuilder()
|
|
)
|
|
{ }
|
|
|
|
public Linter(IConfig config, IReporter reporter, IFragmentBuilder fragmentBuilder, ISqlStreamReaderBuilder sqlStreamReaderBuilder)
|
|
{
|
|
this._config = config;
|
|
this._reporter = reporter;
|
|
|
|
_reporter.Report($"Загрузка SQL Linter...");
|
|
|
|
_pluginHandler = new PluginHandler(_reporter, _config);
|
|
|
|
var ruleVisitor = new SqlRuleVisitor(_pluginHandler, fragmentBuilder, _reporter, sqlStreamReaderBuilder);
|
|
|
|
_fileProcessor = new SqlFileProcessor(ruleVisitor, _pluginHandler);
|
|
|
|
_reporter.Report($"SQL Linter загружен...");
|
|
}
|
|
|
|
public void Run(string filePath)
|
|
{
|
|
this.Run([filePath]);
|
|
}
|
|
|
|
public void Run(List<string> filePaths)
|
|
{
|
|
_reporter.Report($"Запуск SQL Linter...");
|
|
|
|
List<string> files = FileHelpers.FindFilesWithMask(filePaths);
|
|
files.ForEach(file => _reporter.Report($@"Найден файл ""{file}"""));
|
|
|
|
_fileProcessor.ProcessList(filePaths);
|
|
}
|
|
|
|
public void Run(string fileName, Stream fileReader)
|
|
{
|
|
Run(new Dictionary<string, Stream> { [fileName] = fileReader });
|
|
}
|
|
|
|
public void Run(Dictionary<string, Stream> files)
|
|
{
|
|
_reporter.Report($"Запуск SQL Linter...");
|
|
|
|
_fileProcessor.ProcessList(files);
|
|
}
|
|
}
|