Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress the uppercase html attribute warning if it must have a prefix #1718

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,18 @@ attribute.ValueNode is DothtmlValueBindingNode binding &&
{
var pGroup = groupedProperty.PropertyGroup;
var name = groupedProperty.GroupMemberName;
if (pGroup.Name.EndsWith("Attributes") && name.ToLowerInvariant() != name)
var prefix = attribute.AttributeName.Substring(0, attribute.AttributeName.Length - name.Length);
// If the HTML attribute is used with a prefix such as `Item`, it might be clearer if the first character is uppercased
// e.g. ItemClass reads better than Itemclass
// we supress the warning in such case
var allowFirstCharacterUppercase = prefix.Length > 0 && char.IsLetter(prefix[prefix.Length - 1]);
if (pGroup.Name.EndsWith("Attributes") &&
name.Substring(allowFirstCharacterUppercase ? 1 : 0).ToLowerInvariant() != name.Substring(allowFirstCharacterUppercase ? 1 : 0))
{
// properties with at most two typos
var similarNameProperties =
control.Metadata.AllProperties
.Where(p => StringSimilarity.DamerauLevenshteinDistance(p.Name.ToLowerInvariant(), name.ToLowerInvariant()) <= 2)
.Where(p => StringSimilarity.DamerauLevenshteinDistance(p.Name.ToLowerInvariant(), (prefix + name).ToLowerInvariant()) <= 2)
.Select(p => p.Name)
.ToArray();
var similarPropertyHelp =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,25 @@ @viewModel System.Boolean
Assert.AreEqual("HTML attribute name 'Visble' should not contain uppercase letters. Did you mean Visible, or another DotVVM property?", attribute3.AttributeNameNode.NodeWarnings.Single());
}

[TestMethod]
public void DefaultViewCompiler_NonExistenPropertyWarning_PrefixedGroup()
{
var markup = $@"
@viewModel System.Boolean
<dot:HierarchyRepeater ItemClass=AA ItemIncludeInPage=false />
";
var repeater = ParseSource(markup)
.Content.SelectRecursively(c => c.Content)
.Single(c => c.Metadata.Type == typeof(HierarchyRepeater));

var elementNode = (DothtmlElementNode)repeater.DothtmlNode;
var attribute1 = elementNode.Attributes.Single(a => a.AttributeName == "ItemClass");
var attribute2 = elementNode.Attributes.Single(a => a.AttributeName == "ItemIncludeInPage");

Assert.AreEqual(0, attribute1.AttributeNameNode.NodeWarnings.Count(), attribute1.AttributeNameNode.NodeWarnings.StringJoin(", "));
Assert.AreEqual("HTML attribute name 'IncludeInPage' should not contain uppercase letters. Did you intent to use a DotVVM property instead?", XAssert.Single(attribute2.AttributeNameNode.NodeWarnings));
}

[TestMethod]
public void DefaultViewCompiler_UnsupportedCallSite_ResourceBinding_Warning()
{
Expand Down
Loading