mirror of https://github.com/astral-sh/ruff
parent
1d5592d937
commit
e2ec62cf33
93
README.md
93
README.md
|
|
@ -80,61 +80,60 @@ select = [
|
||||||
Alternatively, on the command-line:
|
Alternatively, on the command-line:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
ruff path/to/code/ --select F401 F403
|
ruff path/to/code/ --select F401 --select F403
|
||||||
```
|
```
|
||||||
|
|
||||||
See `ruff --help` for more:
|
See `ruff --help` for more:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
ruff (v0.0.46)
|
ruff: An extremely fast Python linter.
|
||||||
An extremely fast Python linter.
|
|
||||||
|
|
||||||
USAGE:
|
Usage: ruff [OPTIONS] <FILES>...
|
||||||
ruff [OPTIONS] <FILES>...
|
|
||||||
|
|
||||||
ARGS:
|
Arguments:
|
||||||
<FILES>...
|
<FILES>...
|
||||||
|
|
||||||
OPTIONS:
|
Options:
|
||||||
--select <SELECT>...
|
-v, --verbose
|
||||||
List of error codes to enable
|
Enable verbose logging
|
||||||
--extend-select <EXTEND_SELECT>...
|
-q, --quiet
|
||||||
Like --select, but adds additional error codes on top of the selected ones
|
Disable all logging (but still exit with status code "1" upon detecting errors)
|
||||||
--ignore <IGNORE>...
|
-e, --exit-zero
|
||||||
List of error codes to ignore
|
Exit with status code "0", even upon detecting errors
|
||||||
--extend-ignore <EXTEND_IGNORE>...
|
-w, --watch
|
||||||
Like --ignore, but adds additional error codes on top of the ignored ones
|
Run in watch mode by re-running whenever files change
|
||||||
--exclude <EXCLUDE>...
|
-f, --fix
|
||||||
List of paths, used to exclude files and/or directories from checks
|
Attempt to automatically fix lint errors
|
||||||
--extend-exclude <EXTEND_EXCLUDE>...
|
-n, --no-cache
|
||||||
Like --exclude, but adds additional files and directories on top of the excluded ones
|
Disable cache reads
|
||||||
-e, --exit-zero
|
--select <SELECT>
|
||||||
Exit with status code "0", even upon detecting errors
|
List of error codes to enable
|
||||||
-f, --fix
|
--extend-select <EXTEND_SELECT>
|
||||||
Attempt to automatically fix lint errors
|
Like --select, but adds additional error codes on top of the selected ones
|
||||||
--format <FORMAT>
|
--ignore <IGNORE>
|
||||||
Output serialization format for error messages [default: text] [possible values: text,
|
List of error codes to ignore
|
||||||
json]
|
--extend-ignore <EXTEND_IGNORE>
|
||||||
-h, --help
|
Like --ignore, but adds additional error codes on top of the ignored ones
|
||||||
Print help information
|
--exclude <EXCLUDE>
|
||||||
-n, --no-cache
|
List of paths, used to exclude files and/or directories from checks
|
||||||
Disable cache reads
|
--extend-exclude <EXTEND_EXCLUDE>
|
||||||
--per-file-ignores <PER_FILE_IGNORES>...
|
Like --exclude, but adds additional files and directories on top of the excluded ones
|
||||||
List of mappings from file pattern to code to exclude
|
--per-file-ignores <PER_FILE_IGNORES>
|
||||||
-q, --quiet
|
List of mappings from file pattern to code to exclude
|
||||||
Disable all logging (but still exit with status code "1" upon detecting errors)
|
--format <FORMAT>
|
||||||
--add-noqa
|
Output serialization format for error messages [default: text] [possible values: text, json]
|
||||||
Enable automatic additions of noqa directives to failing lines
|
--show-files
|
||||||
--show-files
|
See the files ruff will be run against with the current settings
|
||||||
See the files ruff will be run against with the current settings
|
--show-settings
|
||||||
--show-settings
|
See ruff's settings
|
||||||
See ruff's settings
|
--add-noqa
|
||||||
-v, --verbose
|
Enable automatic additions of noqa directives to failing lines
|
||||||
Enable verbose logging
|
--dummy-variable-rgx <DUMMY_VARIABLE_RGX>
|
||||||
-V, --version
|
Regular expression matching the name of dummy variables
|
||||||
Print version information
|
-h, --help
|
||||||
-w, --watch
|
Print help information
|
||||||
Run in watch mode by re-running whenever files change
|
-V, --version
|
||||||
|
Print version information
|
||||||
```
|
```
|
||||||
|
|
||||||
### Excluding files
|
### Excluding files
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, ValueHint};
|
use clap::Parser;
|
||||||
use rustpython_parser::parser;
|
use rustpython_parser::parser;
|
||||||
|
|
||||||
use ruff::fs;
|
use ruff::fs;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[arg(value_hint = ValueHint::FilePath, required = true)]
|
#[arg(required = true)]
|
||||||
file: PathBuf,
|
file: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, ValueHint};
|
use clap::Parser;
|
||||||
use rustpython_parser::lexer;
|
use rustpython_parser::lexer;
|
||||||
|
|
||||||
use ruff::fs;
|
use ruff::fs;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[arg(value_hint = ValueHint::FilePath, required = true)]
|
#[arg(required = true)]
|
||||||
file: PathBuf,
|
file: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
43
src/main.rs
43
src/main.rs
|
|
@ -1,6 +1,5 @@
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
use regex::Regex;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
@ -8,11 +7,12 @@ use std::sync::mpsc::channel;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, ValueHint};
|
use clap::{command, Parser};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use notify::{raw_watcher, RecursiveMode, Watcher};
|
use notify::{raw_watcher, RecursiveMode, Watcher};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use regex::Regex;
|
||||||
use walkdir::DirEntry;
|
use walkdir::DirEntry;
|
||||||
|
|
||||||
use ::ruff::cache;
|
use ::ruff::cache;
|
||||||
|
|
@ -32,62 +32,61 @@ const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(name = CARGO_PKG_NAME)]
|
#[command(author, about = "ruff: An extremely fast Python linter.")]
|
||||||
#[clap(about = "An extremely fast Python linter.", long_about = None)]
|
#[command(version)]
|
||||||
#[clap(version)]
|
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[arg(value_hint = ValueHint::AnyPath, required = true)]
|
#[arg(required = true)]
|
||||||
files: Vec<PathBuf>,
|
files: Vec<PathBuf>,
|
||||||
/// Enable verbose logging.
|
/// Enable verbose logging.
|
||||||
#[arg(short, long, action)]
|
#[arg(short, long)]
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
/// Disable all logging (but still exit with status code "1" upon detecting errors).
|
/// Disable all logging (but still exit with status code "1" upon detecting errors).
|
||||||
#[arg(short, long, action)]
|
#[arg(short, long)]
|
||||||
quiet: bool,
|
quiet: bool,
|
||||||
/// Exit with status code "0", even upon detecting errors.
|
/// Exit with status code "0", even upon detecting errors.
|
||||||
#[arg(short, long, action)]
|
#[arg(short, long)]
|
||||||
exit_zero: bool,
|
exit_zero: bool,
|
||||||
/// Run in watch mode by re-running whenever files change.
|
/// Run in watch mode by re-running whenever files change.
|
||||||
#[arg(short, long, action)]
|
#[arg(short, long)]
|
||||||
watch: bool,
|
watch: bool,
|
||||||
/// Attempt to automatically fix lint errors.
|
/// Attempt to automatically fix lint errors.
|
||||||
#[arg(short, long, action)]
|
#[arg(short, long)]
|
||||||
fix: bool,
|
fix: bool,
|
||||||
/// Disable cache reads.
|
/// Disable cache reads.
|
||||||
#[arg(short, long, action)]
|
#[arg(short, long)]
|
||||||
no_cache: bool,
|
no_cache: bool,
|
||||||
/// List of error codes to enable.
|
/// List of error codes to enable.
|
||||||
#[arg(long, num_args = 1..)]
|
#[arg(long, value_delimiter = ',')]
|
||||||
select: Vec<CheckCode>,
|
select: Vec<CheckCode>,
|
||||||
/// Like --select, but adds additional error codes on top of the selected ones.
|
/// Like --select, but adds additional error codes on top of the selected ones.
|
||||||
#[arg(long, num_args = 1..)]
|
#[arg(long, value_delimiter = ',')]
|
||||||
extend_select: Vec<CheckCode>,
|
extend_select: Vec<CheckCode>,
|
||||||
/// List of error codes to ignore.
|
/// List of error codes to ignore.
|
||||||
#[arg(long, num_args = 1..)]
|
#[arg(long, value_delimiter = ',')]
|
||||||
ignore: Vec<CheckCode>,
|
ignore: Vec<CheckCode>,
|
||||||
/// Like --ignore, but adds additional error codes on top of the ignored ones.
|
/// Like --ignore, but adds additional error codes on top of the ignored ones.
|
||||||
#[arg(long, num_args = 1..)]
|
#[arg(long, value_delimiter = ',')]
|
||||||
extend_ignore: Vec<CheckCode>,
|
extend_ignore: Vec<CheckCode>,
|
||||||
/// List of paths, used to exclude files and/or directories from checks.
|
/// List of paths, used to exclude files and/or directories from checks.
|
||||||
#[arg(long, num_args = 1..)]
|
#[arg(long, value_delimiter = ',')]
|
||||||
exclude: Vec<String>,
|
exclude: Vec<String>,
|
||||||
/// Like --exclude, but adds additional files and directories on top of the excluded ones.
|
/// Like --exclude, but adds additional files and directories on top of the excluded ones.
|
||||||
#[arg(long, num_args = 1..)]
|
#[arg(long, value_delimiter = ',')]
|
||||||
extend_exclude: Vec<String>,
|
extend_exclude: Vec<String>,
|
||||||
/// List of mappings from file pattern to code to exclude
|
/// List of mappings from file pattern to code to exclude
|
||||||
#[arg(long, num_args = 1..)]
|
#[arg(long, value_delimiter = ',')]
|
||||||
per_file_ignores: Vec<StrCheckCodePair>,
|
per_file_ignores: Vec<StrCheckCodePair>,
|
||||||
/// Output serialization format for error messages.
|
/// Output serialization format for error messages.
|
||||||
#[arg(long, value_enum, default_value_t=SerializationFormat::Text)]
|
#[arg(long, value_enum, default_value_t=SerializationFormat::Text)]
|
||||||
format: SerializationFormat,
|
format: SerializationFormat,
|
||||||
/// See the files ruff will be run against with the current settings.
|
/// See the files ruff will be run against with the current settings.
|
||||||
#[arg(long, action)]
|
#[arg(long)]
|
||||||
show_files: bool,
|
show_files: bool,
|
||||||
/// See ruff's settings.
|
/// See ruff's settings.
|
||||||
#[arg(long, action)]
|
#[arg(long)]
|
||||||
show_settings: bool,
|
show_settings: bool,
|
||||||
/// Enable automatic additions of noqa directives to failing lines.
|
/// Enable automatic additions of noqa directives to failing lines.
|
||||||
#[arg(long, action)]
|
#[arg(long)]
|
||||||
add_noqa: bool,
|
add_noqa: bool,
|
||||||
/// Regular expression matching the name of dummy variables.
|
/// Regular expression matching the name of dummy variables.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue