Configuring Ruff#
Ruff はpyproject.toml
、ruff.toml
、または.ruff.toml
ファイルで設定できます。
Ruff をリンターとして使用するか、フォーマッターとして使用するか、あるいはその両方として使用するかにかかわらず、基礎となる構成戦略とセマンティクスは同じです。
使用可能な設定オプションの完全な列挙については、Settingsを参照してください。
指定しない場合、Ruff のデフォルトの設定は次のようになります。:
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
# Same as Black.
line-length = 88
indent-width = 4
# Assume Python 3.8
target-version = "py38"
[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"
# Like Black, indent with spaces, rather than tabs.
indent-style = "space"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false
# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
# Same as Black.
line-length = 88
indent-width = 4
# Assume Python 3.8
target-version = "py38"
[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[format]
# Like Black, use double quotes for strings.
quote-style = "double"
# Like Black, indent with spaces, rather than tabs.
indent-style = "space"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false
# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
たとえば、次のように Ruff を設定します。:
[tool.ruff.lint]
# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults.
select = ["E4", "E7", "E9", "F", "B"]
# 2. Avoid enforcing line-length violations (`E501`)
ignore = ["E501"]
# 3. Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]
# 4. Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories.
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs,tools}/*" = ["E402"]
[tool.ruff.format]
# 5. Use single quotes in `ruff format`.
quote-style = "single"
[lint]
# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults.
select = ["E4", "E7", "E9", "F", "B"]
# 2. Avoid enforcing line-length violations (`E501`)
ignore = ["E501"]
# 3. Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]
# 4. Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories.
[lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs,tools}/*" = ["E402"]
[format]
# 5. Use single quotes in `ruff format`.
quote-style = "single"
Linter プラグインの設定は、次のようにサブセクションで表されます。:
Ruff はpyproject.toml
、ruff.toml
、.ruff.toml
ファイルを尊重します。3 つとも同等のスキーマを実装しています(ただしruff.toml
と.ruff.toml
バージョンでは[tool.ruff]
ヘッダとtool.ruff
セクションの接頭辞は省略されています)。
使用可能な設定オプションの完全な列挙については、Settingsを参照してください。
Config file discovery#
ESLintと同様に Ruff は階層的な構成をサポートしており、ディレクトリ階層内の「最も近い」構成ファイルが個々のファイルに使用され、構成ファイル内のすべてのパス(例えばexclude
globs やsrc
パス)が、その構成ファイルを含むディレクトリからの相対パスとして解決されます。
There are a few exceptions to these rules:
これらの規則にはいくつかの例外があります。:
- 指定されたパスに"最も近い"
pyproject.toml
ファイルを見つける際、Ruff は[tool.ruff]
セクションがないpyproject.toml
ファイルを無視します。
- 設定ファイルが
--config
経由で直接渡される場合、これらの設定はall解析されたファイルに使用され、その設定ファイル内の相対パス(exclude
globs やsrc
パスなど)は_current_working ディレクトリからの相対パスとして解決されます。
- ファイルシステム階層に設定ファイルが見つからない場合、Ruff はデフォルトの設定を使用するように戻ります。ユーザ固有の設定ファイルが
${config_dir}/ruff/pyproject.toml
に存在する場合、そのファイルがデフォルトの設定の代わりに使用されます。${config_dir}
はetcetera
's native strategyによって決定され、すべての相対パスは再び現在の作業ディレクトリからの相対パスとして解決されます。
- コマンドライン(例えば
--select
)で提供される config-file-supported の設定は、_every_resolved 設定ファイルの設定を上書きします。
ESLintとは異なり Ruff は設定ファイル間の設定をマージしません。代わりに、「最も近い」設定ファイルが使用され、親の設定ファイルは無視されます。この暗黙的なカスケードの代わりに、Ruff はextend
フィールドをサポートしており、次のように別の設定ファイルから設定を継承できます。
上記の規則はすべて、pyproject.toml
、ruff.toml
、.ruff.toml
ファイルにも同様に適用されます。
Ruff が同じディレクトリ内に複数の設定ファイルを検出した場合、.ruff.toml
ファイルがruff.toml
ファイルより優先され、ruff.toml
ファイルがpyproject.toml
ファイルより優先されます。
Python file discovery#
コマンドラインにパスを渡すと、Ruff は各ディレクトリの設定ファイルのexclude
とextend-exclude
の設定を考慮して、そのパスにあるすべての Python ファイルを自動的に検出します。
exclude
設定をツール固有の設定テーブルにスコープすることで、ファイルをリンティングやフォーマットから選択的に除外することもできます。たとえば、次のようにすると、.pyi
ファイルのフォーマットからruff
が防止されますが、それらはリンティングに含まれ続けます。:
デフォルトでは、Ruff は.ignore
、.gitignore
、.git/info/exclude
、およびグローバルなgitignore
ファイルで省略されたファイルもスキップします(参照:respect-gitignore
)。
ruff
に直接渡されたファイルは、上記の条件にかかわらず常に解析されます。
たとえば、ruff check/path/to/excluded/file.py
は常にfile.py
をリントします。
Default inclusions#
デフォルトでは、Ruff は*.py
、*.pyi
、*.ipynb
、またはpyproject.toml
にマッチするファイルを検出します。
ファイル拡張子を追加してファイルをリントまたはフォーマットするには、extend-include
設定を使用します。
include
設定を使用してデフォルトの選択を変更することもできます。
Warning
include
_に提供されるパスは、ファイルと一致する必要があります。例えばinclude=["src"]
はディレクトリと一致するので失敗します。
Jupyter Notebook discovery#
Ruff にはリンティングとフォーマットのサポートが組み込まれていますJupyter Notebooks。これらはバージョン0.6.0
以上でデフォルトでリンティングされフォーマットされています。
JupyterNotebook ファイルをリントのみ、またはフォーマットのみにしたい場合は、セクション固有のexclude
オプションを使用してこれを行うことができます。たとえば、次の例では、JupyterNotebook ファイルのみをリントし、フォーマットは行いません。:
逆に、次の例では、Jupyter Notebook ファイルのみをフォーマットし、リントしません。:
extend-exclude
設定を更新することで、Jupyter Notebook のサポートを完全に無効にすることができます。
Jupyter Notebook ファイルに対して特定のルールを無視したい場合は、per-file-ignores
設定を使用して無視できます。:
いくつかのルールは、Jupyter Notebook ファイルに適用されたときに異なる動作をします。例えば、.py
ファイルに適用された場合、module-import-not-at-top-of-file
(E402
)ルールはファイルの先頭でインポートを検出しますが、ノートブックの場合はセルの先頭でインポートを検出します。特定のルールに対して、ルールのドキュメントは、Jupyter Notebook ファイルに適用されたときに異なる動作をするかどうかを常に指定します。
Command-line interface#
一部の構成オプションは、コマンド行の専用フラグを使用して指定またはオーバーライドできます。
console$ ruff check path/to/code/ --select F401 --select F403 --quiet
その他のすべての設定オプションは、コマンドラインで--config
フラグを使用して設定できます。詳細は後述します。
The --config
CLI flag#
--config
フラグには 2 つの使い方があります。
console$ ruff check path/to/directory --config path/to/ruff.toml
ただし、--config
フラグを使用して、TOML の<KEY> = <VALUE>
ペアを使用した構成設定の任意のオーバーライドを提供することもできます。
これは主に、専用のコマンドラインフラグを持たない設定を上書きしたい場合に便利です。
以下の例では、--config
フラグは、コマンドラインからdummy-variable-rgx
設定を上書きする唯一の方法です。なぜなら、この設定には専用の CLI フラグがないからです。per-file-ignores
設定は--per-file-ignores
専用フラグを使って上書きすることもできますが、--config
を使って設定を上書きすることもできます。
console$ ruff check path/to/file --config path/to/ruff.toml --config "lint.dummy-variable-rgx = '__.*'" --config "lint.per-file-ignores = {'some_file.py' = ['F841']}"
--config
に渡された設定オプションは、ruff.toml
ファイルの設定オプションと同じ方法で解析されます。
そのため、Ruff リンターに固有のオプションはlint.
(--config "dummy-variable-rgx = '__.*'"
)で始まる必要があり、これは単に--config "dummy-variable-rgx = '__.*'"
)よりも優れています。Ruff フォーマッターに固有のオプションはformat.
で始まる必要があります。
特定の設定オプションが dedicated フラグと--config
フラグによって同時に上書きされた場合、dedicated フラグが優先されます。この例では、最大許容行長は 100 ではなく 90 に設定されます。
console$ ruff format path/to/file --line-length=90 --config "line-length=100"
--config"line-length=90"
を指定すると、サブディレクトリで検出された設定ファイルを含め、Ruff によって検出されたall設定ファイルのline-length
設定が上書きされます。
この点で、--config "line-length=90"
を指定することは、--line-length=90
を指定することと同じ効果があります。--line-length=90
を指定すると、特定の設定ファイルがどこにあるかに関係なく、Ruff によって検出されたすべての設定ファイルのline-length
設定が上書きされます。
Full command-line interface#
Ruff のトップレベルコマンドの完全なリストについては、ruff help
を参照してください。
<!-- Ruff: An extremely fast Python linter and code formatter. -->
Ruff: 非常に高速なPythonのリンターおよびコードフォーマッターです。
Usage: ruff [OPTIONS] <COMMAND>
Commands:
<!--
check Run Ruff on the given files or directories (default)
rule Explain a rule (or all rules)
config List or describe the available configuration options
linter List all supported upstream linters
clean Clear any caches in the current directory and any subdirectories
format Run the Ruff formatter on the given files or directories
server Run the language server
version Display Ruff's version
help Print this message or the help of the given subcommand(s)
-->
check 指定したファイルまたはディレクトリに対してRuffを実行します(デフォルト)。
rule 1つのルール(またはすべてのルール)の説明
config 使用可能な構成オプションのリストまたは説明
linter サポートされているすべてのアップストリームlintをリストします。
clean 現在のディレクトリとサブディレクトリのキャッシュをすべてクリアします。
format 指定したファイルまたはディレクトリに対してRuffフォーマッタを実行します。
server 言語サーバーを実行する
version Ruffのバージョンを表示します。
helpこ のメッセージまたは指定されたサブコマンドのヘルプを表示します。
Options:
<!--
-h, --help Print help
-V, --version Print version
-->
-h, --helpヘルプの印刷
-V, --version印刷バージョン
Log levels:
<!--
-v, --verbose Enable verbose logging
-q, --quiet Print diagnostics, but nothing else
-s, --silent Disable all logging (but still exit with status code "1" upon detecting diagnostics)
-->
-v, --verbose冗長ロギングを有効にします。
-q, --quiet診断だけを表示します。
-s, --silentすべてのロギングを無効にします(ただし、診断の検出時にステータスコード"1"で終了します)。
Global options:
--config <CONFIG_OPTION>
<!--
Either a path to a TOML configuration file (`pyproject.toml` or `ruff.toml`), or a TOML `<KEY> = <VALUE>` pair (such as you might find in a `ruff.toml` configuration file) overriding a specific configuration option. Overrides of individual settings using this option always take precedence over all configuration files, including configuration files that were also specified using `--config`
-->
TOML設定ファイル(`pyproject.toml`または`ruff.toml`)へのパス、または特定の設定オプションを上書きするTOML`<KEY> = <VALUE>`のペア(`ruff.toml`設定ファイルにあるようなもの)。このオプションを使用した個々の設定の上書きは、`--config`を使用して指定された設定ファイルを含め、すべての設定ファイルよりも常に優先されます。
--isolated
<!--
Ignore all configuration files
-->
すべての構成ファイルを無視します。
<!-- For help with a specific command, see: `ruff help <command>`. -->
特定のコマンドのヘルプについては、`ruff help<command>`を参照してください。
linting コマンドの詳細については、ruff help check
を参照してください。
<!-- Run Ruff on the given files or directories (default) -->
指定されたファイルまたはディレクトリに対してRuffを実行します(デフォルト)。
Usage: ruff check [OPTIONS] [FILES]...
Arguments:
<!--
[FILES]... List of files or directories to check [default: .]
-->
[FILES]... チェックするファイルまたはディレクトリのリスト[default: .]
Options:
--fix
<!-- Apply fixes to resolve lint violations. Use `--no-fix` to disable or `--unsafe-fixes` to include unsafe fixes -->
リント違反を解決するための修正を適用します。無効にするには`--no-fix`を使用し、安全でない修正を含めるには`--unsafe-fixes`を使用します。
--unsafe-fixes
<!-- Include fixes that may not retain the original intent of the code. Use `--no-unsafe-fixes` to disable -->
コードの本来の意図を保持しない可能性のある修正を含めます。`--no-unsafe-fixes`を使用して無効にします。
--show-fixes
<!-- Show an enumeration of all fixed lint violations. Use `--no-show-fixes` to disable -->
修正されたすべてのリント違反の列挙を表示します。無効にするには`--no-show-fixes`を使用してください
--diff
<!-- Avoid writing any fixed files back; instead, output a diff for each changed file to stdout, and exit 0 if there are no diffs. Implies `--fix-only` -->
修正されたファイルを書き戻さないようにします。代わりに、変更されたファイルごとにdiffをstdoutに出力し、diffがない場合は0を終了します。
-w, --watch
<!-- Run in watch mode by re-running whenever files change -->
ファイルが変更されるたびに再実行し、監視モードで実行します。
--fix-only
<!-- Apply fixes to resolve lint violations, but don't report on, or exit non-zero for, leftover violations. Implies `--fix`. Use `--no-fix-only` to disable or `--unsafe-fixes` to include unsafe fixes -->
リント違反を解決するために修正を適用しますが、残った違反を報告したり、ゼロ以外の値で終了したりしません。`--fix`を意味します。`--no-fix-only`を使用して無効にするか、`--unsafe-fixes`を使用して安全でない修正を含めます。
--ignore-noqa
<!-- Ignore any `# noqa` comments -->
すべての`#noqa`コメントを無視します。
--output-format <OUTPUT_FORMAT>
<!-- Output serialization format for violations. The default serializatio format is "full" [env: RUFF_OUTPUT_FORMAT=] [possible values: text, concise, full, json, json-lines, junit, grouped, github, gitlab, pylint, rdjson, azure, sarif] -->
違反のシリアル化フォーマットを出力します。デフォルトのシリアル化フォーマットは"full"です[env:RUFF_OUTPUT_FORMAT=][可能な値:text, concise, full, json, json-lines, junit, grouped, github, gitlab, pylint, rdjson, azure, sarif]
-o, --output-file <OUTPUT_FILE>
<!-- Specify file to write the linter output to (default: stdout) [env: RUFF_OUTPUT_FILE=] -->
linterの出力を書き込むファイルを指定してください(デフォルト:stdout)[env: RUFF_OUTPUT_FILE=]
--target-version <TARGET_VERSION>
<!-- The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312, py313] -->
サポートする必要があるPythonの最小バージョン[可能な値:py37, py38, py39, py310, py311, py312, py313]
--preview
<!-- Enable preview mode; checks will include unstable rules and fixes. Use `--no-preview` to disable -->
プレビューモードを有効にします。チェックには不安定なルールと修正が含まれます。無効にするには`--no-preview`を使用してください
--extension <EXTENSION>
<!-- List of mappings from file extension to language (one of `python`, `ipynb`, `pyi`). For example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb` -->
ファイル拡張子から言語へのマッピングのリスト(`python`、`ipynb`、`pyi`のいずれか)。例えば、`.ipy`ファイルをIPythonノートブックとして扱うには、`--extension ipy:ipynb`を使用します。
--statistics
<!-- Show counts for every rule with at least one violation -->
違反が1つ以上あるすべてのルールのカウントを表示します。
--add-noqa
<!-- Enable automatic additions of `noqa` directives to failing lines -->
失敗した行への`noqa`指示子の自動追加を有効にします。
--show-files
<!-- See the files Ruff will be run against with the current settings -->
現在の設定でRuffが実行されるファイルを確認します。
--show-settings
<!-- See the settings Ruff will use to lint a given Python file -->
指定されたPythonファイルをリントするためにRuffが使用する設定を確認します。
-h, --help
Print help
ヘルプを表示します。
Rule selection:
--select <RULE_CODE>
<!-- Comma-separated list of rule codes to enable (or ALL, to enable all rules) -->
有効にするルール・コードのコンマ区切りリスト(または、すべてのルールを有効にする場合はALL)
--ignore <RULE_CODE>
<!-- Comma-separated list of rule codes to disable -->
無効にする規則コードのコンマ区切りのリスト
--extend-select <RULE_CODE>
<!-- Like --select, but adds additional rule codes on top of those already specified -->
--selectに似ていますが、すでに指定されているルールコードの上に追加のルールコードを追加します。
--per-file-ignores <PER_FILE_IGNORES>
<!-- List of mappings from file pattern to code to exclude -->
除外するファイルパターンからコードへのマッピングのリスト
--extend-per-file-ignores <EXTEND_PER_FILE_IGNORES>
<!-- Like `--per-file-ignores`, but adds additional ignores on top of those already specified -->
`--per-file-ignores`と似ていますが、すでに指定されているものの上にさらに無視を追加します。
--fixable <RULE_CODE>
<!-- List of rule codes to treat as eligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`) -->
fixの対象として扱うルールコードのリスト。fix自体が有効になっている場合にのみ適用されます(例:`--fix`を使用)。
--unfixable <RULE_CODE>
List of rule codes to treat as ineligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`)
fixに不適格として扱われるルールコードのリスト。fix自体が有効になっている場合にのみ適用されます(例:`--fix`を使用)。
--extend-fixable <RULE_CODE>
<!-- Like --fixable, but adds additional rule codes on top of those already specified -->
--fixableと似ていますが、すでに指定されているものの上に追加のルールコードを追加します。
File selection:
--exclude <FILE_PATTERN>
<!-- List of paths, used to omit files and/or directories from analysis -->
分析からファイルやディレクトリを除外するために使用されるパスのリスト
--extend-exclude <FILE_PATTERN>
<!-- Like --exclude, but adds additional files and directories on top of those already excluded -->
--excludeと似ていますが、すでに除外されているファイルとディレクトリの上に追加のファイルとディレクトリを追加します。
--respect-gitignore
<!-- Respect file exclusions via `.gitignore` and other standard ignore files. Use `--no-respect-gitignore` to disable -->
`.gitignore`やその他の標準的なignoreファイルによるファイルの除外を尊重します。無効にするには`--no-respect-gitignore`を使用してください。
--force-exclude
<!-- Enforce exclusions, even for paths passed to Ruff directly on the command-line. Use `--no-force-exclude` to disable -->
コマンドラインで直接Ruffに渡されたパスに対しても、除外を強制します。`--no-force-exclude`を使用して無効にします。
Miscellaneous:
-n, --no-cache
<!-- Disable cache reads [env: RUFF_NO_CACHE=] -->
キャッシュの読み取りを無効にする[env: RUFF_NO_CACHE=]
--cache-dir <CACHE_DIR>
<!-- Path to the cache directory [env: RUFF_CACHE_DIR=] -->
キャッシュディレクトリへのパス[env: RUFF_CACHE_DIR=]
--stdin-filename <STDIN_FILENAME>
<!-- The name of the file when passing it through stdin -->
stdinに渡すときのファイルの名前
-e, --exit-zero
<!-- Exit with status code "0", even upon detecting lint violations -->
リント違反が検出された場合でも、ステータスコード"0"で終了する
--exit-non-zero-on-fix
<!-- Exit with a non-zero status code if any files were modified via fix, even if no lint violations remain -->
いずれかのファイルがfixによって変更された場合、lint違反が残っていなくても、0以外のステータスコードで終了します。
Log levels:
<!--
-v, --verbose Enable verbose logging
-q, --quiet Print diagnostics, but nothing else
-s, --silent Disable all logging (but still exit with status code "1" upon detecting diagnostics)
-->
-v, --verbose冗長ロギングを有効にします。
-q, --quiet診断だけを表示します。
-s, --silentすべてのロギングを無効にします(ただし、診断の検出時にステータスコード"1"で終了します)。
Global options:
--config <CONFIG_OPTION>
<!-- Either a path to a TOML configuration file (`pyproject.toml` or `ruff.toml`), or a TOML `<KEY> = <VALUE>` pair (such as you might find in a `ruff.toml` configuration file) overriding a specific configuration option. Overrides of individual settings using this option always take precedence over all configuration files, including configuration files that were also specified using `--config` -->
TOML設定ファイル(`pyproject.toml`または`ruff.toml`)へのパス、または特定の設定オプションを上書きするTOML`<KEY> = <VALUE>`のペア(`ruff.toml`設定ファイルにあるようなもの)。このオプションを使用した個々の設定の上書きは、`--config`を使用して指定された設定ファイルを含め、すべての設定ファイルよりも常に優先されます。
--isolated
<!-- Ignore all configuration files -->
すべての構成ファイルを無視します。
フォーマットコマンドの詳細については、ruff help format
を参照してください。:
<!-- Run the Ruff formatter on the given files or directories -->
指定されたファイルまたはディレクトリに対してRuffフォーマッタを実行します。
Usage: ruff format [OPTIONS] [FILES]...
Arguments:
<!-- [FILES]... List of files or directories to format [default: .] -->
[FILES]... フォーマットするファイルまたはディレクトリのリスト[default: .]
Options:
--check
<!-- Avoid writing any formatted files back; instead, exit with a non-zero status code if any files would have been modified, and zero otherwise -->
フォーマットされたファイルを書き戻さないようにします。ファイルが変更された場合は0以外のステータスコードで終了し、それ以外の場合は0で終了します。
--diff
<!-- Avoid writing any formatted files back; instead, exit with a non-zero status code and the difference between the current file and how the formatted file would look like -->
フォーマットされたファイルを書き戻さないようにします。代わりに、ゼロ以外のステータスコードと、現在のファイルとフォーマットされたファイルの外観との違いを使用して終了します。
--extension <EXTENSION>
<!-- List of mappings from file extension to language (one of `python`, `ipynb`, `pyi`). For example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb` -->
ファイル拡張子から言語へのマッピングのリスト(`python`、`ipynb`、`pyi`のいずれか)。例えば、`.ipy`ファイルをIPythonノートブックとして扱うには、`--extension ipy:ipynb`を使用します。
--target-version <TARGET_VERSION>
<!-- The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312, py313] -->
サポートする必要があるPythonの最小バージョン[可能な値:py37, py38, py39, py310, py311, py312, py313]
--preview
<!-- Enable preview mode; enables unstable formatting. Use `--no-preview` to disable -->
プレビューモードを有効にします。不安定な書式設定を有効にします。無効にするには`--no-preview`を使用してください
-h, --help
<!-- Print help (see more with '--help') -->
ヘルプの表示('--help'で詳細を参照)
Miscellaneous:
-n, --no-cache
<!-- Disable cache reads [env: RUFF_NO_CACHE=] -->
キャッシュの読み取りを無効にする[env: RUFF_NO_CACHE=]
--cache-dir <CACHE_DIR>
<!-- Path to the cache directory [env: RUFF_CACHE_DIR=] -->
キャッシュディレクトリへのパス[env: RUFF_CACHE_DIR=]
--stdin-filename <STDIN_FILENAME>
<!-- The name of the file when passing it through stdin -->
stdinに渡すときのファイルの名前
File selection:
--respect-gitignore
<!-- Respect file exclusions via `.gitignore` and other standard ignore files. Use `--no-respect-gitignore` to disable -->
`.gitignore`やその他の標準的なignoreファイルによるファイルの除外を尊重します。無効にするには`--no-respect-gitignore`を使用してください。
--exclude <FILE_PATTERN>
<!-- List of paths, used to omit files and/or directories from analysis -->
分析からファイルやディレクトリを除外するために使用されるパスのリスト
--force-exclude
<!-- Enforce exclusions, even for paths passed to Ruff directly on the command-line. Use `--no-force-exclude` to disable -->
コマンドラインで直接Ruffに渡されたパスに対しても、除外を強制します。`--no-force-exclude`を使用して無効にします。
Format configuration:
--line-length <LINE_LENGTH> Set the line-length
--line-length <LINE_LENGTH> line-lengthを設定します。
Editor options:
<!-- --range <RANGE> When specified, Ruff will try to only format the code in the given range. It might be necessary to extend the start backwards or the end forwards, to fully enclose a logical line. The `<RANGE>` uses the format `<start_line>:<start_column>-<end_line>:<end_column>`. -->
--range <RANGE> 指定された場合、Ruffは指定された範囲のコードのみをフォーマットしようとします。論理行を完全に囲むために、開始を後方に、または終了を前方に延長する必要がある場合があります。`<RANGE>`は`<start_line>:<start_column>-<end_line>:<end_column>`という形式を使用します。
Log levels:
<!--
-v, --verbose Enable verbose logging
-q, --quiet Print diagnostics, but nothing else
-s, --silent Disable all logging (but still exit with status code "1" upon detecting diagnostics)
-->
-v, --verbose冗長ロギングを有効にします。
-q, --quiet診断だけを表示します。
-s, --silentすべてのロギングを無効にします(ただし、診断の検出時にステータスコード"1"で終了します)。
Global options:
--config <CONFIG_OPTION>
<!-- Either a path to a TOML configuration file (`pyproject.toml` or `ruff.toml`), or a TOML `<KEY> = <VALUE>` pair (such as you might find in a `ruff.toml` configuration file) overriding a specific configuration option. Overrides of individual settings using this option always take precedence over all configuration files, including configuration files that were also specified using `--config` -->
TOML設定ファイル(`pyproject.toml`または`ruff.toml`)へのパス、または特定の設定オプションを上書きするTOML`<KEY> = <VALUE>`のペア(`ruff.toml`設定ファイルにあるようなもの)。このオプションを使用した個々の設定の上書きは、`--config`を使用して指定された設定ファイルを含め、すべての設定ファイルよりも常に優先されます。
--isolated
<!-- Ignore all configuration files -->
すべての構成ファイルを無視します。
Shell autocompletion#
Ruff はほとんどのシェルで自動補完をサポートしています。シェル固有の補完スクリプトはruff generate-shell-completion <SHELL>
で生成できます。<SHELL>
はbash
、elvish
、fig
、fish
、powershell
、またはzsh
のいずれかです。
自動補完を有効にするために必要な正確な手順は、シェルによって異なります。手順の例については、Poetryまたはripgrepのドキュメントを参照してください。
例として Zsh のオートコンプリートを有効にするには、ruff generate-shell-completion zsh>~/.zfunc/_ruff
を実行します。次に、~/.zshrc
ファイルがまだ存在しない場合は、次の行を追加します。:
zshfpath+=~/.zfuncautoload -Uz compinit && compinit