Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruff_python_formatter: implement "dynamic" line width mode for docstring code formatting #9098

Merged
merged 7 commits into from
Dec 12, 2023

Commits on Dec 12, 2023

  1. ruff_python_formatter: tweak docstring-code-line-width to support dyn…

    …amic
    
    This makes the internal docstring code line width setting have
    a "mixed type." That is, it can either be a numeric value indicating
    a fixed line width, or it can be the string "dynamic" indicating that
    the line width should respect the overall line width of the surrounding
    code.
    BurntSushi committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    f1a4bc4 View commit details
    Browse the repository at this point in the history
  2. ruff_python_formatter: add 'indent_level' to PyFormatContext

    This lets us track the indent level as state during formatting.
    
    We'll use this to compute the line width for docstring code
    reformatting when "dynamic" mode is enabled.
    BurntSushi committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    c78985b View commit details
    Browse the repository at this point in the history
  3. ruff_python_formatter: add support for docstring code "dynamic" mode

    This computes the line width to use on the nested call to the
    formatter based on the current indent level, indent width and
    configured global setting.
    
    Ref #8855
    BurntSushi committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    41fe17b View commit details
    Browse the repository at this point in the history
  4. ruff_python_formatter: add new set of tests to docstring code snapshot

    This just uses the standard default configuration. We'll add the snapshot
    itself in the next commit and then update the test configuration to use
    the new "dynamic" setting so that we can scrutinize the specific changes.
    BurntSushi committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    9c75aa6 View commit details
    Browse the repository at this point in the history
  5. ruff_python_formatter: update snapshot

    This updates the snapshot with the added configuration from the
    previous commit. This should match the default test configuration,
    so there shouldn't be anything "interesting" in this commit.
    BurntSushi committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    9e95e84 View commit details
    Browse the repository at this point in the history
  6. ruff_python_formatter: run existing tests with "dynamic" setting

    This tests the "dynamic" line width mode. As with the fixed line width
    setting, not much changes here since most of our code examples use very
    short lines.
    
    In a subsequent commit, we'll add more tests specifically targeted at
    line width.
    BurntSushi committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    5c53c91 View commit details
    Browse the repository at this point in the history
  7. ruff_python_formatter: add 'dynamic' mode tests

    This commit adds a few tests specifically for checking the 'dynamic'
    line width mode for formatting docstring code examples.
    BurntSushi committed Dec 12, 2023
    Configuration menu
    Copy the full SHA
    e92a477 View commit details
    Browse the repository at this point in the history