mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-18 03:36:18 +00:00
Merge f1aeeaa40c into 3065f8dbbc
This commit is contained in:
commit
dc90ff05d9
2 changed files with 35 additions and 3 deletions
|
|
@ -4,7 +4,7 @@ use clap::builder::Styles;
|
||||||
use clap::builder::styling::{AnsiColor, Effects};
|
use clap::builder::styling::{AnsiColor, Effects};
|
||||||
use clap::error::ErrorKind;
|
use clap::error::ErrorKind;
|
||||||
use clap::{ArgAction, ArgMatches, Error, Parser};
|
use clap::{ArgAction, ArgMatches, Error, Parser};
|
||||||
use ruff_db::system::SystemPathBuf;
|
use ruff_db::system::{SystemPath, SystemPathBuf};
|
||||||
use ty_combine::Combine;
|
use ty_combine::Combine;
|
||||||
use ty_project::metadata::options::{EnvironmentOptions, Options, SrcOptions, TerminalOptions};
|
use ty_project::metadata::options::{EnvironmentOptions, Options, SrcOptions, TerminalOptions};
|
||||||
use ty_project::metadata::value::{RangedValue, RelativeGlobPattern, RelativePathBuf, ValueSource};
|
use ty_project::metadata::value::{RangedValue, RelativeGlobPattern, RelativePathBuf, ValueSource};
|
||||||
|
|
@ -177,7 +177,7 @@ pub(crate) struct CheckCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckCommand {
|
impl CheckCommand {
|
||||||
pub(crate) fn into_options(self) -> Options {
|
pub(crate) fn into_options(self, project_root: &SystemPath) -> Options {
|
||||||
let rules = if self.rules.is_empty() {
|
let rules = if self.rules.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -196,6 +196,36 @@ impl CheckCommand {
|
||||||
.no_respect_ignore_files
|
.no_respect_ignore_files
|
||||||
.then_some(false)
|
.then_some(false)
|
||||||
.or(self.respect_ignore_files);
|
.or(self.respect_ignore_files);
|
||||||
|
|
||||||
|
// When users explicitly specify directories on the command line, adds it as "dir/**/*"
|
||||||
|
// to include, ensuring their subfolders and subfiles are checked regardless of
|
||||||
|
// `pyproject.toml` original include configuration.
|
||||||
|
let include = {
|
||||||
|
let glob_patterns: Vec<RelativeGlobPattern> = {
|
||||||
|
self.paths
|
||||||
|
.iter()
|
||||||
|
.filter_map(|path| {
|
||||||
|
if !path.as_std_path().is_dir() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = SystemPath::absolute(path, project_root);
|
||||||
|
let path = path.strip_prefix(project_root).ok()?;
|
||||||
|
let path = path.to_string().replace('\\', "/");
|
||||||
|
let path = path.strip_suffix('/').unwrap_or(&path);
|
||||||
|
|
||||||
|
Some(RelativeGlobPattern::cli(format!("{path}/**/*")))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
|
if glob_patterns.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(RangedValue::cli(glob_patterns))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let options = Options {
|
let options = Options {
|
||||||
environment: Some(EnvironmentOptions {
|
environment: Some(EnvironmentOptions {
|
||||||
python_version: self
|
python_version: self
|
||||||
|
|
@ -225,6 +255,7 @@ impl CheckCommand {
|
||||||
exclude: self.exclude.map(|excludes| {
|
exclude: self.exclude.map(|excludes| {
|
||||||
RangedValue::cli(excludes.iter().map(RelativeGlobPattern::cli).collect())
|
RangedValue::cli(excludes.iter().map(RelativeGlobPattern::cli).collect())
|
||||||
}),
|
}),
|
||||||
|
include,
|
||||||
..SrcOptions::default()
|
..SrcOptions::default()
|
||||||
}),
|
}),
|
||||||
rules,
|
rules,
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,8 @@ fn run_check(args: CheckCommand) -> anyhow::Result<ExitStatus> {
|
||||||
|
|
||||||
project_metadata.apply_configuration_files(&system)?;
|
project_metadata.apply_configuration_files(&system)?;
|
||||||
|
|
||||||
let project_options_overrides = ProjectOptionsOverrides::new(config_file, args.into_options());
|
let project_options_overrides =
|
||||||
|
ProjectOptionsOverrides::new(config_file, args.into_options(&project_path));
|
||||||
project_metadata.apply_overrides(&project_options_overrides);
|
project_metadata.apply_overrides(&project_options_overrides);
|
||||||
|
|
||||||
let mut db = ProjectDatabase::new(project_metadata, system)?;
|
let mut db = ProjectDatabase::new(project_metadata, system)?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue