build_output.LintOutputBuilder
convert.build_output.LintOutputBuilder(*args, max_line_length=None, **kwargs)Build a lint-friendly Python view.
Methods
| Name | Description |
|---|---|
| add_noqa | Add noqa suppressions to a line for specified error codes. |
| add_noqa_for_first_code_line | Add appropriate noqa suppressions for the first code line in a chunk. |
| append_placeholder | Append placeholder if preserving line count. |
| build | Populate self.py_lines for linting, guided by block metadata. |
| handle_block_boundary_row | Handle opening/closing fence rows for a Python block. |
| handle_code_row | Handle a non-boundary, non-option row inside a Python block. |
| handle_option_row | Handle a row that belongs to the chunk-options region. |
| make_row_to_block | Build a row-index to block mapping for fast lookups. |
add_noqa
convert.build_output.LintOutputBuilder.add_noqa(line, suppress)Add noqa suppressions to a line for specified error codes.
If the line is within the allowed max line length, E501 (line too long) is also suppressed, since the added noqa comment may push it over the limit.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| line | str | The line of code. | required |
| suppress | list[str] | The error code(s) to suppress (e.g. [“E302”]). | required |
Returns
| Name | Type | Description |
|---|---|---|
| str | The input line with ‘noqa’ suppressions appended as a comment. |
add_noqa_for_first_code_line
convert.build_output.LintOutputBuilder.add_noqa_for_first_code_line(
line,
stripped,
)Add appropriate noqa suppressions for the first code line in a chunk.
Always suppresses E305 (expected 2 blank lines after top-level statement). Also suppresses E302 if the line starts a function, class, or decorator.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| line | str | The line to add noqa comments to. | required |
| stripped | str | The line with leading whitespace removed. | required |
Returns
| Name | Type | Description |
|---|---|---|
| str | The line with appropriate noqa suppressions appended. |
append_placeholder
convert.build_output.LintOutputBuilder.append_placeholder()Append placeholder if preserving line count.
build
convert.build_output.LintOutputBuilder.build(src_bytes)Populate self.py_lines for linting, guided by block metadata.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| src_bytes | bytes | UTF-8 encoded document source. | required |
Returns
| Name | Type | Description |
|---|---|---|
| py_lines | list[str] | Lines for Python file. |
handle_block_boundary_row
convert.build_output.LintOutputBuilder.handle_block_boundary_row(row, block)Handle opening/closing fence rows for a Python block.
If line count preservation is enabled, these rows are replaced with placeholders so that the linter only sees Python code and comments.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| row | int | Current row index. | required |
| block | dict | Metadata for the enclosing Python block. | required |
Returns
| Name | Type | Description |
|---|---|---|
| bool | True if this row has been fully handled and the caller should skip further processing; False otherwise. |
handle_code_row
convert.build_output.LintOutputBuilder.handle_code_row(
row,
line,
stripped,
block,
*,
should_process,
)Handle a non-boundary, non-option row inside a Python block.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| row | int | Zero-based row index. | required |
| line | str | Original line text. | required |
| stripped | str | Line text with leading whitespace removed. | required |
| block | dict | Metadata for the enclosing Python block. | required |
| should_process | bool | Whether this block is being linted. | required |
handle_option_row
convert.build_output.LintOutputBuilder.handle_option_row(
line,
stripped,
*,
should_process,
)Handle a row that belongs to the chunk-options region.
Depending on the content and whether the block is linted, this either preserves the row as-is, replaces it with a placeholder, or strips Quarto-specific annotation syntax.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| line | str | Original line text. | required |
| stripped | str | Line text with leading whitespace removed. | required |
| should_process | bool | Whether the surrounding block is subject to linting. | required |
make_row_to_block
convert.build_output.LintOutputBuilder.make_row_to_block()Build a row-index to block mapping for fast lookups.
Returns
| Name | Type | Description |
|---|---|---|
| dict of int to dict | A mapping from row index to the metadata dictionary for the block that covers that row. |