Skip to content

Commit 869a954

Browse files
authored
Root exclusions in the server to project root (#16043)
## Summary fixes: #16041 ## Test Plan Using the [project](https://github.com/bwcc-clan/polebot) in the linked issue: Notice how the project "polebot" is in the "play" directory which is included in the `exclude` setting as: ```toml exclude = ["play"] ``` **Before this fix** ``` DEBUG ruff:worker:0 ruff_server::resolve: Ignored path via `exclude`: /private/tmp/ruff-test/play/polebot/src/utils/log_tools.py ``` **After this fix** ``` DEBUG ruff:worker:2 ruff_server::resolve: Included path via `include`: /private/tmp/ruff-test/play/polebot/src/utils/log_tools.py ``` I also updated the same project to remove the "play" directory from the `exclude` setting and made sure that anything under the `polebot/play` directory is included: ``` DEBUG ruff:worker:4 ruff_server::resolve: Included path via `include`: /private/tmp/ruff-test/play/polebot/play/test.py ``` And, excluded when I add the directory back: ``` DEBUG ruff:worker:2 ruff_server::resolve: Ignored path via `exclude`: /private/tmp/ruff-test/play/polebot/play/test.py ```
1 parent cc0a5dd commit 869a954

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

crates/ruff_server/src/resolve.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,15 @@ fn is_document_excluded(
5959
) -> bool {
6060
if let Some(exclusion) = match_any_exclusion(
6161
path,
62-
&resolver_settings.exclude,
63-
&resolver_settings.extend_exclude,
62+
resolver_settings,
6463
linter_settings.map(|s| &*s.exclude),
6564
formatter_settings.map(|s| &*s.exclude),
6665
) {
6766
tracing::debug!("Ignored path via `{}`: {}", exclusion, path.display());
6867
return true;
6968
}
7069

71-
if let Some(inclusion) = match_any_inclusion(
72-
path,
73-
&resolver_settings.include,
74-
&resolver_settings.extend_include,
75-
) {
70+
if let Some(inclusion) = match_any_inclusion(path, resolver_settings) {
7671
tracing::debug!("Included path via `{}`: {}", inclusion, path.display());
7772
false
7873
} else if let Some(LanguageId::Python) = language_id {

crates/ruff_workspace/src/resolver.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use ruff_linter::package::PackageRoot;
2323
use ruff_linter::packaging::is_package;
2424

2525
use crate::configuration::Configuration;
26-
use crate::pyproject;
2726
use crate::pyproject::settings_toml;
2827
use crate::settings::Settings;
28+
use crate::{pyproject, FileResolverSettings};
2929

3030
/// The configuration information from a `pyproject.toml` file.
3131
#[derive(Debug)]
@@ -778,19 +778,18 @@ impl std::fmt::Display for ExclusionKind {
778778
/// any of the exclusion criteria.
779779
pub fn match_any_exclusion(
780780
path: &Path,
781-
exclude: &GlobSet,
782-
extend_exclude: &GlobSet,
781+
resolver_settings: &FileResolverSettings,
783782
lint_exclude: Option<&GlobSet>,
784783
format_exclude: Option<&GlobSet>,
785784
) -> Option<ExclusionKind> {
786785
for path in path.ancestors() {
787786
if let Some(basename) = path.file_name() {
788787
let path = Candidate::new(path);
789788
let basename = Candidate::new(basename);
790-
if match_candidate_exclusion(&path, &basename, exclude) {
789+
if match_candidate_exclusion(&path, &basename, &resolver_settings.exclude) {
791790
return Some(ExclusionKind::Exclude);
792791
}
793-
if match_candidate_exclusion(&path, &basename, extend_exclude) {
792+
if match_candidate_exclusion(&path, &basename, &resolver_settings.extend_exclude) {
794793
return Some(ExclusionKind::ExtendExclude);
795794
}
796795
if let Some(lint_exclude) = lint_exclude {
@@ -804,6 +803,11 @@ pub fn match_any_exclusion(
804803
}
805804
}
806805
}
806+
if path == resolver_settings.project_root {
807+
// Bail out; we'd end up past the project root on the next iteration
808+
// (excludes etc. are thus "rooted" to the project).
809+
break;
810+
}
807811
}
808812
None
809813
}
@@ -829,12 +833,11 @@ impl std::fmt::Display for InclusionKind {
829833
/// criteria.
830834
pub fn match_any_inclusion(
831835
path: &Path,
832-
include: &GlobSet,
833-
extend_include: &GlobSet,
836+
resolver_settings: &FileResolverSettings,
834837
) -> Option<InclusionKind> {
835-
if include.is_match(path) {
838+
if resolver_settings.include.is_match(path) {
836839
Some(InclusionKind::Include)
837-
} else if extend_include.is_match(path) {
840+
} else if resolver_settings.extend_include.is_match(path) {
838841
Some(InclusionKind::ExtendInclude)
839842
} else {
840843
None

0 commit comments

Comments
 (0)