Check if comment should be processed for fmt handling. Returns (should_process, is_fmt_off, is_fmt_skip).
(
comment: ProtoComment, leaf: Leaf
)
| 199 | |
| 200 | |
| 201 | def _should_process_fmt_comment( |
| 202 | comment: ProtoComment, leaf: Leaf |
| 203 | ) -> tuple[bool, bool, bool]: |
| 204 | """Check if comment should be processed for fmt handling. |
| 205 | |
| 206 | Returns (should_process, is_fmt_off, is_fmt_skip). |
| 207 | """ |
| 208 | is_fmt_off = contains_fmt_directive(comment.value, FMT_OFF) |
| 209 | is_fmt_skip = contains_fmt_directive(comment.value, FMT_SKIP) |
| 210 | |
| 211 | if not is_fmt_off and not is_fmt_skip: |
| 212 | return False, False, False |
| 213 | |
| 214 | # Invalid use when `# fmt: off` is applied before a closing bracket |
| 215 | if is_fmt_off and leaf.type in CLOSING_BRACKETS: |
| 216 | return False, False, False |
| 217 | |
| 218 | return True, is_fmt_off, is_fmt_skip |
| 219 | |
| 220 | |
| 221 | def _is_valid_standalone_fmt_comment( |
no test coverage detected