Skip to content

Commit

Permalink
validator: Make some length limitations more strict
Browse files Browse the repository at this point in the history
We do not want to enforce too strict style limits, however, some
elements such as names and summary will universally regress usability of
the component when displayed in pretty much all layouts.

So, if people go excessively over reasonable limits, we will now emit a
warning, as that will likely have been unintentional anyway.
  • Loading branch information
ximion committed Jan 18, 2024
1 parent e7ba0bc commit 5e88dad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/as-validator-issue-tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
N_("The component is missing a name (<name/> tag).")
},

{ "component-name-too-long",
AS_ISSUE_SEVERITY_WARNING,
N_("The name of this component is excessively long and can likely not be displayed properly in most layouts.")
},

{ "component-summary-missing",
AS_ISSUE_SEVERITY_ERROR,
N_("The component is missing a summary (<summary/> tag).")
Expand Down Expand Up @@ -505,6 +510,11 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
N_("The summary text does not start with a capitalized word, project name or number.")
},

{ "summary-too-long",
AS_ISSUE_SEVERITY_WARNING,
N_("The summary text is very long, and will likely not be displayed properly everywhere.")
},

{ "icon-stock-cached-has-url",
AS_ISSUE_SEVERITY_ERROR,
/* TRANSLATORS: Please do not translate AppStream tag and property names (in backticks). */
Expand Down Expand Up @@ -755,7 +765,7 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
},

{ "screenshot-caption-too-long",
AS_ISSUE_SEVERITY_PEDANTIC,
AS_ISSUE_SEVERITY_INFO,
N_("The screenshot caption is too long (should be <= 100 characters)"),
},

Expand Down
16 changes: 16 additions & 0 deletions src/as-validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2921,13 +2921,22 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm
} else if (g_strcmp0 (node_name, "source_pkgname") == 0) {
as_validator_check_appear_once (validator, iter, found_tags, FALSE);
} else if (g_strcmp0 (node_name, "name") == 0) {
g_autofree gchar *lang = as_xml_get_prop_value (iter, "lang");

as_validator_check_appear_once (validator, iter, found_tags, TRUE);
if (g_str_has_suffix (node_content, "."))
as_validator_add_issue (validator,
iter,
"name-has-dot-suffix",
node_content);

if (lang == NULL && strlen (node_content) > 40) {
as_validator_add_issue (validator,
iter,
"component-name-too-long",
node_content);
}

} else if (g_strcmp0 (node_name, "summary") == 0) {
g_autofree gchar *lang = NULL;
const gchar *summary = node_content;
Expand Down Expand Up @@ -2962,6 +2971,13 @@ as_validator_validate_component_node (AsValidator *validator, AsContext *ctx, xm
"summary-first-word-not-capitalized",
NULL);

if (lang == NULL && strlen (summary) > 90) {
as_validator_add_issue (validator,
iter,
"summary-too-long",
summary);
}

} else if (g_strcmp0 (node_name, "description") == 0) {
as_validator_check_appear_once (validator, iter, found_tags, TRUE);
as_validator_check_description_tag (validator, iter, mode, TRUE);
Expand Down

0 comments on commit 5e88dad

Please sign in to comment.