Skip to content

Commit

Permalink
Fix code style (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
maroontress-tomohisa authored Aug 2, 2022
1 parent 4bf3914 commit 830a9b8
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 137 deletions.
26 changes: 12 additions & 14 deletions HtmlBuilder/Maroontress/Html/BaseTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public interface BaseTag<out T>
string Name { get; }

/// <summary>
/// Gets a new <see cref="BaseTag{T}"/> object with the <c>id</c>
/// attribute that has the specified value.
/// Gets a new <see cref="BaseTag{T}"/> object with the <c>id</c> attribute
/// that has the specified value.
/// </summary>
/// <param name="id">
/// The value of the <c>id</c> attribute.
Expand Down Expand Up @@ -57,13 +57,12 @@ public interface BaseTag<out T>
T AddClass(params string[] values);

/// <summary>
/// Gets a new <see cref="BaseTag{T}"/> object with the specified
/// attribute that has the specified value.
/// Gets a new <see cref="BaseTag{T}"/> object with the specified attribute
/// that has the specified value.
/// </summary>
/// <param name="attributes">
/// Tuples of the name and value representing an attribute. If the
/// value of the tuple is <c>null</c>, it represents the empty
/// attribute.
/// Tuples of the name and value representing an attribute. If the value of
/// the tuple is <c>null</c>, it represents the empty attribute.
/// </param>
/// <returns>
/// The new <see cref="BaseTag{T}"/> object.
Expand All @@ -83,15 +82,14 @@ public interface BaseTag<out T>
/// </returns>
/// <remarks>
/// <para>An invocation of this method of the form
/// <c>tag.AddEmptyAttributes(n1, n2)</c> behaves in exactly the same
/// way as the invocation <c>tag.AddAttributes((n1, null), (n2,
/// <c>tag.AddEmptyAttributes(n1, n2)</c> behaves in exactly the same way
/// as the invocation <c>tag.AddAttributes((n1, null), (n2,
/// null))</c>.</para>
///
/// <para>The web browser interprets the value of
/// the empty attribute as the empty string implicitly. So, for
/// example, <c>&lt;input disabled&gt;</c> is equivalent to
/// <c>&lt;input disabled=""&gt;</c>. The former can be generated with
/// <c>AddEmptyAttributes("disabled")</c> or
/// <para>The web browser interprets the value of the empty attribute as
/// the empty string implicitly. So, for example, <c>&lt;input
/// disabled&gt;</c> is equivalent to <c>&lt;input disabled=""&gt;</c>. The
/// former can be generated with <c>AddEmptyAttributes("disabled")</c> or
/// <c>AddAttributes(("disabled", null))</c>, and the latter with
/// <c>AddAttributes(("disabled", ""))</c>.</para>
/// </remarks>
Expand Down
4 changes: 2 additions & 2 deletions HtmlBuilder/Maroontress/Html/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Maroontress.Html;
/// <remarks>
/// <para>
/// Some names of the properties that this class contains violate the naming
/// convention so as to enhance convenience. The property name represents
/// the character reference name itself, which is case sensitive.
/// convention so as to enhance convenience. The property name represents the
/// character reference name itself, which is case sensitive.
/// </para>
/// <para>
/// See <a
Expand Down
11 changes: 5 additions & 6 deletions HtmlBuilder/Maroontress/Html/FormatOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ namespace Maroontress.Html;
public sealed class FormatOptions
{
/// <summary>
/// Represents the default indentation, where the indent width is two
/// and the new line is platform-dependent.
/// Represents the default indentation, where the indent width is two and
/// the new line is platform-dependent.
/// </summary>
public static readonly FormatOptions DefaultIndent = new();

/// <summary>
/// Initializes a new instance of the <see cref="FormatOptions"/>
/// class.
/// Initializes a new instance of the <see cref="FormatOptions"/> class.
/// </summary>
/// <param name="indentWidth">
/// The indent width, which must be greater than or equal to 0, and
/// must not be greater than 8.
/// The indent width, which must be greater than or equal to 0, and must
/// not be greater than eight.
/// </param>
/// <param name="newLine">
/// The string representing a new line. <c>null</c> means <see
Expand Down
27 changes: 12 additions & 15 deletions HtmlBuilder/Maroontress/Html/Impl/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ private static readonly IImmutableSet<char> SpaceCharSet
= ImmutableHashSet.Create(' ', '\x09', '\x0a', '\x0c', '\x0d');

/// <summary>
/// Gets the function that returns the modified <c>TagStruct</c>
/// object.
/// Gets the function that returns the modified <c>TagStruct</c> object.
/// </summary>
/// <param name="values">
/// The values of the <c>class</c> attribute to be added.
/// </param>
/// <returns>
/// The function that takes the original <c>TagStruct</c> and returns
/// the modified <c>TagStruct</c>.
/// The function that takes the original <c>TagStruct</c> and returns the
/// modified <c>TagStruct</c>.
/// </returns>
public static Func<TagStruct, TagStruct> GetAddingClassModifier(
IEnumerable<string> values)
Expand All @@ -70,34 +69,32 @@ public static Func<TagStruct, TagStruct> GetAddingClassModifier(
});

/// <summary>
/// Gets the function that returns the modified <c>TagStruct</c>
/// object.
/// Gets the function that returns the modified <c>TagStruct</c> object.
/// </summary>
/// <param name="values">
/// The values of the <c>class</c> attribute to be replaced.
/// </param>
/// <returns>
/// The function that takes the original <c>TagStruct</c> and returns
/// the modified <c>TagStruct</c>.
/// The function that takes the original <c>TagStruct</c> and returns the
/// modified <c>TagStruct</c>.
/// </returns>
public static Func<TagStruct, TagStruct> GetReplacingClassModifier(
IEnumerable<string> values)
IEnumerable<string> values)
=> GetClassModifier(values, d =>
{
d.Classes = values.ToImmutableList();
return d;
});

/// <summary>
/// Gets the function that returns the modified <c>TagStruct</c>
/// object.
/// Gets the function that returns the modified <c>TagStruct</c> object.
/// </summary>
/// <param name="value">
/// The value of the <c>id</c> attribute to be replaced.
/// </param>
/// <returns>
/// The function that takes the original <c>TagStruct</c> and returns
/// the modified <c>TagStruct</c>.
/// The function that takes the original <c>TagStruct</c> and returns the
/// modified <c>TagStruct</c>.
/// </returns>
public static Func<TagStruct, TagStruct> GetReplacingIdModifier(
string value)
Expand Down Expand Up @@ -200,7 +197,7 @@ private static Func<TagStruct, TagStruct> GetClassModifier(
/// </returns>
private static bool IsValid(string name)
{
if (name.Length == 0)
if (name.Length is 0)
{
return false;
}
Expand All @@ -227,7 +224,7 @@ private static bool IsValid(string name)
/// </returns>
private static bool IsNonEmptyAndContainsNoSpaces(string value)
{
if (value.Length == 0)
if (value.Length is 0)
{
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions HtmlBuilder/Maroontress/Html/Impl/BaseTagImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ public T WithId(string id)
/// Gets a new element with adding the specified attributes.
/// </summary>
/// <param name="attributes">
/// Tuples of the name and value representing an attribute. If the
/// value of the tuple is <c>null</c>, it represents the empty
/// attribute.
/// Tuples of the name and value representing an attribute. If the value of
/// the tuple is <c>null</c>, it represents the empty attribute.
/// </param>
/// <returns>
/// A new element.
Expand Down
11 changes: 6 additions & 5 deletions HtmlBuilder/Maroontress/Html/Impl/CharacterReferenceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Maroontress.Html.Impl;
public sealed class CharacterReferenceImpl : AbstractNode, Node
{
/// <summary>
/// Initializes a new instance of the <see
/// cref="CharacterReferenceImpl"/> class.
/// Initializes a new instance of the <see cref="CharacterReferenceImpl"/>
/// class.
/// </summary>
/// <param name="text">
/// The text representings the character reference of this node.
Expand All @@ -18,8 +18,8 @@ public CharacterReferenceImpl(string text)
}

/// <summary>
/// Initializes a new instance of the <see
/// cref="CharacterReferenceImpl"/> class.
/// Initializes a new instance of the <see cref="CharacterReferenceImpl"/>
/// class.
/// </summary>
/// <param name="codePoint">
/// The code point.
Expand All @@ -40,5 +40,6 @@ public override void Accept(NodeVisitor visitor)
=> visitor.VisitEntity(Text);

/// <inheritdoc/>
protected override NodeKind GetKind() => NodeKind.CharacterReference;
protected override NodeKind GetKind()
=> NodeKind.CharacterReference;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ namespace Maroontress.Html.Impl;
using System.IO;

/// <summary>
/// The default visitor implementaion to write the HTML document into
/// text.
/// The default visitor implementaion to write the HTML document into text.
/// </summary>
public sealed class DefaultTextWriterVisitor : AbstractTextWriterVisitor
{
Expand Down
5 changes: 2 additions & 3 deletions HtmlBuilder/Maroontress/Html/Impl/Elements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ private static readonly IImmutableSet<char> ValidCharSet
= NewValidCharSet();

/// <summary>
/// Gets a new <see cref="TagStruct"/> object that has the specified
/// name.
/// Gets a new <see cref="TagStruct"/> object that has the specified name.
/// </summary>
/// <param name="name">
/// The tag name.
Expand Down Expand Up @@ -54,7 +53,7 @@ public static TagStruct NewTagStruct(string name)
/// </returns>
private static bool IsValid(string name)
{
if (name.Length == 0)
if (name.Length is 0)
{
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions HtmlBuilder/Maroontress/Html/Impl/EmptyTagImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ private EmptyTagImpl(
}

/// <inheritdoc/>
public override string Name => data.Name;
public override string Name
=> data.Name;

/// <inheritdoc/>
public override void Accept(NodeVisitor visitor)
=> visitor.VisitEmptyTag(in data);

/// <inheritdoc/>
protected override NodeKind GetKind() => NodeKind.EmptyTag;
protected override NodeKind GetKind()
=> NodeKind.EmptyTag;

/// <inheritdoc/>
protected override EmptyTag Create(Func<TagStruct, TagStruct> modify)
Expand Down
31 changes: 15 additions & 16 deletions HtmlBuilder/Maroontress/Html/Impl/IndentTextWriterVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#pragma warning disable SA1114 // Parameter list should follow declaration
#pragma warning disable SA1115 // Parameter should follow comma
#pragma warning disable SA1515 // Single-line comment should be preceded by blank line

namespace Maroontress.Html.Impl;

using System;
Expand All @@ -17,8 +21,7 @@ public sealed class IndentTextWriterVisitor : AbstractTextWriterVisitor
</flow>
*/
private static readonly ImmutableHashSet<string> ChildrenArePhrasingSet
= new[]
{
= ImmutableHashSet.Create(
// children: phrasing
"h1",
"h2",
Expand All @@ -38,12 +41,10 @@ private static readonly ImmutableHashSet<string> ChildrenArePhrasingSet
// children: text
"option",
"textarea",
"title",
}.ToImmutableHashSet();
"title");

private static readonly ImmutableHashSet<string> ParentIsPhrasingSet
= new[]
{
= ImmutableHashSet.Create(
"a",
"abbr",
"b",
Expand Down Expand Up @@ -76,8 +77,7 @@ private static readonly ImmutableHashSet<string> ParentIsPhrasingSet
"sup",
"time",
"u",
"var",
}.ToImmutableHashSet();
"var");

private readonly int indentWidth;
private readonly string newLine;
Expand All @@ -87,17 +87,16 @@ private static readonly ImmutableHashSet<string> ParentIsPhrasingSet
private bool needsLineFeed;

/// <summary>
/// Initializes a new instance of the <see
/// cref="IndentTextWriterVisitor"/> class.
/// Initializes a new instance of the <see cref="IndentTextWriterVisitor"/>
/// class.
/// </summary>
/// <param name="writer">
/// The text writer object for this visitor to output.
/// </param>
/// <param name="options">
/// The format options.
/// </param>
public IndentTextWriterVisitor(
TextWriter writer, FormatOptions options)
public IndentTextWriterVisitor(TextWriter writer, FormatOptions options)
: base(writer)
{
indentWidth = options.IndentWidth;
Expand All @@ -120,7 +119,7 @@ protected override void WriteStartTagHook(in TagStruct tag)
}
if (ChildrenArePhrasingSet.Contains(name))
{
if (phraseNest == 0)
if (phraseNest is 0)
{
WriteIndent();
}
Expand Down Expand Up @@ -152,7 +151,7 @@ protected override void WriteEndTagHook(in TagStruct tag)
{
WriteEndTag(tag);
--phraseNest;
if (phraseNest == 0)
if (phraseNest is 0)
{
ForceLineFeed();
}
Expand All @@ -172,7 +171,7 @@ protected override void WriteEndTagHook(in TagStruct tag)
/// <inheritdoc/>
protected override void BeforeEmptyOrText()
{
if (!needsLineFeed && phraseNest == 0)
if (!needsLineFeed && phraseNest is 0)
{
WriteIndent();
}
Expand Down Expand Up @@ -202,7 +201,7 @@ private void ForceLineFeed()
private void WriteIndent()
{
LineFeed();
if (indent == 0)
if (indent is 0)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion HtmlBuilder/Maroontress/Html/Impl/TagImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private TagImpl(TagImpl another, Func<TagStruct, TagStruct> modify)

/// <inheritdoc/>
public Tag Add(IEnumerable<Node> children)
=> new TagImpl(this, d =>
=> new TagImpl(this, d =>
{
d.Children = d.Children.Concat(children)
.ToImmutableList();
Expand Down
3 changes: 2 additions & 1 deletion HtmlBuilder/Maroontress/Html/Impl/TextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public override void Accept(NodeVisitor visitor)
=> visitor.VisitText(Text);

/// <inheritdoc/>
protected override NodeKind GetKind() => NodeKind.Text;
protected override NodeKind GetKind()
=> NodeKind.Text;
}
4 changes: 2 additions & 2 deletions HtmlBuilder/Maroontress/Html/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public interface Node
void Accept(NodeVisitor visitor);

/// <summary>
/// Returns the string representing the current object, formatting it
/// with the spcified <see cref="FormatOptions"/>.
/// Returns the string representing the current object, formatting it with
/// the spcified <see cref="FormatOptions"/>.
/// </summary>
/// <param name="options">
/// The format options.
Expand Down
Loading

0 comments on commit 830a9b8

Please sign in to comment.