mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Include both ruff help
and ruff help check
in README (#2325)
This commit is contained in:
parent
2ad29089af
commit
64fb0bd2cc
4 changed files with 128 additions and 23 deletions
93
README.md
93
README.md
|
@ -347,15 +347,14 @@ an equivalent schema (though the `[tool.ruff]` hierarchy can be omitted). For ex
|
||||||
`pyproject.toml` described above would be represented via the following `ruff.toml`:
|
`pyproject.toml` described above would be represented via the following `ruff.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
# Enable Pyflakes and pycodestyle rules.
|
# Enable flake8-bugbear (`B`) rules.
|
||||||
select = ["E", "F"]
|
select = ["E", "F", "B"]
|
||||||
|
|
||||||
# Never enforce `E501` (line length violations).
|
# Never enforce `E501` (line length violations).
|
||||||
ignore = ["E501"]
|
ignore = ["E501"]
|
||||||
|
|
||||||
# Always autofix, but never try to fix `F401` (unused imports).
|
# Avoid trying to fix flake8-bugbear (`B`) violations.
|
||||||
fix = true
|
unfixable = ["B"]
|
||||||
unfixable = ["F401"]
|
|
||||||
|
|
||||||
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
|
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
|
||||||
[per-file-ignores]
|
[per-file-ignores]
|
||||||
|
@ -365,15 +364,18 @@ unfixable = ["F401"]
|
||||||
|
|
||||||
For a full list of configurable options, see the [API reference](#reference).
|
For a full list of configurable options, see the [API reference](#reference).
|
||||||
|
|
||||||
Some common configuration settings can be provided via the command-line:
|
### Command-line interface
|
||||||
|
|
||||||
|
Some configuration settings can be provided via the command-line, such as those related to
|
||||||
|
rule enablement and disablement, file discovery, logging level, and more:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
ruff path/to/code/ --select F401 --select F403
|
ruff path/to/code/ --select F401 --select F403 --quiet
|
||||||
```
|
```
|
||||||
|
|
||||||
See `ruff --help` for more:
|
See `ruff help` for more on Ruff's top-level commands:
|
||||||
|
|
||||||
<!-- Begin auto-generated cli help. -->
|
<!-- Begin auto-generated command help. -->
|
||||||
```
|
```
|
||||||
Ruff: An extremely fast Python linter.
|
Ruff: An extremely fast Python linter.
|
||||||
|
|
||||||
|
@ -396,7 +398,78 @@ Log levels:
|
||||||
|
|
||||||
For help with a specific command, see: `ruff help <command>`.
|
For help with a specific command, see: `ruff help <command>`.
|
||||||
```
|
```
|
||||||
<!-- End auto-generated cli help. -->
|
<!-- End auto-generated command help. -->
|
||||||
|
|
||||||
|
Or `ruff help check` for more on the linting command:
|
||||||
|
|
||||||
|
<!-- Begin auto-generated subcommand help. -->
|
||||||
|
```
|
||||||
|
Run Ruff on the given files or directories
|
||||||
|
|
||||||
|
Usage: ruff check [OPTIONS] [FILES]...
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
[FILES]... List of files or directories to check
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--fix Attempt to automatically fix lint violations
|
||||||
|
--show-source Show violations with source code
|
||||||
|
--diff Avoid writing any fixed files back; instead, output a diff for each changed file to stdout
|
||||||
|
-w, --watch Run in watch mode by re-running whenever files change
|
||||||
|
--fix-only Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix`
|
||||||
|
--format <FORMAT> Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab, pylint]
|
||||||
|
--config <CONFIG> Path to the `pyproject.toml` or `ruff.toml` file to use for configuration
|
||||||
|
--statistics Show counts for every rule with at least one violation
|
||||||
|
--add-noqa Enable automatic additions of `noqa` directives to failing lines
|
||||||
|
--show-files See the files Ruff will be run against with the current settings
|
||||||
|
--show-settings See the settings Ruff will use to lint a given Python file
|
||||||
|
-h, --help Print help
|
||||||
|
|
||||||
|
Rule selection:
|
||||||
|
--select <RULE_CODE>
|
||||||
|
Comma-separated list of rule codes to enable (or ALL, to enable all rules)
|
||||||
|
--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 the selected ones
|
||||||
|
--extend-ignore <RULE_CODE>
|
||||||
|
Like --ignore, but adds additional rule codes on top of the ignored ones
|
||||||
|
--per-file-ignores <PER_FILE_IGNORES>
|
||||||
|
List of mappings from file pattern to code to exclude
|
||||||
|
--fixable <RULE_CODE>
|
||||||
|
List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
||||||
|
--unfixable <RULE_CODE>
|
||||||
|
List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
||||||
|
|
||||||
|
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
|
||||||
|
--respect-gitignore Respect file exclusions via `.gitignore` and other standard ignore files
|
||||||
|
--force-exclude Enforce exclusions, even for paths passed to Ruff directly on the command-line
|
||||||
|
|
||||||
|
Rule configuration:
|
||||||
|
--target-version <TARGET_VERSION>
|
||||||
|
The minimum Python version that should be supported
|
||||||
|
--line-length <LINE_LENGTH>
|
||||||
|
Set the line-length for length-associated rules and automatic formatting
|
||||||
|
--dummy-variable-rgx <DUMMY_VARIABLE_RGX>
|
||||||
|
Regular expression matching the name of dummy variables
|
||||||
|
|
||||||
|
Miscellaneous:
|
||||||
|
-n, --no-cache
|
||||||
|
Disable cache reads
|
||||||
|
--isolated
|
||||||
|
Ignore all configuration files
|
||||||
|
--cache-dir <CACHE_DIR>
|
||||||
|
Path to the cache directory [env: RUFF_CACHE_DIR=]
|
||||||
|
--stdin-filename <STDIN_FILENAME>
|
||||||
|
The name of the file when passing it through stdin
|
||||||
|
-e, --exit-zero
|
||||||
|
Exit with status code "0", even upon detecting lint violations
|
||||||
|
--update-check
|
||||||
|
Enable or disable automatic update checks
|
||||||
|
```
|
||||||
|
<!-- End auto-generated subcommand help. -->
|
||||||
|
|
||||||
### `pyproject.toml` discovery
|
### `pyproject.toml` discovery
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//! This library only exists to enable the Ruff internal tooling (`ruff_dev`)
|
//! This library only exists to enable the Ruff internal tooling (`ruff_dev`)
|
||||||
//! to automatically update the `ruff --help` output in the `README.md`.
|
//! to automatically update the `ruff help` output in the `README.md`.
|
||||||
//!
|
//!
|
||||||
//! For the actual Ruff library, see [`ruff`].
|
//! For the actual Ruff library, see [`ruff`].
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
@ -10,7 +10,26 @@ mod args;
|
||||||
|
|
||||||
use clap::CommandFactory;
|
use clap::CommandFactory;
|
||||||
|
|
||||||
/// Returns the output of `ruff --help`.
|
/// Returns the output of `ruff help`.
|
||||||
pub fn help() -> String {
|
pub fn command_help() -> String {
|
||||||
args::Args::command().render_help().to_string()
|
args::Args::command().render_help().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the output of `ruff help check`.
|
||||||
|
pub fn subcommand_help() -> String {
|
||||||
|
let output = args::Args::command()
|
||||||
|
.find_subcommand_mut("check")
|
||||||
|
.expect("`check` subcommand not found")
|
||||||
|
.render_help()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
// Replace the header, to fix Clap's omission of "ruff" on the "Usage: check" line.
|
||||||
|
let header =
|
||||||
|
"Run Ruff on the given files or directories (default)\n\nUsage: check [OPTIONS] [FILES]...";
|
||||||
|
let replacement =
|
||||||
|
"Run Ruff on the given files or directories\n\nUsage: ruff check [OPTIONS] [FILES]...";
|
||||||
|
let output = output
|
||||||
|
.strip_prefix(header)
|
||||||
|
.expect("`output` does not start expected header");
|
||||||
|
format!("{replacement}{output}")
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
//! Generate CLI help.
|
//! Generate CLI help.
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
|
|
||||||
use crate::utils::replace_readme_section;
|
use crate::utils::replace_readme_section;
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::str;
|
||||||
|
|
||||||
const HELP_BEGIN_PRAGMA: &str = "<!-- Begin auto-generated cli help. -->";
|
const COMMAND_HELP_BEGIN_PRAGMA: &str = "<!-- Begin auto-generated command help. -->";
|
||||||
const HELP_END_PRAGMA: &str = "<!-- End auto-generated cli help. -->";
|
const COMMAND_HELP_END_PRAGMA: &str = "<!-- End auto-generated command help. -->";
|
||||||
|
|
||||||
|
const SUBCOMMAND_HELP_BEGIN_PRAGMA: &str = "<!-- Begin auto-generated subcommand help. -->";
|
||||||
|
const SUBCOMMAND_HELP_END_PRAGMA: &str = "<!-- End auto-generated subcommand help. -->";
|
||||||
|
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
|
@ -19,15 +22,25 @@ fn trim_lines(s: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(args: &Args) -> Result<()> {
|
pub fn main(args: &Args) -> Result<()> {
|
||||||
let output = trim_lines(ruff_cli::help().trim());
|
// Generate `ruff help`.
|
||||||
|
let command_help = trim_lines(ruff_cli::command_help().trim());
|
||||||
|
|
||||||
|
// Generate `ruff help check`.
|
||||||
|
let subcommand_help = trim_lines(ruff_cli::subcommand_help().trim());
|
||||||
|
|
||||||
if args.dry_run {
|
if args.dry_run {
|
||||||
print!("{output}");
|
print!("{command_help}");
|
||||||
|
print!("{subcommand_help}");
|
||||||
} else {
|
} else {
|
||||||
replace_readme_section(
|
replace_readme_section(
|
||||||
&format!("```\n{output}\n```\n"),
|
&format!("```\n{command_help}\n```\n"),
|
||||||
HELP_BEGIN_PRAGMA,
|
COMMAND_HELP_BEGIN_PRAGMA,
|
||||||
HELP_END_PRAGMA,
|
COMMAND_HELP_END_PRAGMA,
|
||||||
|
)?;
|
||||||
|
replace_readme_section(
|
||||||
|
&format!("```\n{subcommand_help}\n```\n"),
|
||||||
|
SUBCOMMAND_HELP_BEGIN_PRAGMA,
|
||||||
|
SUBCOMMAND_HELP_END_PRAGMA,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue