yanglint: Add commands for sample skeleton generation and IETF validation#2531
yanglint: Add commands for sample skeleton generation and IETF validation#2531HanzlikPetr wants to merge 2 commits into
Conversation
Roytak
left a comment
There was a problem hiding this comment.
Mostly smaller things, good overall.
| void cmd_sample_help(void); | ||
| /** |
| */ | ||
| int cmd_ietf_opt(struct yl_opt *yo, const char *cmdline, char ***posv, int *posc); | ||
| /** | ||
| * @copydoc cmd_add_dep |
|
|
||
| printf(" -t, --ietf\n" | ||
| " Enable strict IETF validation rules for the loaded schemas.\n\n"); | ||
| } |
| 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; |
There was a problem hiding this comment.
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.
| } 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; | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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; |
| struct lysp_submodule *sub = mod->parsed->includes[i].submodule; | ||
| const char *sub_file = sub->filepath ? strrchr(sub->filepath, '/') + 1 : sub->name; |
There was a problem hiding this comment.
Same as above with the path, also consider moving var definitions to the beginning.
| } | ||
|
|
||
| LY_LIST_FOR(grps, grp) { | ||
| if (grp->dsc == NULL) { |
There was a problem hiding this comment.
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.
| print_xml_skeleton(struct ly_out *out, struct lysc_node *root) | ||
| { | ||
| struct lysc_node *node = root; | ||
| int spaces = 2; |
There was a problem hiding this comment.
Consider a macro instead of a random magical 2, there are multiple occurrences.
| " 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" |
No description provided.