-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract exclusion-inclusion to a helper function
- Loading branch information
1 parent
83003dc
commit 5ad936f
Showing
6 changed files
with
62 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ mod edit; | |
mod fix; | ||
mod format; | ||
mod lint; | ||
mod resolve; | ||
mod server; | ||
mod session; | ||
mod trace; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::path::Path; | ||
|
||
use ruff_linter::settings::LinterSettings; | ||
use ruff_workspace::resolver::{match_any_exclusion, match_any_inclusion}; | ||
use ruff_workspace::{FileResolverSettings, FormatterSettings}; | ||
|
||
/// 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 | ||
/// that tool. For example, a diagnostics request should provide the linter settings while the | ||
/// formatting request should provide the formatter settings. | ||
/// | ||
/// The logic for the resolution considers both inclusion and exclusion and is as follows: | ||
/// 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( | ||
path: &Path, | ||
resolver_settings: &FileResolverSettings, | ||
linter_settings: Option<&LinterSettings>, | ||
formatter_settings: Option<&FormatterSettings>, | ||
) -> bool { | ||
if let Some(exclusion) = match_any_exclusion( | ||
path, | ||
&resolver_settings.exclude, | ||
&resolver_settings.extend_exclude, | ||
linter_settings.map(|s| &*s.exclude), | ||
formatter_settings.map(|s| &*s.exclude), | ||
) { | ||
tracing::debug!("Ignored path via `{}`: {}", exclusion, path.display()); | ||
return true; | ||
} | ||
|
||
if let Some(inclusion) = match_any_inclusion( | ||
path, | ||
&resolver_settings.include, | ||
&resolver_settings.extend_include, | ||
) { | ||
tracing::debug!("Included path via `{}`: {}", inclusion, path.display()); | ||
false | ||
} else { | ||
// Path is excluded by not being in the inclusion set. | ||
true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters