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
Collaborator

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 on lines +289 to +290
void cmd_sample_help(void);
/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing a new line.

Comment thread tools/lint/cmd.h
*/
int cmd_ietf_opt(struct yl_opt *yo, const char *cmdline, char ***posv, int *posc);
/**
* @copydoc cmd_add_dep

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing a new line.

Comment thread tools/lint/main_ni.c
Comment on lines +237 to 240

printf(" -t, --ietf\n"
" Enable strict IETF validation rules for the loaded schemas.\n\n");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should be -T I guess.

Comment thread tools/lint/cmd_ietf.c
check_parsed_boilerplate(const char *name, const char *filepath, const char *dsc, const char *contact, const char *org, struct lysp_revision *revs, int type, struct lysp_ext *exts,
struct lysp_feature *feats, struct lysp_ident *idents, struct lysp_node_augment *augments, struct lysp_tpdf *tpdfs, struct lysp_node_grp *grps, struct ly_out *out, int *found_2119)
{
const char *file_name = filepath ? strrchr(filepath, '/') + 1 : name;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If filepath is non-NULL, but containts no '/', strrchr returns NULL, and NULL + 1 is UB. Check if this can ever happen and consider adding some guards/extracting to a function, because the same pattern can be found 3 times in this file.

Comment thread tools/lint/main_ni.c
Comment on lines +846 to +852
} else if (yo.data_out_format) {
for (u = 0; u < yo.schema_modules.count; ++u) {
yo.last_one = (u + 1) == yo.schema_modules.count;
if ((ret = cmd_sample_exec(&ctx, &yo, ((struct lys_module *)yo.schema_modules.objs[u])->name))) {
goto cleanup;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sample should probably use it's own dedicated flag instead of yo.data_out_format, because this flag is also used by format (-f). So it seems to me that if a user passes -f, it will now also print a sample skeleton before processing data.

Comment thread tools/lint/cmd_ietf.c
static void
check_ietf(const struct lys_module *mod, struct ly_out *out)
{
const char *file_name = mod->filepath ? strrchr(mod->filepath, '/') + 1 : mod->name;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above.

Comment thread tools/lint/cmd_ietf.c
Comment on lines +641 to +642
struct lysp_submodule *sub = mod->parsed->includes[i].submodule;
const char *sub_file = sub->filepath ? strrchr(sub->filepath, '/') + 1 : sub->name;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above with the path, also consider moving var definitions to the beginning.

Comment thread tools/lint/cmd_ietf.c
}

LY_LIST_FOR(grps, grp) {
if (grp->dsc == NULL) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some code in this PR uses the short check, i.g. !grp->dsc while others the long one, i.g. grp->dsc = NULL. You should almost always use the first one, since it's libyang idiomatic.

Comment thread tools/lint/cmd_sample.c
print_xml_skeleton(struct ly_out *out, struct lysc_node *root)
{
struct lysc_node *node = root;
int spaces = 2;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider a macro instead of a random magical 2, there are multiple occurrences.

Comment thread tools/lint/main_ni.c
" yanglint [-f { xml | json }] <schema>... <file>...\n"
" Validates the YANG modeled data <file>(s) according to the <schema>(s) optionally\n"
" printing them in the specified format.\n\n"
" yanglint -S { xml | json } <schema>...\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Needs one more space.

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.

2 participants