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(config, ruleVisitor, _pluginHandler); _reporter.Report($"SQL Linter загружен..."); } public void Run(string filePath) { this.Run([filePath]); } public void Run(List filePaths) { _reporter.Report($"Запуск SQL Linter..."); List files = FileHelpers.FindFilesWithMask(filePaths); files.ForEach(file => _reporter.Report($@"Найден файл ""{file}""")); _fileProcessor.ProcessList(filePaths); } public void Run(string fileName, Stream fileReader) { Run(new Dictionary { [fileName] = fileReader }); } public void Run(Dictionary files) { _reporter.Report($"Запуск SQL Linter..."); _fileProcessor.ProcessList(files); } }