[ty] File inclusion and exclusion (#18498)

This commit is contained in:
Micha Reiser 2025-06-12 19:07:31 +02:00 committed by GitHub
parent 3c6c017950
commit 1f27d53fd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 2728 additions and 159 deletions

View file

@ -5,7 +5,9 @@ use clap::{ArgAction, ArgMatches, Error, Parser};
use ruff_db::system::SystemPathBuf;
use ty_project::combine::Combine;
use ty_project::metadata::options::{EnvironmentOptions, Options, SrcOptions, TerminalOptions};
use ty_project::metadata::value::{RangedValue, RelativePathBuf, ValueSource};
use ty_project::metadata::value::{
RangedValue, RelativeExcludePattern, RelativePathBuf, ValueSource,
};
use ty_python_semantic::lint;
#[derive(Debug, Parser)]
@ -148,6 +150,13 @@ pub(crate) struct CheckCommand {
respect_ignore_files: Option<bool>,
#[clap(long, overrides_with("respect_ignore_files"), hide = true)]
no_respect_ignore_files: bool,
/// Glob patterns for files to exclude from type checking.
///
/// Uses gitignore-style syntax to exclude files and directories from type checking.
/// Supports patterns like `tests/`, `*.tmp`, `**/__pycache__/**`.
#[arg(long, help_heading = "File selection")]
exclude: Option<Vec<String>>,
}
impl CheckCommand {
@ -195,6 +204,12 @@ impl CheckCommand {
}),
src: Some(SrcOptions {
respect_ignore_files,
exclude: self.exclude.map(|excludes| {
excludes
.iter()
.map(|exclude| RelativeExcludePattern::cli(exclude))
.collect()
}),
..SrcOptions::default()
}),
rules,