carpentries / styles

Styles for The Carpentries lessons. No README to avoid merge conflicts with lessons. Demo 👇
https://carpentries.github.io/lesson-example
Other
84 stars 94 forks source link

Print error in lesson_check.py if code block has no class specifier #550

Closed tomgreen66 closed 3 years ago

tomgreen66 commented 3 years ago

So I think we need a:

            if cls is None:
                print(self.filename, self.get_loc(node))

That's a good idea with one comment: we need to make sure it's clear that this is an error message and to either halt the execution of lesson-check or skip to the next file when this happens because we can't produce an AST of (and, therefore, analyze) the current file. Would you like to submit a PR with this fix?

Originally posted by @maxim-belkin in https://github.com/carpentries/styles/issues/543#issuecomment-780047919

tomgreen66 commented 3 years ago

Have maybe improved upon suggestion to add another check and just include the check for cls is None in the self.reporter.check and in the process make it cls is not None. See:

ARCCA/styles@661de87e4a8ce6c962180420c11922f07e476384

zkamvar commented 3 years ago

The solution does work, but this allows the AST to be malformed because we expect that all code blocks should have a class associated.

I think the deeper problem is HOW the AST is malformed, because it could be via user error or, as we saw in #543, a parser error. Because None is an unexpected condition which could be caused by either user or parser, it would not be a good idea to throw an error, because that would end up frustrating users if it's the fault of the parser and the lesson is otherwise fine.