mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
530 stars 343 forks source link

pyang --lint error on canonical ordering when it shouldn't be #799

Closed rpchoang closed 2 years ago

rpchoang commented 2 years ago

Hello,

I was trying to use pyang to validate my yang files are up to standard with the RFCs. I'm getting these errors saying that certain statements aren't in order when they do follow the RFC guidelines. The RFC I'm referring to: RFC 6020 section 12: https://datatracker.ietf.org/doc/html/rfc6020#section-12

For an example, a leaf node I had a config statement before type and it was giving me an error saying this is not in canonical order. However according to the RFC section 12 where it mentions leaf statements it says that these two can be placed in any order. Following RFC ABNF canonical order, it still returns an error.

Is there an update planned for this? Thanks!

mbj4668 commented 2 years ago

type and config can be placed in any order, but the canonical order is the strict order defined by the ABNF grammar, i.e., type before config.

rpchoang commented 2 years ago

Hello, it's stated in RFC 6020 "Within the ABNF grammar, unordered statements are marked with comments." and such unordered statements can be seen in the example listed above, while other ordered statements can be seen without the comments.

And as there is no mention of canonical in RFC 5234, canonical order is the order that the different statements are listed on RFC 6020, even the ones listed with the comments mentioning it can be put in any order? The only mention of strict ordering in RFC 5234 are things in parenthesis, which this case is not applicable to this situation.

Thanks!

mbj4668 commented 2 years ago

"canonical order" is not an ABNF term, it is a YANG term. Section 12 of 6020 says:

  In YANG, almost all statements are unordered.  The ABNF grammar
  [RFC5234] defines the canonical order.
rpchoang commented 2 years ago

Ah so the ABNF just defines the format that YANG RFC 6020 is showing us. And even though it says that these statements may appear in any order, the recommended canonical order means the exact order that these statements appear in RFC 6020 section 12?

leaf-stmt = leaf-keyword sep identifier-arg-str optsep "{" stmtsep ;; these stmts can appear in any order [when-stmt stmtsep] (if-feature-stmt stmtsep) type-stmt stmtsep [units-stmt stmtsep] (must-stmt stmtsep) [default-stmt stmtsep] [config-stmt stmtsep] [mandatory-stmt stmtsep] [status-stmt stmtsep] [description-stmt stmtsep] [reference-stmt stmtsep] "}"

mbj4668 commented 2 years ago

Correct.