mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-26 01:48:17 +00:00
include .pyw files by default when linting and formatting (#20458)
- Adds test cases exercising file selection by extension with `--preview` enabled and disabled. - Adds `INCLUDE_PREVIEW` with file patterns including `*.pyw`. - In global preview mode, default configuration selects patterns from `INCLUDE_PREVIEW`. - Manually tested ruff server with local vscode for both formatting and linting of a `.pyw` file. Closes https://github.com/astral-sh/ruff/issues/13246
This commit is contained in:
parent
fcc76bb7b2
commit
83f80effec
7 changed files with 535 additions and 7 deletions
|
|
@ -55,7 +55,8 @@ use crate::options::{
|
|||
PydoclintOptions, PydocstyleOptions, PyflakesOptions, PylintOptions, RuffOptions,
|
||||
};
|
||||
use crate::settings::{
|
||||
EXCLUDE, FileResolverSettings, FormatterSettings, INCLUDE, LineEnding, Settings,
|
||||
EXCLUDE, FileResolverSettings, FormatterSettings, INCLUDE, INCLUDE_PREVIEW, LineEnding,
|
||||
Settings,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
|
@ -274,9 +275,14 @@ impl Configuration {
|
|||
extend_exclude: FilePatternSet::try_from_iter(self.extend_exclude)?,
|
||||
extend_include: FilePatternSet::try_from_iter(self.extend_include)?,
|
||||
force_exclude: self.force_exclude.unwrap_or(false),
|
||||
include: FilePatternSet::try_from_iter(
|
||||
self.include.unwrap_or_else(|| INCLUDE.to_vec()),
|
||||
)?,
|
||||
include: match global_preview {
|
||||
PreviewMode::Disabled => FilePatternSet::try_from_iter(
|
||||
self.include.unwrap_or_else(|| INCLUDE.to_vec()),
|
||||
)?,
|
||||
PreviewMode::Enabled => FilePatternSet::try_from_iter(
|
||||
self.include.unwrap_or_else(|| INCLUDE_PREVIEW.to_vec()),
|
||||
)?,
|
||||
},
|
||||
respect_gitignore: self.respect_gitignore.unwrap_or(true),
|
||||
project_root: project_root.to_path_buf(),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ pub struct Options {
|
|||
///
|
||||
/// For more information on the glob syntax, refer to the [`globset` documentation](https://docs.rs/globset/latest/globset/#syntax).
|
||||
#[option(
|
||||
default = r#"["*.py", "*.pyi", "*.ipynb", "**/pyproject.toml"]"#,
|
||||
default = r#"["*.py", "*.pyi", "*.pyw", "*.ipynb", "**/pyproject.toml"]"#,
|
||||
value_type = "list[str]",
|
||||
example = r#"
|
||||
include = ["*.py"]
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ impl From<ConfigurationOrigin> for Relativity {
|
|||
}
|
||||
}
|
||||
|
||||
/// Find all Python (`.py`, `.pyi` and `.ipynb` files) in a set of paths.
|
||||
/// Find all Python (`.py`, `.pyi`, `.pyw`, and `.ipynb` files) in a set of paths.
|
||||
pub fn python_files_in_path<'a>(
|
||||
paths: &[PathBuf],
|
||||
pyproject_config: &'a PyprojectConfig,
|
||||
|
|
|
|||
|
|
@ -144,6 +144,13 @@ pub(crate) static INCLUDE: &[FilePattern] = &[
|
|||
FilePattern::Builtin("*.ipynb"),
|
||||
FilePattern::Builtin("**/pyproject.toml"),
|
||||
];
|
||||
pub(crate) static INCLUDE_PREVIEW: &[FilePattern] = &[
|
||||
FilePattern::Builtin("*.py"),
|
||||
FilePattern::Builtin("*.pyi"),
|
||||
FilePattern::Builtin("*.pyw"),
|
||||
FilePattern::Builtin("*.ipynb"),
|
||||
FilePattern::Builtin("**/pyproject.toml"),
|
||||
];
|
||||
|
||||
impl FileResolverSettings {
|
||||
fn new(project_root: &Path) -> Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue