Skip to content

yanglint: Add commands for sample skeleton generation and IETF validation#2531

Open
HanzlikPetr wants to merge 2 commits into
CESNET:develfrom
HanzlikPetr:new_yanglint_func
Open

yanglint: Add commands for sample skeleton generation and IETF validation#2531
HanzlikPetr wants to merge 2 commits into
CESNET:develfrom
HanzlikPetr:new_yanglint_func

Conversation

@HanzlikPetr

Copy link
Copy Markdown

No description provided.

@Roytak Roytak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly smaller things, good overall.

Comment thread tools/lint/cmd.h
Comment thread tools/lint/cmd.h Outdated
Comment thread tools/lint/main_ni.c Outdated
Comment thread tools/lint/cmd_ietf.c Outdated
Comment thread tools/lint/main_ni.c Outdated
Comment thread tools/lint/cmd_ietf.c Outdated
Comment thread tools/lint/cmd_ietf.c Outdated
Comment thread tools/lint/cmd_ietf.c Outdated
Comment thread tools/lint/cmd_sample.c Outdated
Comment thread tools/lint/main_ni.c Outdated
@HanzlikPetr HanzlikPetr force-pushed the new_yanglint_func branch 4 times, most recently from 8a82540 to 9cb0f82 Compare July 7, 2026 12:11
Comment thread tools/lint/cmd.h
/**
* @copydoc cmd_add_opt
*/
int cmd_sample_opt(struct yl_opt *yo, const char *cmdline, char ***posv, int *posc);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline after this one.

Comment thread tools/lint/cmd_sample.c

/* reset getopt */
optind = 0;
while ((opt = getopt_long(argc, argv, "f:ho:", options, &opt_index)) != -1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the order of the chars the same as in options to easily keep track of them.

Comment thread tools/lint/cmd_sample.c
}

static void
print_xml_nodes(struct ly_out *out, const struct lysc_node *node, int *space_count)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is space_count an out parameter? It should be simpler to just use an int space_count, no need to decrease the count then. Also, missing doxygen.

Comment thread tools/lint/cmd_sample.c
Comment on lines +313 to +320
case LY_TYPE_INT64:
case LY_TYPE_UINT64:
case LY_TYPE_DEC64:
return 1;

default:
return 1;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on what were the specific types selected and rest put into default? Best to just enumerate all the types and not use any default.

Comment thread tools/lint/ietf.c
return 0;
}

if (ly_pattern_compile(NULL, pattern, &pcre2_code) != 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the docs, but I think you do not have to call ly_pattern_compile() if you do not want to reuse the pattern code, just pass NULL to ly_pattern_match().

Comment thread tools/lint/ietf.c
LY_LIST_FOR(data, root) {
is_mandatory = 0;

if (root->flags & LYS_MAND_TRUE) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is enough, the other ones are covered by this, the flag is set for those other cases as well.

Comment thread tools/lint/ietf.c
* @param node_name The string name of the parent node to provide context in the error message.
* @param found_2119 A pointer to an integer flag that tracks if RFC 2119 keywords are used in the module/submodule.
*/
#define CHECK_INNER_DEFS(node_ptr, node_type_str, node_name, found_2119) \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor to a function, macro too complex.

Comment thread tools/lint/ietf.h
* @return 0 on successful execution of the validation pipeline (note: this returns 0 even if IETF compliance warnings/errors were printed to the output).
* @return 1 on fatal execution errors (e.g., module not found, module failed to compile, or memory allocation failure).
*/
int ietf(struct ly_ctx **ctx, struct yl_opt *yo, const char *posv);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use clear names with the local prefix even for function in the internal API. yanglint uses yl prefix, so yl_validate_ietf, for example.

Comment thread tools/lint/main_ni.c
{"json-null", no_argument, NULL, 'J'},
{"debug", required_argument, NULL, 'G'},
{"sample-skeleton", required_argument, NULL, 'S'},
{"ietf", no_argument, NULL, 1000},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use a valid single-char variant for every command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants