Skip to content

Commit

Permalink
Fix #17 ensure xmldocs are available (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Jul 20, 2022
1 parent fbbc37c commit d227b47
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/EditorConfig.Core/Charset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// </summary>
public enum Charset
{
#pragma warning disable CS1591
Latin1,
UTF8,
/// <summary>
Expand All @@ -13,6 +14,7 @@ public enum Charset
UTF8BOM,
UTF16BE,
UTF16LE,
#pragma warning restore CS1591

}
}
}
8 changes: 8 additions & 0 deletions src/EditorConfig.Core/ConfigSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public class ConfigSection : IReadOnlyDictionary<string, string>
private readonly Dictionary<string, string> _backingDictionary;

private static readonly Dictionary<string, string> DefaultGlobalDictionary = new Dictionary<string, string>();
/// <summary> Represents an ini section within the editorconfig file </summary>
public ConfigSection() => _backingDictionary = DefaultGlobalDictionary;

/// <summary> Represents an ini section within the editorconfig file </summary>
public ConfigSection(string name, string configDirectory, Dictionary<string, string> backingDictionary)
{
Glob = FixGlob(name, configDirectory);
Expand Down Expand Up @@ -206,12 +208,18 @@ IEnumerator<KeyValuePair<string, string>> IEnumerable<KeyValuePair<string, strin

IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable) _backingDictionary).GetEnumerator();

/// <inheritdoc cref="ICollection.Count"/>
public int Count => _backingDictionary.Count;
/// <inheritdoc cref="Dictionary{TKey,TValue}.ContainsKey"/>
public bool ContainsKey(string key) => _backingDictionary.ContainsKey(key);
/// <inheritdoc cref="Dictionary{TKey,TValue}.TryGetValue"/>
public bool TryGetValue(string key, out string value) =>
_backingDictionary.TryGetValue(key, out value);
/// <inheritdoc cref="Dictionary{TKey,TValue}.get_Item"/>
public string this[string key] => _backingDictionary[key];
/// <inheritdoc cref="Dictionary{TKey,TValue}.Keys"/>
public IEnumerable<string> Keys => _backingDictionary.Keys;
/// <inheritdoc cref="Dictionary{TKey,TValue}.Values"/>
public IEnumerable<string> Values => _backingDictionary.Values;
}
}
1 change: 1 addition & 0 deletions src/EditorConfig.Core/EditorConfig.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PackageId>editorconfig</PackageId>
<Description>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.</Description>
<PackageTags>development editor IDE coding-style editorconfig</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down
23 changes: 13 additions & 10 deletions src/EditorConfig.Core/EditorConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
namespace EditorConfig.Core
{
/// <summary>
/// Represents the raw config file as INI
/// Represents the raw config file as INI, please use <see cref="EditorConfigParser.GetConfigurationFilesTillRoot"/>
/// </summary>
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",
Expand All @@ -29,15 +29,18 @@ public class EditorConfigFile
"root",
};

private readonly Dictionary<string, string> _globalDict = new Dictionary<string, string>();
public List<ConfigSection> Sections { get; } = new List<ConfigSection>();
private readonly Dictionary<string, string> _globalDict = new Dictionary<string, string>();
/// <summary> All discovered sections </summary>
public List<ConfigSection> Sections { get; } = new List<ConfigSection>();

/// <summary> The directory of the EditorConfig file </summary>
public string Directory { get; }

private readonly bool _isRoot;
/// <summary> Indicates wheter the loaded editorconfig represents the root of the chain </summary>
public bool IsRoot => _isRoot;

public EditorConfigFile(string file)
internal EditorConfigFile(string file)
{
Directory = Path.GetDirectoryName(file);
Parse(file);
Expand All @@ -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;
Expand All @@ -93,7 +96,7 @@ private void Parse(string file)
var section = new ConfigSection(sectionName, Directory, activeDict);
Sections.Add(section);
}

}
}
}
2 changes: 1 addition & 1 deletion src/EditorConfig.Core/EditorConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private bool IsMatch(string glob, string fileName, string directory)
}

/// <summary>
/// Gets all relevant <see cref="EditorConfigFile"/> for <see cref="file"/> until the first config file upwards
/// Gets all relevant <see cref="EditorConfigFile"/> for <paramref name="file"/> until the first config file upwards
/// marked as root.
/// </summary>
public IList<EditorConfigFile> GetConfigurationFilesTillRoot(string file)
Expand Down
4 changes: 3 additions & 1 deletion src/EditorConfig.Core/EndOfLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
17 changes: 10 additions & 7 deletions src/EditorConfig.Core/FileConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
namespace EditorConfig.Core
{

/// <summary>
/// Represents the result of <see cref="EditorConfigParser.Parse(string[])"/> and yields all configuration for a particular file
/// </summary>
public class FileConfiguration
{
private List<ConfigSection> Sections { get; }
Expand Down Expand Up @@ -69,7 +72,7 @@ public class FileConfiguration
public Version Version { get; }

/// <summary>
/// Holds the editor configuration for a file, please use <see cref="EditorConfigParser.Parse"/> to get an instance
/// Holds the editor configuration for a file, please use <see cref="EditorConfigParser.Parse(string[])"/> to get an instance
/// </summary>
internal FileConfiguration(Version version, string fileName, List<ConfigSection> sections)
{
Expand All @@ -87,12 +90,12 @@ internal FileConfiguration(Version version, string fileName, List<ConfigSection>

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)
Expand Down
8 changes: 5 additions & 3 deletions src/EditorConfig.Core/IndentSize.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System.Diagnostics;

#pragma warning disable CS1591
namespace EditorConfig.Core
{
/// <summary>
/// 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.
/// </summary>
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);
Expand Down Expand Up @@ -47,4 +48,5 @@ public static IndentSize Columns(int numberOfColumns)

private IndentSize(int numberOfColumns) => NumberOfColumns = numberOfColumns;
}
}
#pragma warning restore CS1591
}
4 changes: 3 additions & 1 deletion src/EditorConfig.Core/IndentStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace EditorConfig.Core
/// </summary>
public enum IndentStyle
{
#pragma warning disable CS1591
Tab,
Space
#pragma warning restore CS1591
}
}
}
3 changes: 3 additions & 0 deletions src/EditorConfig.Core/Minimatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class GlobMatcherOptions

// ReSharper restore UnusedAutoPropertyAccessor.Global

/// <summary>
/// A simple glob matcher implementation, if you want a proper one please use a full fletched one from nuget.
/// </summary>
public class GlobMatcher
{
private readonly GlobMatcherOptions myOptions;
Expand Down

0 comments on commit d227b47

Please sign in to comment.