diff --git a/src/EditorConfig.Core/Charset.cs b/src/EditorConfig.Core/Charset.cs index a4652da..1ce2694 100644 --- a/src/EditorConfig.Core/Charset.cs +++ b/src/EditorConfig.Core/Charset.cs @@ -5,6 +5,7 @@ /// public enum Charset { +#pragma warning disable CS1591 Latin1, UTF8, /// @@ -13,6 +14,7 @@ public enum Charset UTF8BOM, UTF16BE, UTF16LE, +#pragma warning restore CS1591 } -} \ No newline at end of file +} diff --git a/src/EditorConfig.Core/ConfigSection.cs b/src/EditorConfig.Core/ConfigSection.cs index f3cc1da..b7bea39 100644 --- a/src/EditorConfig.Core/ConfigSection.cs +++ b/src/EditorConfig.Core/ConfigSection.cs @@ -12,8 +12,10 @@ public class ConfigSection : IReadOnlyDictionary private readonly Dictionary _backingDictionary; private static readonly Dictionary DefaultGlobalDictionary = new Dictionary(); + /// Represents an ini section within the editorconfig file public ConfigSection() => _backingDictionary = DefaultGlobalDictionary; + /// Represents an ini section within the editorconfig file public ConfigSection(string name, string configDirectory, Dictionary backingDictionary) { Glob = FixGlob(name, configDirectory); @@ -206,12 +208,18 @@ IEnumerator> IEnumerable ((IEnumerable) _backingDictionary).GetEnumerator(); + /// public int Count => _backingDictionary.Count; + /// public bool ContainsKey(string key) => _backingDictionary.ContainsKey(key); + /// public bool TryGetValue(string key, out string value) => _backingDictionary.TryGetValue(key, out value); + /// public string this[string key] => _backingDictionary[key]; + /// public IEnumerable Keys => _backingDictionary.Keys; + /// public IEnumerable Values => _backingDictionary.Values; } } diff --git a/src/EditorConfig.Core/EditorConfig.Core.csproj b/src/EditorConfig.Core/EditorConfig.Core.csproj index 9dafb03..1522205 100644 --- a/src/EditorConfig.Core/EditorConfig.Core.csproj +++ b/src/EditorConfig.Core/EditorConfig.Core.csproj @@ -5,6 +5,7 @@ editorconfig EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readibly and they work nicely with version control systems. This is the core library of EditorConfig written ported to .NET. development editor IDE coding-style editorconfig + true true diff --git a/src/EditorConfig.Core/EditorConfigFile.cs b/src/EditorConfig.Core/EditorConfigFile.cs index a7ebe68..8557b88 100644 --- a/src/EditorConfig.Core/EditorConfigFile.cs +++ b/src/EditorConfig.Core/EditorConfigFile.cs @@ -8,14 +8,14 @@ namespace EditorConfig.Core { /// - /// Represents the raw config file as INI + /// Represents the raw config file as INI, please use /// public class EditorConfigFile { private static readonly Regex SectionRe = new Regex(@"^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$"); private static readonly Regex CommentRe = new Regex(@"^\s*[#;]"); private static readonly Regex PropertyRe = new Regex(@"^\s*([\w\.\-_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$"); - + private static readonly string[] KnownProperties = { "indent_style", @@ -29,15 +29,18 @@ public class EditorConfigFile "root", }; - private readonly Dictionary _globalDict = new Dictionary(); - public List Sections { get; } = new List(); + private readonly Dictionary _globalDict = new Dictionary(); + /// All discovered sections + public List Sections { get; } = new List(); + /// The directory of the EditorConfig file public string Directory { get; } - + private readonly bool _isRoot; + /// Indicates wheter the loaded editorconfig represents the root of the chain public bool IsRoot => _isRoot; - public EditorConfigFile(string file) + internal EditorConfigFile(string file) { Directory = Path.GetDirectoryName(file); Parse(file); @@ -57,18 +60,18 @@ private void Parse(string file) foreach (var line in lines) { if (string.IsNullOrWhiteSpace(line)) continue; - + if (CommentRe.IsMatch(line)) continue; var matches = PropertyRe.Matches(line); if (matches.Count > 0) { var key = matches[0].Groups[1].Value.Trim(); var value = matches[0].Groups[2].Value.Trim(); - + key = key.ToLowerInvariant(); if (KnownProperties.Contains(key, StringComparer.OrdinalIgnoreCase)) value = value.ToLowerInvariant(); - + //! do not Add(), avoid exceptions on duplicate keys activeDict[key] = value; reset = false; @@ -93,7 +96,7 @@ private void Parse(string file) var section = new ConfigSection(sectionName, Directory, activeDict); Sections.Add(section); } - + } } } diff --git a/src/EditorConfig.Core/EditorConfigParser.cs b/src/EditorConfig.Core/EditorConfigParser.cs index d305290..d88a9c5 100644 --- a/src/EditorConfig.Core/EditorConfigParser.cs +++ b/src/EditorConfig.Core/EditorConfigParser.cs @@ -89,7 +89,7 @@ private bool IsMatch(string glob, string fileName, string directory) } /// - /// Gets all relevant for until the first config file upwards + /// Gets all relevant for until the first config file upwards /// marked as root. /// public IList GetConfigurationFilesTillRoot(string file) diff --git a/src/EditorConfig.Core/EndOfLine.cs b/src/EditorConfig.Core/EndOfLine.cs index 1251cb4..5a2ddb9 100644 --- a/src/EditorConfig.Core/EndOfLine.cs +++ b/src/EditorConfig.Core/EndOfLine.cs @@ -6,9 +6,11 @@ namespace EditorConfig.Core public enum EndOfLine { // ReSharper disable InconsistentNaming +#pragma warning disable CS1591 LF, CR, CRLF +#pragma warning restore CS1591 // ReSharper restore InconsistentNaming } -} \ No newline at end of file +} diff --git a/src/EditorConfig.Core/FileConfiguration.cs b/src/EditorConfig.Core/FileConfiguration.cs index f16de7e..f35bbf5 100644 --- a/src/EditorConfig.Core/FileConfiguration.cs +++ b/src/EditorConfig.Core/FileConfiguration.cs @@ -7,6 +7,9 @@ namespace EditorConfig.Core { + /// + /// Represents the result of and yields all configuration for a particular file + /// public class FileConfiguration { private List Sections { get; } @@ -69,7 +72,7 @@ public class FileConfiguration public Version Version { get; } /// - /// Holds the editor configuration for a file, please use to get an instance + /// Holds the editor configuration for a file, please use to get an instance /// internal FileConfiguration(Version version, string fileName, List sections) { @@ -87,12 +90,12 @@ internal FileConfiguration(Version version, string fileName, List IndentStyle = Sections.LastOrDefault(s => s.IndentStyle.HasValue)?.IndentStyle; IndentSize = Sections.LastOrDefault(s => s.IndentSize != null)?.IndentSize; - TabWidth = Sections.LastOrDefault(s => s.TabWidth.HasValue)?.TabWidth; - EndOfLine = Sections.LastOrDefault(s => s.EndOfLine.HasValue)?.EndOfLine; - Charset = Sections.LastOrDefault(s => s.Charset.HasValue)?.Charset; - TrimTrailingWhitespace = Sections.LastOrDefault(s => s.TrimTrailingWhitespace.HasValue)?.TrimTrailingWhitespace; - InsertFinalNewline = Sections.LastOrDefault(s => s.InsertFinalNewline.HasValue)?.InsertFinalNewline; - MaxLineLength = Sections.LastOrDefault(s => s.MaxLineLength.HasValue)?.MaxLineLength; + TabWidth = Sections.FirstOrDefault(s => s.TabWidth.HasValue)?.TabWidth; + EndOfLine = Sections.FirstOrDefault(s => s.EndOfLine.HasValue)?.EndOfLine; + Charset = Sections.FirstOrDefault(s => s.Charset.HasValue)?.Charset; + TrimTrailingWhitespace = Sections.FirstOrDefault(s => s.TrimTrailingWhitespace.HasValue)?.TrimTrailingWhitespace; + InsertFinalNewline = Sections.FirstOrDefault(s => s.InsertFinalNewline.HasValue)?.InsertFinalNewline; + MaxLineLength = Sections.FirstOrDefault(s => s.MaxLineLength.HasValue)?.MaxLineLength; //default tab_width to indent_size when indent size is a number if (IndentSize != null && IndentSize.NumberOfColumns.HasValue) diff --git a/src/EditorConfig.Core/IndentSize.cs b/src/EditorConfig.Core/IndentSize.cs index 5a1f1e5..6415847 100644 --- a/src/EditorConfig.Core/IndentSize.cs +++ b/src/EditorConfig.Core/IndentSize.cs @@ -1,16 +1,17 @@ using System.Diagnostics; +#pragma warning disable CS1591 namespace EditorConfig.Core { /// - /// a whole number defining the number of columns used for each indentation level and the width of soft tabs (when supported). + /// a whole number defining the number of columns used for each indentation level and the width of soft tabs (when supported). /// When set to tab, the value of tab_width (if specified) will be used. /// public class IndentSize { public static IndentSize Tab { get; } = new IndentSize(useTabs: true); public static IndentSize Unset { get; } = new IndentSize(); - + private static IndentSize Column1 { get; } = new IndentSize(1); private static IndentSize Column2 { get; } = new IndentSize(2); private static IndentSize Column3 { get; } = new IndentSize(3); @@ -47,4 +48,5 @@ public static IndentSize Columns(int numberOfColumns) private IndentSize(int numberOfColumns) => NumberOfColumns = numberOfColumns; } -} \ No newline at end of file +#pragma warning restore CS1591 +} diff --git a/src/EditorConfig.Core/IndentStyle.cs b/src/EditorConfig.Core/IndentStyle.cs index 8332e32..a9bf358 100644 --- a/src/EditorConfig.Core/IndentStyle.cs +++ b/src/EditorConfig.Core/IndentStyle.cs @@ -5,7 +5,9 @@ namespace EditorConfig.Core /// public enum IndentStyle { +#pragma warning disable CS1591 Tab, Space +#pragma warning restore CS1591 } -} \ No newline at end of file +} diff --git a/src/EditorConfig.Core/Minimatcher.cs b/src/EditorConfig.Core/Minimatcher.cs index a07fe3a..5f19697 100644 --- a/src/EditorConfig.Core/Minimatcher.cs +++ b/src/EditorConfig.Core/Minimatcher.cs @@ -56,6 +56,9 @@ public class GlobMatcherOptions // ReSharper restore UnusedAutoPropertyAccessor.Global + /// + /// A simple glob matcher implementation, if you want a proper one please use a full fletched one from nuget. + /// public class GlobMatcher { private readonly GlobMatcherOptions myOptions;