You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, in a module, the comment is parsed as module headers. So some codemods may insert statement between the comment and the first statement, e.g. EnsureImportPresentCommand .
It's probably not easy to differentiate whether a comment is for the first statement or not to handle it properly when parsing a module. It could be solved by building a helper to post processing the CST by giving some hints (e.g. # lint-ignore comment should be associate with the first statement).
What if we take as headers only comments starting with #! or #\s*@ and also comments that are not followed by a statement?, in other words any of the following cases:
#!/usr/bin/env python# @oncall xxx
# @oncall xxx
# some comments with no immediate statements after# going to the header.# statement commentimportxxx
What if we take as headers only comments starting with #! or #\s*@ and also comments that are not followed by a statement?, in other words any of the following cases:
That sounds like a great idea! We can try implement this and run on existing code to see if it works well.
I don't know that there's a perfect, general, easily-configurable way to handle this. For context, I'm assuming this is trying to solve the special case of Instagram/Fixit#143 in libcst itself, which would be great.
My proposal would be not specialcase @ because of @manual autodeps. Just #! (in the first line) and PEP 263 comments (in the first two lines). Are you already working on a PR for this?
In a local scope, e.g. inside a function, class, if condition.
The comment is associated with the statement correctly.
However, in a module, the comment is parsed as module headers. So some codemods may insert statement between the comment and the first statement, e.g.
EnsureImportPresentCommand
.It's probably not easy to differentiate whether a comment is for the first statement or not to handle it properly when parsing a module. It could be solved by building a helper to post processing the CST by giving some hints (e.g.
# lint-ignore
comment should be associate with the first statement).CC @zsol @thatch
The text was updated successfully, but these errors were encountered: