mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
Use tool specific function to perform exclude checks (#15486)
## Summary This PR creates separate functions to check whether the document path is excluded for linting or formatting. The main motivation is to avoid the double `Option` for the call sites and makes passing the correct settings simpler.
This commit is contained in:
parent
aefb607405
commit
bec8441cf5
5 changed files with 47 additions and 17 deletions
|
@ -6,6 +6,38 @@ use ruff_workspace::{FileResolverSettings, FormatterSettings};
|
|||
|
||||
use crate::edit::LanguageId;
|
||||
|
||||
/// Return `true` if the document at the given [`Path`] should be excluded from linting.
|
||||
pub(crate) fn is_document_excluded_for_linting(
|
||||
path: &Path,
|
||||
resolver_settings: &FileResolverSettings,
|
||||
linter_settings: &LinterSettings,
|
||||
language_id: Option<LanguageId>,
|
||||
) -> bool {
|
||||
is_document_excluded(
|
||||
path,
|
||||
resolver_settings,
|
||||
Some(linter_settings),
|
||||
None,
|
||||
language_id,
|
||||
)
|
||||
}
|
||||
|
||||
/// Return `true` if the document at the given [`Path`] should be excluded from formatting.
|
||||
pub(crate) fn is_document_excluded_for_formatting(
|
||||
path: &Path,
|
||||
resolver_settings: &FileResolverSettings,
|
||||
formatter_settings: &FormatterSettings,
|
||||
language_id: Option<LanguageId>,
|
||||
) -> bool {
|
||||
is_document_excluded(
|
||||
path,
|
||||
resolver_settings,
|
||||
None,
|
||||
Some(formatter_settings),
|
||||
language_id,
|
||||
)
|
||||
}
|
||||
|
||||
/// Return `true` if the document at the given [`Path`] should be excluded.
|
||||
///
|
||||
/// The tool-specific settings should be provided if the request for the document is specific to
|
||||
|
@ -16,7 +48,9 @@ use crate::edit::LanguageId;
|
|||
/// 1. Check for global `exclude` and `extend-exclude` options along with tool specific `exclude`
|
||||
/// option (`lint.exclude`, `format.exclude`).
|
||||
/// 2. Check for global `include` and `extend-include` options.
|
||||
pub(crate) fn is_document_excluded(
|
||||
/// 3. Check if the language ID is Python, in which case the document is included.
|
||||
/// 4. If none of the above conditions are met, the document is excluded.
|
||||
fn is_document_excluded(
|
||||
path: &Path,
|
||||
resolver_settings: &FileResolverSettings,
|
||||
linter_settings: Option<&LinterSettings>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue