Skip to content

Settings#

Top-level#

builtins#

システムの組み込みコマンドに加えて、定義された参照として扱う組み込みコマンドのリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff]
builtins = ["_"]
builtins = ["_"]

cache-dir#

キャッシュディレクトリへのパス。

デフォルトでは、Ruff は現在のプロジェクトルートの.ruff_cacheディレクトリにキャッシュ結果を保存します。

ただし、Ruff は環境変数RUFF_CACHE_DIRも尊重します。これはデフォルトよりも優先されます。

この設定は、環境変数RUFF_CACHE_DIRが設定されている場合でも上書きされます。

Default value: .ruff_cache

Type: str

Example usage:

[tool.ruff]
cache-dir = "~/.cache/ruff"
cache-dir = "~/.cache/ruff"

exclude#

書式設定とリンティングから除外するファイルパターンのリスト。

除外はグローバルに基づいており、次のいずれかになります。:

  • .mypy_cache(ツリー内の.mypy_cacheという名前のディレクトリを除外する)、foo.py(foo.pyという名前のファイルを除外する)、foo_*.py(foo_*.pyに一致するファイルを除外する)のような単一パスパターン。
  • directory/foo.py(特定のファイルを除外するため)やdirectory/*.py(directory内のすべての Python ファイルを除外するため)のような相対パターン。これらのパスはプロジェクトルート(例えば、pyproject.tomlを含むディレクトリ)からの相対パスであることに注意してください。

glob 構文の詳細については、globset documentationを参照してください。

通常、除外されたパスを変更するには、extend-excludeを使用することに注意してください。

Default value: [".bzr", ".direnv", ".eggs", ".git", ".git-rewrite", ".hg", ".mypy_cache", ".nox", ".pants.d", ".pytype", ".ruff_cache", ".svn", ".tox", ".venv", "__pypackages__", "_build", "buck-out", "dist", "node_modules", "venv"]

Type: list[str]

Example usage:

[tool.ruff]
exclude = [".venv"]
exclude = [".venv"]

extend#

この構成にマージするローカルのpyproject.tomlファイルへのパス。ユーザーのホームディレクトリと環境変数が展開されます。

現在のpyproject.tomlファイルを解決するために、Ruff はまずこの基本構成ファイルを解決し、次に現在の構成ファイルで定義されている任意のプロパティにマージします。

Default value: null

Type: str

Example usage:

[tool.ruff]
# Extend the `pyproject.toml` file in the parent directory.
extend = "../pyproject.toml"
# But use a different line length.
line-length = 100
# Extend the `pyproject.toml` file in the parent directory.
extend = "../pyproject.toml"
# But use a different line length.
line-length = 100

extend-exclude#

excludeで指定されたものに加えて、フォーマットとリンティングから除外するファイルパターンのリスト。

除外はグローバルに基づいており、次のいずれかになります。:

  • .mypy_cache(ツリー内の.mypy_cacheという名前のディレクトリを除外する)、foo.py(foo.pyという名前のファイルを除外する)、foo_*.py(foo_*.pyに一致するファイルを除外する)のような単一パスパターン。
  • directory/foo.py(特定のファイルを除外するため)やdirectory/*.py(directory内の Python ファイルを除外するため)のような相対パターン。これらのパスはプロジェクトのルート(例えば、pyproject.tomlを含むディレクトリ)からの相対パスであることに注意してください。

glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff]
# In addition to the standard set of exclusions, omit all tests, plus a specific file.
extend-exclude = ["tests", "src/bad.py"]
# In addition to the standard set of exclusions, omit all tests, plus a specific file.
extend-exclude = ["tests", "src/bad.py"]

extend-include#

includeで指定されたものに加えて、リンティング時に含めるファイルパターンのリスト。

包含は glob に基づいており、.pyw拡張子を持つ任意のファイルを含めるには、*.pywのような単一パスパターンである必要があります。

glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff]
# In addition to the standard set of inclusions, include `.pyw` files.
extend-include = ["*.pyw"]
# In addition to the standard set of inclusions, include `.pyw` files.
extend-include = ["*.pyw"]

fix#

ruffの実行時にデフォルトで修正動作を有効にします(--fixおよび--no-fixコマンドラインフラグで上書きされます)。

--unsafe-fixesが指定されていない限り、自動修正のみが含まれます。

Default value: false

Type: bool

Example usage:

[tool.ruff]
fix = true
fix = true

fix-only#

fixと似ていますが、残りの違反の報告を無効にします。fixを意味します。

Default value: false

Type: bool

Example usage:

[tool.ruff]
fix-only = true
fix-only = true

force-exclude#

明示的に Ruff に渡されたパスに対しても、excludeextend-excludeパターンを強制するかどうか。通常、Ruff は、通常は除外されるパスであっても、直接渡されたパスを無視します。force-exclude=trueを設定すると、Ruff はこれらの除外を明確に尊重します。

これは、pre-commitの場合に便利です。このプラグインは、変更されたすべてのファイルを明示的にruff-pre-commitプラグインに渡します。Ruff の独自の設定で除外としてマークされているかどうかは関係ありません。

Default value: false

Type: bool

Example usage:

[tool.ruff]
force-exclude = true
force-exclude = true

include#

リンティング時に含めるファイルパターンのリスト。

包含は glob に基づいており、*.pywのような単一パスパターンである必要があります。これは、.pyw拡張子を持つファイルを含めるためです。pyproject.tomlは設定のためではなく、例えば[project]がスキーマに一致するかどうかを調べるためにここに含まれています。

ノートブックファイル(.ipynb拡張子)は、Ruff 0.6.0+にデフォルトで含まれています。

glob 構文の詳細については、globset documentationを参照してください。

Default value: ["*.py", "*.pyi", "*.ipynb", "**/pyproject.toml"]

Type: list[str]

Example usage:

[tool.ruff]
include = ["*.py"]
include = ["*.py"]

indent-width#

インデントレベル(タブ)ごとのスペースの数。

タブの表示幅を決定するために(E501のような)長い行の違反を強制するときに、フォーマッタによって使用されます。

このオプションは、ソフトタブ(indent-style = space)を使用するときにフォーマッタが挿入するスペースの数を変更します。

PEP 8 recommends using 4 spaces per indentation level.

PEP 8 では、indentation levelごとに 4 つのスペースを使用することを推奨しています。

Default value: 4

Type: int

Example usage:

[tool.ruff]
indent-width = 2
indent-width = 2

line-length#

長い行の違反(E501など)を強制するときに使用する行の長さで、isortとフォーマッタが行をラップするのに適した場所です。

長さは、東アジアの文字または絵文字を含む行を除き、1 行あたりの文字数によって決まります。

これらの行では、各文字のunicode widthが加算されて長さが決定されます。

値は0より大きく、320以下でなければなりません。

注意:フォーマッタはline-length内に収まるように行を整形しようとしますが、これは厳密な上限ではなく、整形された行はline-lengthを超える可能性があります。

E501とフォーマッタに異なる長さを設定するには、pycodestyle.max-line-lengthを参照してください。

Default value: 88

Type: int

Example usage:

[tool.ruff]
# Allow lines to be as long as 120.
line-length = 120
# Allow lines to be as long as 120.
line-length = 120

namespace-packages#

指定されたディレクトリを名前空間パッケージとしてマークします。モジュールを解決するために、Ruff はこれらのディレクトリとそのすべてのサブディレクトリを__init__.pyファイルが含まれているかのように扱います。

Default value: []

Type: list[str]

Example usage:

[tool.ruff]
namespace-packages = ["airflow/providers"]
namespace-packages = ["airflow/providers"]

output-format#

違反メッセージをフォーマットするスタイル:"full"(デフォルト)(ソースを表示)、"concise""grouped"(ファイルごとにメッセージをグループ化)、"json"(機械可読)、"junit"(機械可読 XML)、"GitHub"(GitHub Actions アノテーション)、"GitLab"(GitLab CI コード品質レポート)、"pyint"(Pyint テキスト形式)、または"azure"(Azure Pipeline ロギングコマンド)。

Default value: "full"

Type: "full" | "concise" | "grouped" | "json" | "junit" | "github" | "gitlab" | "pylint" | "azure"

Example usage:

[tool.ruff]
# Group violations by containing file.
output-format = "grouped"
# Group violations by containing file.
output-format = "grouped"

preview#

プレビュー・モードを使用可能にするかどうか。プレビュー・モードが使用可能な場合、Ruff は不安定なルール、修正およびフォーマットを使用します。

Default value: false

Type: bool

Example usage:

[tool.ruff]
# Enable preview features.
preview = true
# Enable preview features.
preview = true

required-version#

実行時に適用するために、Ruff のバージョンに要件を適用します。

Ruff のバージョンが要件を満たしていない場合、Ruff はエラーで終了します。

たとえば、pyproject.tomlファイルを使用して、多くの環境にわたって結果を統合する場合に便利です。

==0.3.1>=0.3.1のようなPEP 440指定子を受け入れます。

Default value: null

Type: str

Example usage:

[tool.ruff]
required-version = ">=0.0.193"
required-version = ">=0.0.193"

respect-gitignore#

.ignore.gitignore.git/info/exclude、およびグローバルなgitignoreファイルによって無視されるファイルを自動的に除外するかどうか。

デフォルトで有効になっています。

Default value: true

Type: bool

Example usage:

[tool.ruff]
respect-gitignore = false
respect-gitignore = false

show-fixes#

修正されたすべてのリント違反の列挙を表示するかどうか(--show-fixesコマンドラインフラグで上書きされます)。

Default value: false

Type: bool

Example usage:

[tool.ruff]
# Enumerate all fixed violations.
show-fixes = true
# Enumerate all fixed violations.
show-fixes = true

src#

ファーストパーティとサードパーティのインポートを解決するときに考慮するディレクトリ。

省略した場合、srcディレクトリには通常、次の両方がデフォルトで含まれます。:

  1. 最も近いpyproject.tomlruff.toml、または.ruff.tomlファイルを含むディレクトリ("プロジェクトルート")。
  2. プロジェクトルートの"src"サブディレクトリ。

これらの既定により、UV はフラットレイアウトと「src」レイアウトの両方をサポートします。(設定ファイルが明示的に提供されている場合(たとえば、--configコマンドラインフラグを使用して)、現在の作業ディレクトリがプロジェクトのルートと見なされます)。

例として、次のような代替プロジェクト構造を考えてみましょう。:

my_project
├── pyproject.toml
└── lib
    └── my_package
        ├── __init__.py
        ├── foo.py
        └── bar.py

この場合、インポートを解決するときにmy_package.fooがファーストパーティと見なされるように、./libディレクトリをsrcオプションに含める必要があります(たとえば、src = ["lib"])。

このフィールドは glob をサポートします。例えば、python_modulesディレクトリに一連の Python パッケージがある場合、src = ["python_modules/*"]を展開すると、そのディレクトリ内のすべてのパッケージが組み込まれます。ユーザーのホームディレクトリと環境変数も展開されます。

Default value: [".", "src"]

Type: list[str]

Example usage:

[tool.ruff]
# Allow imports relative to the "src" and "test" directories.
src = ["src", "test"]
# Allow imports relative to the "src" and "test" directories.
src = ["src", "test"]

target-version#

型アノテーションの書き換えなど、自動コードアップグレードを検討する場合にターゲットとする Python の最小バージョン。Ruff は、特定のバージョンでは利用できない機能を使用して変更を提案することはありません。

たとえば、Python>=3.10 または==3.10 のサポートを表すには、target-version = "py310"と指定します。

すでにpyproject.tomlファイルを使用している場合は、代わりにproject.requires-pythonをお勧めします。これは、Python パッケージング標準に基づいており、他のツールによって尊重されるためです。たとえば、Ruff は次のものをtarget-version="py38"と同じものとして扱います。:

[project]
requires-python = ">=3.8"

If both are specified, target-version takes precedence overrequires-python.

両方を指定した場合、target-versionrequires-pythonより優先されます。

Default value: "py38"

Type: "py37" | "py38" | "py39" | "py310" | "py311" | "py312"

Example usage:

[tool.ruff]
# Always generate Python 3.7-compatible code.
target-version = "py37"
# Always generate Python 3.7-compatible code.
target-version = "py37"

unsafe-fixes#

安全でない修正の適用を有効にします。

除外すると、安全でない修正が利用可能になったときにヒントが表示されます。

false に設定すると、ヒントは非表示になります。

Default value: null

Type: bool

Example usage:

[tool.ruff]
unsafe-fixes = true
unsafe-fixes = true

format#

Ruff がコードをフォーマットする方法を設定します。

docstring-code-format#

docstring 内のコードスニペットをフォーマットするかどうか。

これを有効にすると、docstring 内の Python コード例は自動的に再フォーマットされます。

たとえば、これを有効にすると、次のコードが実行されます。:

def f(x):
    """
    Something about `f`. And an example in doctest format:

    >>> f(  x  )

    Markdown is also supported:

    ```py
    f(  x  )
    ```

    As are reStructuredText literal blocks::

        f(  x  )

    And reStructuredText code blocks:

    .. code-block:: python

        f(  x  )
    """
    pass

次のように再フォーマットされます(残りのオプションがデフォルトに設定されていると仮定します)。:

def f(x):
    """
    Something about `f`. And an example in doctest format:

    >>> f(x)

    Markdown is also supported:

    ```py
    f(x)
    ```

    As are reStructuredText literal blocks::

        f(x)

    And reStructuredText code blocks:

    .. code-block:: python

        f(x)
    """
    pass

docstring 内のコード・スニペットに無効な Python コードが含まれている場合、またはフォーマッターが無効な Python コードを書き込む可能性がある場合には、そのコード例はフォーマッターによって無視され、そのまま保持されます。

現在、doctest、Markdown、reStructuredText リテラルブロック、reStructuredText コードブロックはすべてサポートされており、自動的に認識されます。Markdown および reStructuredText リテラルブロック内のラベルのないフェンスで囲まれたコードブロックの場合、内容は Python であると想定され、再フォーマットされます。他のフォーマットと同様に、内容が有効でない場合

Python の場合、ブロックは自動的に変更されません。

Default value: false

Type: bool

Example usage:

[tool.ruff.format]
# Enable reformatting of code snippets in docstrings.
docstring-code-format = true
[format]
# Enable reformatting of code snippets in docstrings.
docstring-code-format = true

docstring-code-line-length#

docstring 内のコードスニペットをフォーマットするときに使用する行の長さを設定します。

これは、docstring-code-format設定が有効になっている場合にのみ有効です。

この設定のデフォルト値は"dynamic"です。これにより、docstring 内の再フォーマットされたコード例が、周囲の Python コードに使用されるグローバルな行長設定に準拠することが保証されます。この設定のポイントは、コード例を再フォーマットするときに docstring のインデントを考慮することです。

または、固定整数に設定することもできます。これにより、docstring 内のすべての再フォーマットされたコード例に同じ行長制限が適用されます。固定整数に設定すると、docstring のインデントは考慮されません。つまり、再フォーマットされたコード例の行が、グローバルに設定された行長制限を超える可能性があります。

たとえば、これが20に設定されていて、docstring-code-formatが有効になっている場合、次のコードが表示されます。:

def f(x):
    '''
    Something about `f`. And an example:

    .. code-block:: python

        foo, bar, quux = this_is_a_long_line(lion, hippo, lemur, bear)
    '''
    pass

次のように再フォーマットされます(残りのオプションがデフォルトに設定されていると仮定します):

def f(x):
    """
    Something about `f`. And an example:

    .. code-block:: python

        (
            foo,
            bar,
            quux,
        ) = this_is_a_long_line(
            lion,
            hippo,
            lemur,
            bear,
        )
    """
    pass

Default value: "dynamic"

Type: int | "dynamic"

Example usage:

[tool.ruff.format]
# Format all docstring code snippets with a line length of 60.
docstring-code-line-length = 60
[format]
# Format all docstring code snippets with a line length of 60.
docstring-code-line-length = 60

exclude#

グローバルに除外されたファイルに加えて、フォーマットから除外するファイルパターンのリスト(excludeおよびextend-excludeを参照)。

除外はグローバルに基づいており、次のいずれかになります。:

  • .mypy_cache(ツリー内の.mypy_cacheという名前のディレクトリを除外する)、foo.py(foo.pyという名前のファイルを除外する)、foo_*.py(foo_*.pyに一致するファイルを除外する)のような単一パスパターン。
  • 相対パターン:directory/foo.py(その特定のファイルを除外する)またはdirectory/*.py( これらのパスはプロジェクトのルート(例えば、pyproject.tomlを含むディレクトリ)からの相対パスであることに注意してください。

glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.format]
exclude = ["generated"]
[format]
exclude = ["generated"]

indent-style#

インデントにスペースまたはタブを使用するかどうか。

indent-style = "space" (default):

def f():
    print("Hello") #  Spaces indent the `print` statement.

indent-style = "tab":

indent-style="tab"::

def f():
    print("Hello") #  A tab `\t` indents the `print` statement.

PEP 8 では、indentationにスペースを使用することを推奨しています。

私たちはアクセシビリティを重視しています。アクセシビリティ用のタブが必要ない場合は、タブを使用することはお勧めしません。

インデントごとのスペースの数とタブ幅を設定するには、indent-widthを参照してください。

Default value: space

Type: "space" | "tab"

Example usage:

[tool.ruff.format]
# Use tabs instead of 4 space indentation.
indent-style = "tab"
[format]
# Use tabs instead of 4 space indentation.
indent-style = "tab"

line-ending#

Ruff が行末で使用する文字。

  • auto: 改行スタイルはファイルごとに自動的に検出されます。行末が混在しているファイルは、最初に検出された行末に変換されます。行末が含まれていないファイルのデフォルトは\nです。
  • lf: 行末は\nに変換されます。UNIX のデフォルトの行末です。
  • cr-lf: 行末は\r\nに変換されます。Windows のデフォルトの行末です。
  • native: 行末は UNIX では\nに、Windows では\r\nに変換されます。

Default value: auto

Type: "auto" | "lf" | "cr-lf" | "native"

Example usage:

[tool.ruff.format]
# Use `\n` line endings for all files
line-ending = "lf"
[format]
# Use `\n` line endings for all files
line-ending = "lf"

preview#

不安定なプレビュースタイルの書式設定を有効にするかどうかを指定します。

Default value: false

Type: bool

Example usage:

[tool.ruff.format]
# Enable preview style formatting.
preview = true
[format]
# Enable preview style formatting.
preview = true

quote-style#

文字列の優先引用符文字を構成します。推奨されるオプションは次のとおりです。

  • double(デフォルト): 二重引用符"を使用します
  • single: 単一引用符'を使用します

PEP 8およびPEP 257に従って

Ruff は、quote-style = "single"を使用している場合でも、トリプルクォートされた文字列と docstring に対して二重引用符を好みます。

Ruff は、設定された引用符を使用することで、文字列内の引用符文字をエスケープする必要がなくなる場合、その使用から逸脱します。:

a = "a string without any quotes"
b = "It's monday morning"

quote-style = "single"を使用すると、Ruff はaに割り当てられた文字列の引用符を単一引用符に変更します。

しかし、Ruff はbに割り当てられた文字列に二重引用符を使用します。これは、単一引用符を使用すると'をエスケープする必要があり、コードが読みにくくなるためです:'It\'s monday morning'

さらに、Ruff は、すでに単一引用符と二重引用符の混合を使用しており、ダブルまたはシングルスタイルに移行できないプロジェクトに対して、引用符スタイルの「保持」をサポートしています。

引用符スタイルのpreserveは、すべての文字列の引用符を変更しません。

Default value: double

Type: "double" | "single" | "preserve"

Example usage:

[tool.ruff.format]
# Prefer single quotes over double quotes.
quote-style = "single"
[format]
# Prefer single quotes over double quotes.
quote-style = "single"

skip-magic-trailing-comma#

Ruff は、既存の末尾のカンマを使用して、短い行を分離しておく必要があることを示します。

このオプションがtrueに設定されている場合、マジック・トレーリング・カンマは無視されます。

例えば、skip-magic-trailing-comma=falseの場合、引数を 1 行にまとめると行の長さを超えないとしても、Ruff は引数を分離したままにします。:

# The arguments remain on separate lines because of the trailing comma after `b`
def test(
    a,
    b,
): pass

skip-magic-trailing-comma = trueを設定すると、書式が次のように変更されます。:

# The arguments remain on separate lines because of the trailing comma after `b`
def test(a, b):
    pass

Default value: false

Type: bool

Example usage:

[tool.ruff.format]
skip-magic-trailing-comma = true
[format]
skip-magic-trailing-comma = true

lint#

Ruff がコードをチェックする方法を設定します。

lintセクションで指定されたオプションは、推奨されていないトップレベルの設定よりも優先されます。

allowed-confusables#

RUF001RUF002、およびRUF003を適用する際に無視することが許される"紛らわしい"Unicode 文字のリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint]
# Allow minus-sign (U+2212), greek-small-letter-rho (U+03C1), and the asterisk-operator (U+2217),
# which could be confused for "-", "p", and "*", respectively.
allowed-confusables = ["−", "ρ", "∗"]
[lint]
# Allow minus-sign (U+2212), greek-small-letter-rho (U+03C1), and the asterisk-operator (U+2217),
# which could be confused for "-", "p", and "*", respectively.
allowed-confusables = ["−", "ρ", "∗"]

dummy-variable-rgx#

「ダミー」変数を識別するために使用される正規表現、または(例えば)未使用変数の規則を適用するときに無視されるべき変数。デフォルトの式は___、および_varに一致しますが、_var_には一致しません。

Default value: "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

Type: re.Pattern

Example usage:

[tool.ruff.lint]
# Only ignore variables named "_".
dummy-variable-rgx = "^_$"
[lint]
# Only ignore variables named "_".
dummy-variable-rgx = "^_$"

exclude#

グローバルに除外されたファイルに加えて、リンティングから除外するファイルパターンのリスト(excludeおよびextend-excludeを参照)。

除外はグローバルに基づいており、次のいずれかになります。:

  • .mypy_cache(ツリー内の.mypy_cacheという名前のディレクトリを除外する)、foo.py(foo.pyという名前のファイルを除外する)、foo_*.py(foo_*.pyに一致するファイルを除外する)のような単一パスパターン。
  • 相対パターン:directory/foo.py(その特定のファイルを除外する)またはdirectory/*.py( これらのパスはプロジェクトのルート(例えば、pyproject.tomlを含むディレクトリ)からの相対パスであることに注意してください。

glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint]
exclude = ["generated"]
[lint]
exclude = ["generated"]

explicit-preview-rules#

プレビュー・ルールを選択するために正確なコードを必要とするかどうか。有効にすると、プレビュー・ルールは接頭辞によって選択されません。ルールを有効にするには、各プレビュー・ルールの完全なコードが必要です。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint]
# Require explicit selection of preview rules.
explicit-preview-rules = true
[lint]
# Require explicit selection of preview rules.
explicit-preview-rules = true

extend-fixable#

fixableで指定されたものに加えて、修正可能とみなされるルールコードまたはプレフィックスのリスト。

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# Enable fix for flake8-bugbear (`B`), on top of any rules specified by `fixable`.
extend-fixable = ["B"]
[lint]
# Enable fix for flake8-bugbear (`B`), on top of any rules specified by `fixable`.
extend-fixable = ["B"]

extend-ignore#

Deprecated

このオプションは廃止されました。extend-ignoreオプションはignoreと交換可能になりました。代わりにignoreオプションを使用するように構成を更新してください。

ignoreで指定されたものに加えて、無視するルールコードまたはプレフィックスのリスト。

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# Skip unused variable rules (`F841`).
extend-ignore = ["F841"]
[lint]
# Skip unused variable rules (`F841`).
extend-ignore = ["F841"]

extend-per-file-ignores#

per-file-ignoriesによって除外されたルールに加えて、除外するルール・コードまたはプレフィックスへのファイル・パターンからのマッピングのリスト。

Default value: {}

Type: dict[str, list[RuleSelector]]

Example usage:

[tool.ruff.lint.extend-per-file-ignores]
# Also ignore `E402` in all `__init__.py` files.
"__init__.py" = ["E402"]
[lint.extend-per-file-ignores]
# Also ignore `E402` in all `__init__.py` files.
"__init__.py" = ["E402"]

extend-safe-fixes#

安全でない修正が安全であると考えられるルールコードまたはプレフィックスのリスト。

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# Allow applying all unsafe fixes in the `E` rules and `F401` without the `--unsafe-fixes` flag
extend-safe-fixes = ["E", "F401"]
[lint]
# Allow applying all unsafe fixes in the `E` rules and `F401` without the `--unsafe-fixes` flag
extend-safe-fixes = ["E", "F401"]

extend-select#

selectで指定されたものに加えて、有効にするルールコードまたはプレフィックスのリスト。

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# On top of the default `select` (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
extend-select = ["B", "Q"]
[lint]
# On top of the default `select` (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
extend-select = ["B", "Q"]

extend-unsafe-fixes#

安全な修正が安全でないと見なされるルールコードまたはプレフィックスのリスト。

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# Require the `--unsafe-fixes` flag when fixing the `E` rules and `F401`
extend-unsafe-fixes = ["E", "F401"]
[lint]
# Require the `--unsafe-fixes` flag when fixing the `E` rules and `F401`
extend-unsafe-fixes = ["E", "F401"]

external#

Ruff によってサポートされていないが、(例えば)# noqaディレクティブを検証するときに保持されるべきルールコードまたはプレフィックスのリスト。Ruff によってまだ実装されていないプラグインをカバーする# noqaディレクティブを保持するのに便利です。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint]
# Avoiding flagging (and removing) any codes starting with `V` from any
# `# noqa` directives, despite Ruff's lack of support for `vulture`.
external = ["V"]
[lint]
# Avoiding flagging (and removing) any codes starting with `V` from any
# `# noqa` directives, despite Ruff's lack of support for `vulture`.
external = ["V"]

fixable#

修正可能とみなされるルール・コードまたは接頭辞のリスト。デフォルトでは、すべてのルールが修正可能とみなされます。

Default value: ["ALL"]

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# Only allow fix behavior for `E` and `F` rules.
fixable = ["E", "F"]
[lint]
# Only allow fix behavior for `E` and `F` rules.
fixable = ["E", "F"]

ignore#

無視する規則コードまたは接頭辞のリスト。接頭辞は、厳密な規則(F841など)、カテゴリ全体(Fなど)、またはその間の任意のものを指定できます。

有効なルールと無効なルールの関係を(それぞれselectignoreによって)断ち切る場合、より具体的なプレフィックスがより具体的でないプレフィックスを上書きします。

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# Skip unused variable rules (`F841`).
ignore = ["F841"]
[lint]
# Skip unused variable rules (`F841`).
ignore = ["F841"]

ignore-init-module-imports#

Deprecated

このオプションは0.4. 4で廃止されました。ignore-init-module-importsは将来のバージョンで削除される予定です。これは、F401が__init__.py(現在プレビューモード)の未使用のインポートに対する適切な修正を推奨するようになったためです。詳細についてはドキュメントを参照し、構成を更新してください。

__init__.pyファイル内の未使用のインポートを自動的に削除しないようにしてください。このようなインポートにはフラグが付けられますが、インポートがモジュールの__all__シンボルに追加されるか、冗長なエイリアス(例えば、import os as os)で再エクスポートされるかを示す専用のメッセージが表示されます。

このオプションはデフォルトで有効になっていますが、安全でない修正を介してインポートを削除することもできます。

Default value: true

Type: bool

Example usage:

[tool.ruff.lint]
ignore-init-module-imports = false
[lint]
ignore-init-module-imports = false

logger-objects#

logging.Loggerオブジェクトと同等に扱われるべきオブジェクトのリスト。

これは、共通モジュールからlogging.Loggerオブジェクトを再エクスポートするプロジェクトの適切な診断(例えば、loggingの非推奨やその他のベストプラクティスを特定するため)を確実にするのに役立ちます。

たとえば、次の内容のモジュールlogging_setup.pyがあるとします。:

import logging

logger = logging.getLogger(__name__)

"logging_setup.logger"logger-objectsに追加すると、他のモジュール(例えばfrom logging_setup import logger)からインポートされた場合、logging_setup.loggerlogging.Loggerオブジェクトとして扱われるようになります。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint]
logger-objects = ["logging_setup.logger"]
[lint]
logger-objects = ["logging_setup.logger"]

per-file-ignores#

一致するファイルを考慮する場合に、ファイル・パターンから除外するルール・コードまたは接頭辞へのマッピングのリスト。最初の!はファイル・パターンを否定します。

Default value: {}

Type: dict[str, list[RuleSelector]]

Example usage:

[tool.ruff.lint.per-file-ignores]
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
# Ignore `D` rules everywhere except for the `src/` directory.
"!src/**.py" = ["D"]
[lint.per-file-ignores]
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
# Ignore `D` rules everywhere except for the `src/` directory.
"!src/**.py" = ["D"]

preview#

プレビュー・モードを有効にするかどうか。プレビュー・モードが有効な場合、Ruff は不安定なルールと修正を使用します。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint]
# Enable preview features.
preview = true
[lint]
# Enable preview features.
preview = true

select#

使用可能にするルール・コードまたは接頭辞のリスト。接頭辞は、正確なルール(F841など)、カテゴリ全体(Fなど)またはその間の任意のものを指定できます。

有効なルールと無効なルールの関係を(それぞれselectignoreによって)断ち切る場合、より具体的なプレフィックスがより具体的でないプレフィックスを上書きします。

Default value: ["E4", "E7", "E9", "F"]

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
select = ["E4", "E7", "E9", "F", "B", "Q"]
[lint]
# On top of the defaults (`E4`, E7`, `E9`, and `F`), enable flake8-bugbear (`B`) and flake8-quotes (`Q`).
select = ["E4", "E7", "E9", "F", "B", "Q"]

task-tags#

認識するタスクタグのリスト("TODO"、"FIXME"、"XXX"など)。

これらのタグで始まるコメントは、コメントアウトされたコード検出(ERA)では無視され、ignore-overlong-task-commentstrueに設定されている場合は、行長ルール(E501)によってスキップされます。

Default value: ["TODO", "FIXME", "XXX"]

Type: list[str]

Example usage:

[tool.ruff.lint]
task-tags = ["HACK"]
[lint]
task-tags = ["HACK"]

typing-modules#

エクスポートがtypingモジュールのメンバーと同等に扱われるべきモジュールのリスト。

これは、互換性モジュールからtypingおよびtyping_extensionsメンバを再エクスポートするプロジェクトに対して、適切な型アノテーション推論を保証するのに便利です。省略した場合、typingおよびtyping_extensions以外のモジュールからインポートされたメンバは、通常の Python オブジェクトとして扱われます。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint]
typing-modules = ["airflow.typing_compat"]
[lint]
typing-modules = ["airflow.typing_compat"]

unfixable#

修正不可能と見なす規則コードまたはプレフィクスのリスト。

Default value: []

Type: list[RuleSelector]

Example usage:

[tool.ruff.lint]
# Disable fix for unused imports (`F401`).
unfixable = ["F401"]
[lint]
# Disable fix for unused imports (`F401`).
unfixable = ["F401"]

lint.flake8-annotations#

allow-star-arg-any#

動的に型指定された*argsおよび**kwargs引数に対してANN401を抑制するかどうか。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true
[lint.flake8-annotations]
allow-star-arg-any = true

ignore-fully-untyped#

型指定されていない宣言に対してANN*規則を抑制するかどうか。

これにより、コードベースに型を徐々に追加することが容易になります。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-annotations]
ignore-fully-untyped = true
[lint.flake8-annotations]
ignore-fully-untyped = true

mypy-init-return#

少なくとも 1 つの引数に注釈が付けられている場合に、__init__の戻り値の型ヒントの省略を許可するかどうか。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-annotations]
mypy-init-return = true
[lint.flake8-annotations]
mypy-init-return = true

suppress-dummy-args#

(_のような)"ダミー"変数 regex にマッチする引数に対してANN000レベルの違反を抑制するかどうか。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-annotations]
suppress-dummy-args = true
[lint.flake8-annotations]
suppress-dummy-args = true

suppress-none-returning#

次のいずれかの条件を満たす関数に対して、ANN200レベルの違反を抑止するかどうか。:

  • return文が含まれていません。
  • 明示的なreturn文はすべてNoneを(明示的または暗黙的に)返します。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-annotations]
suppress-none-returning = true
[lint.flake8-annotations]
suppress-none-returning = true

lint.flake8-bandit#

check-typed-exception#

特定の例外タイプに対してtry-except-pass(S110)を禁止するかどうか。デフォルトでは、try-except-passExceptionBaseExceptionに対してのみ禁止されています。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-bandit]
check-typed-exception = true
[lint.flake8-bandit]
check-typed-exception = true

hardcoded-tmp-directory#

一時的と見なすディレクトリのリスト。

Default value: ["/tmp", "/var/tmp", "/dev/shm"]

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-bandit]
hardcoded-tmp-directory = ["/foo/bar"]
[lint.flake8-bandit]
hardcoded-tmp-directory = ["/foo/bar"]

hardcoded-tmp-directory-extend#

hardcoded-tmp-directoryで指定されたディレクトリに加えて、一時的と見なすディレクトリのリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-bandit]
hardcoded-tmp-directory-extend = ["/foo/bar"]
[lint.flake8-bandit]
hardcoded-tmp-directory-extend = ["/foo/bar"]

lint.flake8-boolean-trap#

extend-allowed-calls#

ブール値トラップを許可する追加の呼び出し可能関数。

完全修飾名のリスト(例えば、Fieldではなくpydantic.Field)を受け取ることを期待します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-boolean-trap]
extend-allowed-calls = ["pydantic.Field", "django.db.models.Value"]
[lint.flake8-boolean-trap]
extend-allowed-calls = ["pydantic.Field", "django.db.models.Value"]

lint.flake8-bugbear#

extend-immutable-calls#

例えば、function-call-in-default-argumentルール(B008)やfunction-call-in-dataclass-defaultsルール(RUF009)など、評価時に「不変」とみなされる追加の呼び出し可能な関数。

完全修飾名のリスト(例えば、Queryではなくfastapi.Query)を受け取ることを期待します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-bugbear]
# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
extend-immutable-calls = ["fastapi.Depends", "fastapi.Query"]
[lint.flake8-bugbear]
# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
extend-immutable-calls = ["fastapi.Depends", "fastapi.Query"]

lint.flake8-builtins#

builtins-allowed-modules#

許可する組み込みモジュール名のリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-builtins]
builtins-allowed-modules = ["id"]
[lint.flake8-builtins]
builtins-allowed-modules = ["id"]

builtins-ignorelist#

組み込みコマンドのリストを無視します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = ["id"]
[lint.flake8-builtins]
builtins-ignorelist = ["id"]

lint.flake8-comprehensions#

allow-dict-calls-with-keyword-arguments#

キーワード引数(例:dict(a=1, b=2))を使用するdict呼び出しを許可します。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-comprehensions]
allow-dict-calls-with-keyword-arguments = true
[lint.flake8-comprehensions]
allow-dict-calls-with-keyword-arguments = true

著作権表示内で実行する著者。提供されている場合、著者は著作権表示の直後に存在する必要があります。

Default value: null

Type: str

Example usage:

[tool.ruff.lint.flake8-copyright]
author = "Ruff"
[lint.flake8-copyright]
author = "Ruff"

著作権表示を適用するために必要な最小ファイル・サイズ(バイト単位)。デフォルトでは、すべてのファイルが検証されます。

Default value: 0

Type: int

Example usage:

[tool.ruff.lint.flake8-copyright]
# Avoid enforcing a header on files smaller than 1024 bytes.
min-file-size = 1024
[lint.flake8-copyright]
# Avoid enforcing a header on files smaller than 1024 bytes.
min-file-size = 1024

regexクレートでコンパイルされた、著作権表示と一致するために使用される正規表現。

デフォルトは(?i)Copyright\s+((?:\(C\)©)\s+)?\d{4}((-,\s)\d{4})*で、次の文字列と一致します。:

  • Copyright 2023
  • Copyright (C) 2023
  • Copyright 2021-2023
  • Copyright (C) 2021-2023
  • Copyright (C) 2021, 2023

Default value: (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*

Type: str

Example usage:

[tool.ruff.lint.flake8-copyright]
notice-rgx = "(?i)Copyright \\(C\\) \\d{4}"
[lint.flake8-copyright]
notice-rgx = "(?i)Copyright \\(C\\) \\d{4}"

lint.flake8-errmsg#

max-string-length#

例外メッセージ内の文字列リテラルの最大文字列長。

Default value: 0

Type: int

Example usage:

[tool.ruff.lint.flake8-errmsg]
max-string-length = 20
[lint.flake8-errmsg]
max-string-length = 20

lint.flake8-gettext#

extend-function-names#

function-namesに含まれている関数名に加えて、国際化呼び出しとして考慮すべき追加の関数名。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-gettext]
extend-function-names = ["ugettetxt"]
[lint.flake8-gettext]
extend-function-names = ["ugettetxt"]

function-names#

国際化コールと見なされる関数名。

Default value: ["_", "gettext", "ngettext"]

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-gettext]
function-names = ["_", "gettext", "ngettext", "ugettetxt"]
[lint.flake8-gettext]
function-names = ["_", "gettext", "ngettext", "ugettetxt"]

lint.flake8-implicit-str-concat#

allow-multiline#

複数行の文字列に暗黙的な文字列連結を許可するかどうか。

デフォルトでは、複数行ストリングの暗黙的な連結が許可されています(ただし、バックスラッシュで区切られた継続行は禁止されています)。

allow-multiline=falseを設定すると、explicit-string-concatenation(ISC003)ルールが自動的に無効になります。そうしないと、暗黙的および明示的な複数行文字列の連結が違反と見なされ、linter 準拠の複数行文字列を書くことができなくなります。

Default value: true

Type: bool

Example usage:

[tool.ruff.lint.flake8-implicit-str-concat]
allow-multiline = false
[lint.flake8-implicit-str-concat]
allow-multiline = false

lint.flake8-import-conventions#

aliases#

インポート用の従来のエイリアス。これらのエイリアスは、extend-aliasesオプションで拡張できます。

Default value: {"altair": "alt", "matplotlib": "mpl", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns", "tensorflow": "tf", "tkinter": "tk", "holoviews": "hv", "panel": "pn", "plotly.express": "px", "polars": "pl", "pyarrow": "pa", "xml.etree.ElementTree": "ET"}

Type: dict[str, str]

Example usage:

[tool.ruff.lint.flake8-import-conventions.aliases]
# Declare the default aliases.
altair = "alt"
"matplotlib.pyplot" = "plt"
numpy = "np"
pandas = "pd"
seaborn = "sns"
scipy = "sp"
[lint.flake8-import-conventions.aliases]
# Declare the default aliases.
altair = "alt"
"matplotlib.pyplot" = "plt"
numpy = "np"
pandas = "pd"
seaborn = "sns"
scipy = "sp"

banned-aliases#

モジュールから禁止されたインポートエイリアスへのマッピング。

Default value: {}

Type: dict[str, list[str]]

Example usage:

[tool.ruff.lint.flake8-import-conventions.banned-aliases]
# Declare the banned aliases.
"tensorflow.keras.backend" = ["K"]
[lint.flake8-import-conventions.banned-aliases]
# Declare the banned aliases.
"tensorflow.keras.backend" = ["K"]

banned-from#

from ... import ... 構文を使用してからインポートしてはならないモジュールのリスト。

例えば、banned-from=["pandas"]が指定された場合、from pandas import DataFrameは許可されず、import pandasは許可されます。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-import-conventions]
# Declare the banned `from` imports.
banned-from = ["typing"]
[lint.flake8-import-conventions]
# Declare the banned `from` imports.
banned-from = ["typing"]

extend-aliases#

モジュールから従来のインポートエイリアスへのマッピング。これらのエイリアスはaliasesマッピングに追加されます。

Default value: {}

Type: dict[str, str]

Example usage:

[tool.ruff.lint.flake8-import-conventions.extend-aliases]
# Declare a custom alias for the `dask` module.
"dask.dataframe" = "dd"
[lint.flake8-import-conventions.extend-aliases]
# Declare a custom alias for the `dask` module.
"dask.dataframe" = "dd"

lint.flake8-pytest-style#

fixture-parentheses#

パラメータなしの@pytest.fixture()が括弧を持つべきかどうかを指定するブールフラグです。オプションがfalse(デフォルト)に設定されている場合、@pytest.fixtureは有効で@pytest.fixture()は無効です。trueに設定されている場合、@pytest.fixture()は有効で@pytest.fixtureは無効です。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = true
[lint.flake8-pytest-style]
fixture-parentheses = true

mark-parentheses#

パラメータなしの@pytest.mark.foo()が括弧を持つべきかどうかを指定するブールフラグです。オプションがfalse(デフォルト)に設定されている場合、@pytest.mark.fooは有効で@pytest.mark.foo()は無効です。trueに設定されている場合、@pytest.mark.foo()は有効で@pytest.mark.fooは無効です。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-pytest-style]
mark-parentheses = true
[lint.flake8-pytest-style]
mark-parentheses = true

parametrize-names-type#

@pytest.mark.parametizeで複数の引数名に必要な型です。以下の値がサポートされています:

  • csv - カンマで区切られたリスト、例:@pytest.mark.parametize("name1,name2",...)
  • tuple(デフォルト) - 例:@pytest.mark.parametize(("name1","name2"),...)
  • list - 例:@pytest.mark.parametize(["name1","name2"],...)

Default value: tuple

Type: "csv" | "tuple" | "list"

Example usage:

[tool.ruff.lint.flake8-pytest-style]
parametrize-names-type = "list"
[lint.flake8-pytest-style]
parametrize-names-type = "list"

parametrize-values-row-type#

複数のパラメータの場合、@pytest.mark.parametizeの値の各行に必要な型です。次の値がサポートされています:

  • tuple (default) — e.g. @pytest.mark.parametrize(("name1", "name2"), [(1, 2), (3, 4)])
  • list — e.g. @pytest.mark.parametrize(("name1", "name2"), [[1, 2], [3, 4]])

Default value: tuple

Type: "tuple" | "list"

Example usage:

[tool.ruff.lint.flake8-pytest-style]
parametrize-values-row-type = "list"
[lint.flake8-pytest-style]
parametrize-values-row-type = "list"

parametrize-values-type#

@pytest.mark.parametricizeの値リスト行に必要な型です。次の値がサポートされています:

  • tuple -例: @pytest.mark.parametize("name",(1, 2, 3))
  • list(デフォルト) - 例: @pytest.mark.parametize("name",[1, 2, 3])

Default value: list

Type: "tuple" | "list"

Example usage:

[tool.ruff.lint.flake8-pytest-style]
parametrize-values-type = "tuple"
[lint.flake8-pytest-style]
parametrize-values-type = "tuple"

raises-extend-require-match-for#

pytest.raises()呼び出しで match=パラメータを必要とする追加の例外名のリスト。これにより、match=パラメータを必要とする例外のデフォルトリストが拡張されます。

このオプションは、リスト全体を指定しなくても、match=パラメーターを必要とする例外のデフォルト・リストを拡張したい場合に便利です。

このオプションは、defaultlist から例外を削除しないことに注意してください。

Supports glob patterns. For more information on the glob syntax, referto the globset documentation.

glob パターンをサポートします。glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-pytest-style]
raises-extend-require-match-for = ["requests.RequestException"]
[lint.flake8-pytest-style]
raises-extend-require-match-for = ["requests.RequestException"]

raises-require-match-for#

pytest.raises()呼び出しで match=パラメータを必要とする例外名のリスト。

glob パターンをサポートします。glob 構文の詳細については、globset documentationを参照してください。

Default value: ["BaseException", "Exception", "ValueError", "OSError", "IOError", "EnvironmentError", "socket.error"]

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-pytest-style]
raises-require-match-for = ["requests.RequestException"]
[lint.flake8-pytest-style]
raises-require-match-for = ["requests.RequestException"]

lint.flake8-quotes#

avoid-escape#

PEP 8に従って、文字列に一重引用符が含まれている場合に一重引用符を使用しないようにするか、またはその逆に二重引用符を使用するか。

これにより、ストリング内の引用符をエスケープする必要性が最小限に抑えられます。

Default value: true

Type: bool

Example usage:

[tool.ruff.lint.flake8-quotes]
# Don't bother trying to avoid escapes.
avoid-escape = false
[lint.flake8-quotes]
# Don't bother trying to avoid escapes.
avoid-escape = false

docstring-quotes#

docstring に適した引用符のスタイル("single"または"double")。

フォーマッタを使用する場合、"double"のみが互換性があります。これは、フォーマッタが docstrings 文字列に二重引用符を強制するためです。

Default value: "double"

Type: "single" | "double"

Example usage:

[tool.ruff.lint.flake8-quotes]
docstring-quotes = "single"
[lint.flake8-quotes]
docstring-quotes = "single"

inline-quotes#

インライン文字列に適した引用符のスタイル("single"または"double")。

フォーマッタを使用するときは、format.quote-styleが同じ推奨の引用スタイルに設定されていることを確認してください。

Default value: "double"

Type: "single" | "double"

Example usage:

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"
[lint.flake8-quotes]
inline-quotes = "single"

multiline-quotes#

複数行の文字列に適した引用符のスタイル("single"または"double")。

フォーマッタを使用する場合、"double"のみが互換性があります。これは、フォーマッタが複数行の文字列に二重引用符を強制するためです。

Default value: "double"

Type: "single" | "double"

Example usage:

[tool.ruff.lint.flake8-quotes]
multiline-quotes = "single"
[lint.flake8-quotes]
multiline-quotes = "single"

lint.flake8-self#

extend-ignore-names#

ignore-namesに含まれる名前に加えて、flake8-self違反を考慮する場合に無視する追加の名前。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-self]
extend-ignore-names = ["_base_manager", "_default_manager",  "_meta"]
[lint.flake8-self]
extend-ignore-names = ["_base_manager", "_default_manager",  "_meta"]

ignore-names#

flake8-self違反を考慮するときに無視する名前のリスト。

Default value: ["_make", "_asdict", "_replace", "_fields", "_field_defaults", "_name_", "_value_"]

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-self]
ignore-names = ["_new"]
[lint.flake8-self]
ignore-names = ["_new"]

lint.flake8-tidy-imports#

ban-relative-imports#

すべての関連するインポートを禁止するか("all")、親モジュール内またはそれ以降に拡張するインポートのみを禁止するか("parents")。

Default value: "parents"

Type: "parents" | "all"

Example usage:

[tool.ruff.lint.flake8-tidy-imports]
# Disallow all relative imports.
ban-relative-imports = "all"
[lint.flake8-tidy-imports]
# Disallow all relative imports.
ban-relative-imports = "all"

banned-api#

インポートまたはアクセスできない特定のモジュールまたはモジュールメンバー。

この規則は偶発的な使用にフラグを立てることだけを目的としており、evalまたはimportlibによって回避できることに注意してください。

Default value: {}

Type: dict[str, { "msg": str }]

Example usage:

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"cgi".msg = "The cgi module is deprecated, see https://peps.python.org/pep-0594/#cgi."
"typing.TypedDict".msg = "Use typing_extensions.TypedDict instead."
[lint.flake8-tidy-imports.banned-api]
"cgi".msg = "The cgi module is deprecated, see https://peps.python.org/pep-0594/#cgi."
"typing.TypedDict".msg = "Use typing_extensions.TypedDict instead."

banned-module-level-imports#

モジュールレベルでインポートされない可能性があり、代わりに遅延インポートされる必要がある特定のモジュールのリスト(例:関数定義、if TYPE_CHECKING:ブロック、またはその他のネストされたコンテキスト内)。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-tidy-imports]
# Ban certain modules from being imported at module level, instead requiring
# that they're imported lazily (e.g., within a function definition).
banned-module-level-imports = ["torch", "tensorflow"]
[lint.flake8-tidy-imports]
# Ban certain modules from being imported at module level, instead requiring
# that they're imported lazily (e.g., within a function definition).
banned-module-level-imports = ["torch", "tensorflow"]

lint.flake8-type-checking#

exempt-modules#

特定のモジュールをタイプチェックブロックに移動する必要がないようにします。

Default value: ["typing"]

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-type-checking]
exempt-modules = ["typing", "typing_extensions"]
[lint.flake8-type-checking]
exempt-modules = ["typing", "typing_extensions"]

quote-annotations#

タイプ注釈の周りに引用符を追加するかどうか。追加すると、対応するインポートがタイプチェックブロックに移動されます。

例えば、以下の例では、型アノテーションでのみ使用されているにもかかわらず、Python はSequenceが実行時に使用可能であることを要求しています。:

from collections.abc import Sequence

def func(value: Sequence[int]) -> None:
    ...

言い換えると、from collections.abc import Sequenceを上記のif TYPE_CHECKING:ブロックに移動すると、実行時にその型が使用できなくなるため、実行時エラーが発生します。

デフォルトでは、Ruff はそのようなランタイムセマンティクスを尊重し、そのようなランタイムエラーを防ぐためにインポートの移動を回避します。

quote-annotationstrueに設定すると、Ruff は注釈の周りに引用符を追加するように指示され(例えば"Sequence[int]")、次のように Ruff がインポートをif TYPE_CHECKING:ブロックに移動できるようになります。:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from collections.abc import Sequence

def func(value: "Sequence[int]") -> None:
    ...

この設定は、from_ _future __import annotationsが存在する場合には効果がないことに注意してください。__future__アノテーションは常に引用されたアノテーションと区別して扱われます。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-type-checking]
# Add quotes around type annotations, if doing so would allow
# an import to be moved into a type-checking block.
quote-annotations = true
[lint.flake8-type-checking]
# Add quotes around type annotations, if doing so would allow
# an import to be moved into a type-checking block.
quote-annotations = true

runtime-evaluated-base-classes#

列挙されたクラスのいずれかを基本クラスとしてリストするクラスは、型チェックブロックに移動する必要がないように免除します。

一般的な例としては、Pydantic のpydantic.BaseModelや SQLAlchemy のSQLAlchemy.orm.DeclarativeBaseなどがありますが、これらの基本クラスを継承するユーザー定義のクラスもサポートできます。たとえば、プロジェクト全体で使用される共通のDeclarativeBaseサブクラス(base.pyclass Base(DeclarativeBase) ...など)を定義している場合は、このリスト(runtime-evaluated-base-classes=["base.Base"])に追加して、モデルが型チェックブロックに移動されないようにすることができます。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-type-checking]
runtime-evaluated-base-classes = ["pydantic.BaseModel", "sqlalchemy.orm.DeclarativeBase"]
[lint.flake8-type-checking]
runtime-evaluated-base-classes = ["pydantic.BaseModel", "sqlalchemy.orm.DeclarativeBase"]

runtime-evaluated-decorators#

列挙されたデコレータのいずれかで修飾されたクラスと関数を、型チェックブロックに移動しないように免除します。

一般的な例としては、Pydantic の@pydantic.validate_callデコレータ(関数用)や attrs の@attrs.defineデコレータ(クラス用)などがあります。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.flake8-type-checking]
runtime-evaluated-decorators = ["pydantic.validate_call", "attrs.define"]
[lint.flake8-type-checking]
runtime-evaluated-decorators = ["pydantic.validate_call", "attrs.define"]

strict#

同じモジュールに対して有効なランタイムインポートが存在する場合でも、TC001TC002、およびTC003ルールを適用します。

flake8-type-checking のstrictオプションを参照してください。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-type-checking]
strict = true
[lint.flake8-type-checking]
strict = true

lint.flake8-unused-arguments#

ignore-variadic-names#

*args**kwargsのような使用されていない可変引数を許可するかどうか。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.flake8-unused-arguments]
ignore-variadic-names = true
[lint.flake8-unused-arguments]
ignore-variadic-names = true

lint.isort#

case-sensitive#

大文字と小文字の区別を考慮してインポートをソートします。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
case-sensitive = true
[lint.isort]
case-sensitive = true

classes#

大文字小文字の区別に関係なく、常にorder-by-typeのクラスとして認識されるトークンのオーバーライドリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
classes = ["SVC"]
[lint.isort]
classes = ["SVC"]

combine-as-imports#

同じ行でインポートとして結合します。isort のcombine-as-importsオプションを参照してください。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
combine-as-imports = true
[lint.isort]
combine-as-imports = true

constants#

大文字小文字の区別に関係なく、常に CONSTANTfororder-by-typeとして認識されるトークンのオーバーライドリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
constants = ["constant"]
[lint.isort]
constants = ["constant"]

default-section#

指定されたsection-orderに適合しないインポートのデフォルトセクションを定義します。

Default value: third-party

Type: str

Example usage:

[tool.ruff.lint.isort]
default-section = "first-party"
[lint.isort]
default-section = "first-party"

detect-same-package#

同じパッケージ内からのインポートを自動的にファーストパーティとしてマークするかどうか。

たとえば、detect-same-package = trueの場合、fooパッケージ内のファイルを分析すると、fooパッケージ内からのインポートはすべてファーストパーティと見なされます。

srcがすべてのファーストパーティソースを検出するように設定されている場合、このヒューリスティックは不要なことがよくあります。ただし、src設定されていない場合、このヒューリスティックは、within(acrossではなく_)ファーストパーティパッケージからのファーストパーティインポートを検出するのに役立ちます。

Default value: true

Type: bool

Example usage:

[tool.ruff.lint.isort]
detect-same-package = false
[lint.isort]
detect-same-package = false

extra-standard-library#

Ruff が事前に知っているモジュールに加えて、標準ライブラリを考慮すべきモジュールのリスト。

glob パターンをサポートします。glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
extra-standard-library = ["path"]
[lint.isort]
extra-standard-library = ["path"]

force-single-line#

読み込みからのすべてのデータを、それぞれの行に表示します。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
force-single-line = true
[lint.isort]
force-single-line = true

force-sort-within-sections#

(import sysのような)単純なスタイルのインポートを、(from itertools import groupbyのような)from スタイルのインポートの前にソートしないでください。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
force-sort-within-sections = true
[lint.isort]
force-sort-within-sections = true

force-to-top#

特定のインポートを該当するセクションの先頭に強制的に配置します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
force-to-top = ["src"]
[lint.isort]
force-to-top = ["src"]

force-wrap-aliases#

複数のメンバーと少なくとも 1 つの別名を持つimport fromステートメント(たとえば、import A as B)を、すべての行に正確に 1 つのメンバーが含まれるようにラップするように強制します。たとえば、このフォーマットは 1 行に凝縮されるのではなく、保持されます::

from .utils import (
    test_directory as test_directory,
    test_id as test_id
)

この設定は、combine-as-imports=trueと組み合わせた場合にのみ有効であることに注意してください。combine-as-importsが有効になっていない場合、エイリアスされたすべてのimport fromに独自の行が与えられます。この場合、ラップは必要ありません。

フォーマッタを使用する場合は、force-wrap-aliasesを有効にするときにformat.skip-magic-trailing-commafalse(デフォルト)に設定されていることを確認してください。これにより、すべてのメンバーが 1 行に収まる場合にフォーマッタがメンバーを折りたたまないようにします。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
force-wrap-aliases = true
combine-as-imports = true
[lint.isort]
force-wrap-aliases = true
combine-as-imports = true

forced-separate#

指定された順序で、インポートの補助ブロックに分割するモジュールのリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
forced-separate = ["tests"]
[lint.isort]
forced-separate = ["tests"]

from-first#

ソート時にimport fromインポートを「straight」インポートの前に配置するかどうか。

For example, by default, imports will be sorted such that straight imports appearbefore import from imports, as in:

たとえば、デフォルトでは、インポートは次のようにimport fromインポートの前に表示されるようにソートされます。:

import os
import sys
from typing import List

代わりに、from-first = trueを設定すると、次のように、import fromインポートがストレートインポートの前に表示されるようにソートされます。:

from typing import List
import os
import sys

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
from-first = true
[lint.isort]
from-first = true

known-first-party#

ローカルファイルシステムのイントロスペクションによって識別できるかどうかに関係なく、ファーストパーティと見なすモジュールのリスト。

glob パターンをサポートします。glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
known-first-party = ["src"]
[lint.isort]
known-first-party = ["src"]

known-local-folder#

ローカルフォルダと見なすモジュールのリスト。

通常、これは相対インポート(from . import module)のために予約されています。

glob パターンをサポートします。glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
known-local-folder = ["src"]
[lint.isort]
known-local-folder = ["src"]

known-third-party#

ローカルファイルシステムのイントロスペクションによって識別できるかどうかに関係なく、サードパーティと見なすモジュールのリスト。

glob パターンをサポートします。glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
known-third-party = ["src"]
[lint.isort]
known-third-party = ["src"]

length-sort#

文字列の長さでインポートをソートし、短いインポートが長いインポートの前に表示されるようにします。たとえば、デフォルトでは、インポートは次のようにアルファベット順にソートされます:

import collections
import os

length-sort = trueを設定すると、次のように、短いインポートが長いインポートの前に表示されるようにソートされます。:

import os
import collections

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
length-sort = true
[lint.isort]
length-sort = true

length-sort-straight#

文字列の長さで直接インポートをソートします。length-sortに似ていますが、直接インポートにのみ適用され、fromインポートには影響しません。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
length-sort-straight = true
[lint.isort]
length-sort-straight = true

lines-after-imports#

インポート後に配置する空白行の数。

自動判別には-1を使用してください。

Ruff は、型付けスタイルの推奨事項(source)に従って、型付けスタブファイル(拡張子.pyiのファイル)のインポート後に最大 1 行の空白行を使用します。

フォーマッタを使用する場合、値-112のみが互換性があります。これは、インポート後に少なくとも 1 行、多くても 2 行の空行が強制されるためです。

Default value: -1

Type: int

Example usage:

[tool.ruff.lint.isort]
# Use a single line after each import block.
lines-after-imports = 1
[lint.isort]
# Use a single line after each import block.
lines-after-imports = 1

lines-between-types#

"direct"とimport fromimports の間に置く行数。

フォーマッタを使用する場合、空行01のみが互換性があります。これは、ネストされたブロックにインポートした後、最大 1 つの値が保持されるためです。

Default value: 0

Type: int

Example usage:

[tool.ruff.lint.isort]
# Use a single line between direct and from import.
lines-between-types = 1
[lint.isort]
# Use a single line between direct and from import.
lines-between-types = 1

no-lines-before#

前のセクションから空行で区切られるべきではないセクションのリスト。

Default value: []

Type: list["future" | "standard-library" | "third-party" | "first-party" | "local-folder" | str]

Example usage:

[tool.ruff.lint.isort]
no-lines-before = ["future", "standard-library"]
[lint.isort]
no-lines-before = ["future", "standard-library"]

no-sections#

すべてのインポートを同じセクションバケットに配置します。

たとえば、標準ライブラリとサードパーティのインポートを分離するのではなく、次のようにします。:

import os
import sys

import numpy
import pandas

no-sections = trueを設定すると、代わりにすべての読み込みが 1 つのセクションにグループ化されます。:

import numpy
import os
import pandas
import sys

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.isort]
no-sections = true
[lint.isort]
no-sections = true

order-by-type#

アルファベット順に加えて、大文字と小文字を区別して、インポートをタイプ別に順序付けします。

Default value: true

Type: bool

Example usage:

[tool.ruff.lint.isort]
order-by-type = true
[lint.isort]
order-by-type = true

relative-imports-order#

"より近い"インポート(より少ない.文字、最もローカル)を"より遠い"インポート(より多い.文字、最もローカル)の前に配置するか、またはその逆に配置するか。

デフォルト("furthest-to-closest")は、isort のreverse-relativeデフォルト(reverse-relative=false)と同じです。これを"closest-to-furthest"に設定することは、isort のreverse-relative = trueと同じです。

Default value: furthest-to-closest

Type: "furthest-to-closest" | "closest-to-furthest"

Example usage:

[tool.ruff.lint.isort]
relative-imports-order = "closest-to-furthest"
[lint.isort]
relative-imports-order = "closest-to-furthest"

required-imports#

指定したインポート行をすべてのファイルに追加します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]
[lint.isort]
required-imports = ["from __future__ import annotations"]

section-order#

セクションを出力する順序を上書きします。カスタム・セクションの移動に使用できます。

Default value: ["future", "standard-library", "third-party", "first-party", "local-folder"]

Type: list["future" | "standard-library" | "third-party" | "first-party" | "local-folder" | str]

Example usage:

[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "first-party", "local-folder", "third-party"]
[lint.isort]
section-order = ["future", "standard-library", "first-party", "local-folder", "third-party"]

sections#

セクション名からモジュールへのマッピングのリスト。

デフォルトでは、インポートはタイプ(future, third-partyなど)に従って分類されます。この設定により、モジュールをカスタム・セクションにグループ化して、組込みセクションを拡張または上書きできます。

たとえば、すべてのテストユーティリティをグループ化するには、testingセクションを作成します。:

testing = ["pytest", "hypothesis"]

リスト内の値は、glob パターンとして扱われます。たとえば、LangChain エコシステム(LangChain-coreLangChain-openaiなど)内のすべてのパッケージを一致させるには、次のようにします。:

langchain = ["langchain-*"]

カスタムセクションは通常、section-orderリストに挿入して、次のようにスタンドアロングループとして意図した順序で表示されるようにする必要があります。:

section-order = [
  "future",
  "standard-library",
  "third-party",
  "first-party",
  "local-folder",
  "testing"
]

カスタムセクションがsection-orderから省略された場合、そのセクションのインポートはdefault-section(デフォルトではthird-party)に割り当てられます。

Default value: {}

Type: dict[str, list[str]]

Example usage:

[tool.ruff.lint.isort.sections]
# Group all Django imports into a separate section.
"django" = ["django"]
[lint.isort.sections]
# Group all Django imports into a separate section.
"django" = ["django"]

single-line-exclusions#

単一行ルールから除外する 1 つ以上のモジュール。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
single-line-exclusions = ["os", "json"]
[lint.isort]
single-line-exclusions = ["os", "json"]

split-on-trailing-comma#

複数行のインポートで最後のメンバーの後にカンマを置くと、インポートが 1 行に折りたたまれることはありません。

isort のsplit-on-trailing-commaオプションを参照してください。

フォーマッタを使用する場合、split-on-trailing-commaを有効にするときに、format.skip-magic-trailing-commafalse(デフォルト)に設定されていることを確認してください。これにより、フォーマッタが末尾のカンマを削除しないようにします。

Default value: true

Type: bool

Example usage:

[tool.ruff.lint.isort]
split-on-trailing-comma = false
[lint.isort]
split-on-trailing-comma = false

variables#

大文字小文字の区別に関係なく、常に varfororder-by-typeとして認識されるトークンのオーバーライドリスト。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.isort]
variables = ["VAR"]
[lint.isort]
variables = ["VAR"]

lint.mccabe#

max-complexity#

C901エラーを引き起こす前に許容される McCabe の最大複雑度。

Default value: 10

Type: int

Example usage:

[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 5.
max-complexity = 5
[lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 5.
max-complexity = 5

lint.pep8-naming#

classmethod-decorators#

メソッドに適用されたときに、そのメソッドが(組み込みの@classmethodに加えて)クラスメソッドとして扱われるべきであることを示すデコレータのリスト。

例えば、Ruff は、このリスト内のデコレータによって修飾されたメソッドが最初の引数としてcls引数を取ることを期待します。

完全修飾された名前のリスト(例えばvalidatorではなくpydantic.validator)を受け取るか、デコレータ自体がドット付きの名前で構成されている場合には最後のセグメントと照合されるプレーンな名前を受け取ることを期待します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.pep8-naming]
classmethod-decorators = [
    # Allow Pydantic's `@validator` decorator to trigger class method treatment.
    "pydantic.validator",
    # Allow SQLAlchemy's dynamic decorators, like `@field.expression`, to trigger class method treatment.
    "declared_attr",
    "expression",
    "comparator",
]
[lint.pep8-naming]
classmethod-decorators = [
    # Allow Pydantic's `@validator` decorator to trigger class method treatment.
    "pydantic.validator",
    # Allow SQLAlchemy's dynamic decorators, like `@field.expression`, to trigger class method treatment.
    "declared_attr",
    "expression",
    "comparator",
]

extend-ignore-names#

ignore-namesに含まれるものに加えて、pep8-naming違反を考慮するときに無視する追加の名前(またはパターン)。

glob パターンをサポートします。たとえば、test_で始まる名前や_testで終わる名前をすべて無視するには、ignore-names=["test_*","*_test"]を使用します。

glob 構文の詳細については、globset documentationを参照してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.pep8-naming]
extend-ignore-names = ["callMethod"]
[lint.pep8-naming]
extend-ignore-names = ["callMethod"]

ignore-names#

pep8-naming違反を考慮するときに無視する名前(またはパターン)のリスト。

glob パターンをサポートします。たとえば、test_で始まる名前や_testで終わる名前をすべて無視するには、ignore-names = ["test_*", "*_test"]を使用します。

glob 構文の詳細については、globset documentationを参照してください。

Default value: ["setUp", "tearDown", "setUpClass", "tearDownClass", "setUpModule", "tearDownModule", "asyncSetUp", "asyncTearDown", "setUpTestData", "failureException", "longMessage", "maxDiff"]

Type: list[str]

Example usage:

[tool.ruff.lint.pep8-naming]
ignore-names = ["callMethod"]
[lint.pep8-naming]
ignore-names = ["callMethod"]

staticmethod-decorators#

メソッドに適用されたときに、そのメソッドが(組み込みの@staticmethodに加えて)静的メソッドとして扱われるべきであることを示すデコレータのリスト。

例えば Ruff は、このリストのデコレータによって修飾されたメソッドには、selfcls引数がないことを期待します。

完全修飾された名前のリスト(例えば、teardownではなくbelay.Device.teardown)を受け取るか、デコレータ自体がドット付きの名前で構成されている場合には、最後のセグメントと照合されるプレーンな名前を受け取ることを期待します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.pep8-naming]
# Allow Belay's `@Device.teardown` decorator to trigger static method treatment.
staticmethod-decorators = ["belay.Device.teardown"]
[lint.pep8-naming]
# Allow Belay's `@Device.teardown` decorator to trigger static method treatment.
staticmethod-decorators = ["belay.Device.teardown"]

lint.pycodestyle#

ignore-overlong-task-comments#

task-tags(デフォルトでは:["TODO","FIXME","XXX"])で始まるコメントに対して行長違反(E501)を発生させるかどうか。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.pycodestyle]
ignore-overlong-task-comments = true
[lint.pycodestyle]
ignore-overlong-task-comments = true

max-doc-length#

スタンドアロンコメントを含む、doc-line-too-longドキュメント(W505)内の違反に許可される最大行長。デフォルトでは、これはnullに設定されており、違反のレポートは無効になります。

長さは、アジア系文字または絵文字を含む行を除き、1 行あたりの文字数によって決まります。

これらの行では、各文字のunicode widthが加算されて長さが決定されます。

詳細については、doc-line-too-longルールを参照してください。

Default value: null

Type: int

Example usage:

[tool.ruff.lint.pycodestyle]
max-doc-length = 88
[lint.pycodestyle]
max-doc-length = 88

max-line-length#

line-too-long違反に対して許可される最大行長。デフォルトでは、これはline-lengthオプションの値に設定されます。

このオプションは、pycodestyle.line-lengthline-lengthより大きい値に設定することで、フォーマッタが自動的に分割できない非常に長い行を検出したい場合に使用します。

# The formatter wraps lines at a length of 88.
line-length = 88

[pycodestyle]
# E501 reports lines that exceed the length of 100.
max-line-length = 100

長さは、東アジアの文字または絵文字を含む行を除き、1 行あたりの文字数によって決まります。

これらの行では、各文字のunicode widthが加算されて長さが決定されます。

詳細については、line-too-longルールを参照してください。

Default value: null

Type: int

Example usage:

[tool.ruff.lint.pycodestyle]
max-line-length = 100
[lint.pycodestyle]
max-line-length = 100

lint.pydocstyle#

convention#

docstring セクションを分析するときに、Google スタイル、NumPy スタイルの規則、またはPEP 257のデフォルトを使用するかどうか。

規則を有効にすると、指定した規則に含まれていないすべての規則が無効になります。そのため、意図されたワークフローでは、規則を有効にしてから、その上にある追加の規則を選択的に有効または無効にします。

たとえば、Google スタイルの規則を使用しながら、すべての関数パラメータのドキュメントを必要としないようにするには、次のようにします。:

[tool.ruff.lint]
# Enable all `pydocstyle` rules, limiting to those that adhere to the
# Google convention via `convention = "google"`, below.
select = ["D"]

# On top of the Google convention, disable `D417`, which requires
# documentation for every function parameter.
ignore = ["D417"]

[tool.ruff.lint.pydocstyle]
convention = "google"

To enable an additional rule that's excluded from the convention,select the desired rule via its fully qualified rule code (e.g.,D400 instead of D4 or D40):

規則から除外された追加の規則を有効にするには、完全修飾された規則コード(たとえば、D40またはD4ではなくD400)を使用して目的の規則を選択します。:

[tool.ruff.lint]
# Enable D400 on top of the Google convention.
extend-select = ["D400"]

[tool.ruff.lint.pydocstyle]
convention = "google"

Default value: null

Type: "google" | "numpy" | "pep257"

Example usage:

[tool.ruff.lint.pydocstyle]
# Use Google-style docstrings.
convention = "google"
[lint.pydocstyle]
# Use Google-style docstrings.
convention = "google"

ignore-decorators#

指定された完全修飾子で修飾された関数やメソッドの docstring は無視してください。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.pydocstyle]
ignore-decorators = ["typing.overload"]
[lint.pydocstyle]
ignore-decorators = ["typing.overload"]

property-decorators#

デコレータのリストで、メソッドに適用されると、(組み込みの@propertyと標準ライブラリ@functools.cached_propertyに加えて)そのメソッドがプロパティとして扱われることを示します。

例えば、Ruff は、このリストのデコレータによって装飾されたメソッドが、非命令的なサマリ行を使用できることを期待します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.pydocstyle]
property-decorators = ["gi.repository.GObject.Property"]
[lint.pydocstyle]
property-decorators = ["gi.repository.GObject.Property"]

lint.pyflakes#

extend-generics#

任意の添字を型注釈として扱う必要があるような、汎用と見なされる追加の関数またはクラス(例えば、django.db.models.ForeignKey["User"]ForeignKey)。

完全修飾名のリスト(例えば、ForeignKeyではなくdjango.db.models.ForeignKey)を受け取ることを期待します。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.pyflakes]
extend-generics = ["django.db.models.ForeignKey"]
[lint.pyflakes]
extend-generics = ["django.db.models.ForeignKey"]

lint.pylint#

allow-dunder-method-names#

Python 標準ライブラリ(PLW3201を参照)のデフォルトセットに加えて、許可するダンダメソッド名。

Default value: []

Type: list[str]

Example usage:

[tool.ruff.lint.pylint]
allow-dunder-method-names = ["__tablename__", "__table_args__"]
[lint.pylint]
allow-dunder-method-names = ["__tablename__", "__table_args__"]

allow-magic-value-types#

「マジック値」として使用される場合に無視される定数型です(PLR2004を参照)。

Default value: ["str", "bytes"]

Type: list["str" | "bytes" | "complex" | "float" | "int"]

Example usage:

[tool.ruff.lint.pylint]
allow-magic-value-types = ["int"]
[lint.pylint]
allow-magic-value-types = ["int"]

max-args#

関数またはメソッドの定義に使用できる引数の最大数(PLR0913を参照)。

Default value: 5

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-args = 10
[lint.pylint]
max-args = 10

max-bool-expr#

1 つのif文内で許可されるブール式の最大数です(PLR0916を参照)。

Default value: 5

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-bool-expr = 10
[lint.pylint]
max-bool-expr = 10

max-branches#

関数またはメソッド本体に許可される分岐の最大数(PLR0912を参照)。

Default value: 12

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-branches = 15
[lint.pylint]
max-branches = 15

max-locals#

関数またはメソッド本体に許可されるローカル変数の最大数(PLR0914を参照)。

Default value: 15

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-locals = 20
[lint.pylint]
max-locals = 20

max-nested-blocks#

関数またはメソッド本体内で許容されるネストされたブロックの最大数(PLR1702を参照)。

Default value: 5

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-nested-blocks = 10
[lint.pylint]
max-nested-blocks = 10

max-positional-args#

関数またはメソッドの定義に使用できる位置引数の最大数(PLR0917を参照)。

指定しない場合、デフォルトではmax-argsの値になります。

Default value: 5

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-positional-args = 3
[lint.pylint]
max-positional-args = 3

max-public-methods#

クラスに許可されている public メソッドの最大数(PLR0904を参照)。

Default value: 20

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-public-methods = 30
[lint.pylint]
max-public-methods = 30

max-returns#

関数またはメソッド本体に許可される return 文の最大数(PLR0911を参照)

Default value: 6

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-returns = 10
[lint.pylint]
max-returns = 10

max-statements#

関数またはメソッド本体に許可されるステートメントの最大数(PLR0915を参照)。

Default value: 50

Type: int

Example usage:

[tool.ruff.lint.pylint]
max-statements = 75
[lint.pylint]
max-statements = 75

lint.pyupgrade#

keep-runtime-typing#

Whether to avoid PEP 585 (List[int] -> list[int]) and PEP 604(Union[str, int] -> str | int) rewrites even if a file importsfrom __future__ import annotations.

PEP 585(List[int] -> list[int])とPEP 604(Union[str, int] -> str | int)を回避するかどうかは、ファイルがfrom__future__import annotationsをインポートした場合でも書き換えます。

For example, while the following is valid Python 3.8 code due to thepresence of from __future__ import annotations, the use of str | intprior to Python 3.10 will cause Pydantic to raise a TypeError atruntime:

例えば、以下のコードはfrom __future__ import annotationsが存在するため Python 3.8 のコードとしては有効ですが、Python 3.10 より前のバージョンでstr | intを使用すると、Pydantic は実行時にTypeErrorを発生させてしまいます。:

from __future__ import annotations

import pydantic

class Foo(pydantic.BaseModel):
    bar: str | int

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true
[lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true

lint.ruff#

parenthesize-tuple-in-subscript#

タプルによってキー付けされたアイテムに、タプルを括弧で囲んでアクセスするかどうかを指定します(RUF031を参照)。

Default value: false

Type: bool

Example usage:

[tool.ruff.lint.ruff]
# Make it a violation to use a tuple in a subscript without parentheses.
parenthesize-tuple-in-subscript = true
[lint.ruff]
# Make it a violation to use a tuple in a subscript without parentheses.
parenthesize-tuple-in-subscript = true