Добавьте файлы проекта.
This commit is contained in:
12
SQLLinter/Infrastructure/Configuration/Config.cs
Normal file
12
SQLLinter/Infrastructure/Configuration/Config.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using SQLLinter.Common;
|
||||
using SQLLinter.Core.Interfaces;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Configuration
|
||||
{
|
||||
public class Config : IConfig
|
||||
{
|
||||
public int CompatibilityLevel { get; set; }
|
||||
public Dictionary<string, RuleViolationSeverity> Rules { get; set; } = new();
|
||||
public List<string> Plugins { get; set; } = new();
|
||||
}
|
||||
}
|
||||
10
SQLLinter/Infrastructure/Configuration/EnvironmentWrapper.cs
Normal file
10
SQLLinter/Infrastructure/Configuration/EnvironmentWrapper.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace SQLLinter.Infrastructure.Configuration
|
||||
{
|
||||
public class EnvironmentWrapper
|
||||
{
|
||||
public string GetEnvironmentVariable(string name)
|
||||
{
|
||||
return Environment.GetEnvironmentVariable(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using SQLLinter.Core;
|
||||
using SQLLinter.Core.Interfaces;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Configuration.Overrides
|
||||
{
|
||||
public class OverrideCompatabilityLevel : IOverride
|
||||
{
|
||||
public OverrideCompatabilityLevel(string value)
|
||||
{
|
||||
if (int.TryParse(value, out var parsedCompatabilityLevel))
|
||||
{
|
||||
CompatabilityLevel = parsedCompatabilityLevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
CompatabilityLevel = Constants.DefaultCompatabilityLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public int CompatabilityLevel { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using SQLLinter.Core;
|
||||
using SQLLinter.Core.Interfaces;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Configuration.Overrides;
|
||||
|
||||
public class OverrideFinder
|
||||
{
|
||||
private static Regex _OverrideRegex = new Regex(@".*?sqllinter-override ?(.* += +.*)+.*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public IEnumerable<IOverride> GetOverrideList(Stream fileStream)
|
||||
{
|
||||
var overrideList = new List<IOverride>();
|
||||
TextReader reader = new StreamReader(fileStream);
|
||||
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
if (line.Length > Constants.MaxLineWidthForRegexEval || !line.Contains("sqllinter-override"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var match = _OverrideRegex.Match(line);
|
||||
if (!match.Success)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var overrideDetails = match.Groups[1].Value.Split(',').Select(p => p.Trim()).ToList();
|
||||
foreach (var overrideDetail in overrideDetails)
|
||||
{
|
||||
var details = overrideDetail.Split(' ').Select(p => p.Trim()).ToList();
|
||||
if (OverrideTypeMap.List.ContainsKey(details[0]))
|
||||
{
|
||||
var overrideType = OverrideTypeMap.List.GetValueOrDefault(details[0]);
|
||||
overrideList.Add((IOverride)Activator.CreateInstance(overrideType, details[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return overrideList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace SQLLinter.Infrastructure.Configuration.Overrides
|
||||
{
|
||||
public class OverrideTypeMap
|
||||
{
|
||||
public static readonly Dictionary<string, Type> List = new Dictionary<string, Type>
|
||||
{
|
||||
{ "compatibility-level", typeof(OverrideCompatabilityLevel) },
|
||||
// Deprecate usage of misspelled "compatability-level".
|
||||
{ "compatability-level", typeof(OverrideCompatabilityLevel) }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user