Skip to content

Support ruff as a formatter #296

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

Closed
felix-cw opened this issue Mar 8, 2023 · 2 comments
Closed

Support ruff as a formatter #296

felix-cw opened this issue Mar 8, 2023 · 2 comments

Comments

@felix-cw
Copy link
Contributor

felix-cw commented Mar 8, 2023

Ruff is a linter for python that also has the ability to fix the lints automatically.
I'm using it as an alternative to isort.

I think it would be good to add it as a supported option in this package.

Here is the code I used to add it as a custom formatter:

from jupyterlab_code_formatter.formatters import (
    SERVER_FORMATTERS,
    CommandLineFormatter,
)


class RuffFixFormatter(CommandLineFormatter):
    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", "--fix-only", "-", "--select=COM,I"]


SERVER_FORMATTERS["ruff_isort"] = RuffFixFormatter()

I'm not sure how to pass args to a custom function via the normal jupyter lab config, so I hardcoded my rule selection argument --select=COM,I.

@jbusecke
Copy link

jbusecke commented Mar 8, 2023

+1 👍

@ryantam626
Copy link
Collaborator

Forgot to report back, 2.0.0/2.1.0+ would have ruff support, thanks again for your PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants