Skip to content

Ruff fix 'formatter' no longer works since 0.1.0 #331

@felix-cw

Description

@felix-cw

This concerns using ruff check --fix to fix code (#296) instead of the new ruff format command.

Since ruff 0.1.0, the functionality no longer works. This is because since astral-sh/ruff#7838, ruff emits to stderr, which jupyterlab_code_formatter interprets as an error.

A potential fix is to add the -e and -q flags to the ruff call, which sets the exit code to 0 and suppresses stderr respectively.

class RuffFixFormatter(CommandLineFormatter):
    @property
    def label(self) -> str:
        return f"Apply ruff Formatter"

    def __init__(self):
        try:
            from ruff.__main__ import find_ruff_bin

            ruff_command = find_ruff_bin()
        except (ImportError, FileNotFoundError):
            ruff_command = "ruff"
        self.command = [ruff_command, "check", "-eq", "--fix-only", "-"]

I edited my installation of jupyterlab_code_formatter to the above and it works, but I haven't had a chance to test more systematically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions