Closed mwermelinger closed 9 months ago
A construct like try ... except ...
should have the comment on the try
line and not report a violation for that line and the except
line.
I don't know how linters robustly check if the end-of-line comment includes noqa: ...
: are comments accessible from the AST? As a first approach, we could just try something like line.rstrip().endswith("# allowed")
. If that's true, that line isn't further checked.
Of course, how to allow one construct but not another that occurs in the same line, is a different issue :-)
Actually, low effort: just ~5 LOC. The try/except separation was resolved in previous commit.
Forgot to update docs...
Most linters permit creating exceptions when we know it's OK to break a rule. This is typically done by adding a comment like
# noqa: F401
to disable reporting error F401 just for that line. The exact form of the comment depends on the linter.In the case of
allowed
, this would be useful when creating an assignment that contains scaffolding code that students aren't required to understand or change. If the scaffolding code contains non-taught constructs,allowed
will report them. This may confuse students and makes it harder to distinguish violations in teacher's code and student's code.Since
allowed
doesn't have different error codes, a comment like# allowed
should be enough, stating that the constructs in that line are allowed.