summaryrefslogtreecommitdiff
path: root/buildscripts/linter/ruffformatter.py
blob: 545da83c36f83e00994d6899bafa91f7585e1fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Ruff formatter support module."""

from typing import List

from . import base


class RuffFormatter(base.LinterBase):
    """Ruff formatter."""

    def __init__(self):
        """Create a Ruff formatter."""
        super(RuffFormatter, self).__init__("ruff", "0.4.4")

    def get_lint_version_cmd_args(self) -> list[str]:
        """Get the command to run a version check."""
        return ["--version"]

    def get_lint_cmd_args(self, files: list[str]) -> list[str]:
        """Get the command to run a check."""
        if not files:
            return ["format", "--check"]

        files = " ".join(files)
        return ["format", "--check", files]

    def get_fix_cmd_args(self, files: list[str]) -> list[str]:
        """Get the command to run a fix."""
        if not files:
            return ["format"]

        files = " ".join(files)
        return ["format", files]