Skip to content

Commit

Permalink
fix(config): don't ignore 'include' when 'ignore' is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Jan 12, 2024
1 parent ca94eb0 commit ba034b5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Read our [guidelines for writing a good changelog entry](https:/biom

- Fix [1440](https:/biomejs/biome/issues/1440), a case where `extends` and `overrides` weren't correctly emitting the final configuration. Contributed by @arendjr

- Correctly handle `include` when `ignore` is set (#1468). Contributed by @Conaclos

Previously, Biome ignored `include` if `ignore` was set.
Now, Biome check both `include` and `ignore`.
A file is processed if it is included and not ignored.
If `include` is not set all files are considered included.

### Editors

### Formatter
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_service/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ fn to_file_settings(
included_files: to_matcher(
working_directory,
config.include.as_ref(),
vcs_config_path,
gitignore_matches,
None,
&[],
)?,
ignore_unknown: config.ignore_unknown.unwrap_or_default(),
})
Expand Down
40 changes: 14 additions & 26 deletions crates/biome_service/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,9 @@ impl WorkspaceServer {
/// Check whether a file is ignored in the top-level config `files.ignore`/`files.include`
fn is_ignored_by_top_level_config(&self, path: &Path) -> bool {
let settings = self.settings();

if !settings.as_ref().files.ignored_files.is_empty() {
return settings.as_ref().files.ignored_files.matches_path(path);
} else if !settings.as_ref().files.included_files.is_empty() {
return !settings.as_ref().files.included_files.matches_path(path);
}

false
let is_included = settings.as_ref().files.included_files.is_empty()
|| settings.as_ref().files.included_files.matches_path(path);
!is_included || settings.as_ref().files.ignored_files.matches_path(path)
}
}

Expand Down Expand Up @@ -278,26 +273,19 @@ impl Workspace for WorkspaceServer {
return Ok(false);
}

let excluded_by_override = settings.as_ref().override_settings.is_path_excluded(path);
let included_by_override = settings.as_ref().override_settings.is_path_included(path);

// Overrides have top priority
if let Some(excluded_by_override) = excluded_by_override {
if excluded_by_override {
return Ok(true);
}
let excluded_by_override = settings.as_ref().override_settings.is_path_excluded(path);
if excluded_by_override.unwrap_or_default() {
return Ok(true);
}

if let Some(included_by_override) = included_by_override {
if included_by_override {
return Ok(!included_by_override);
}
let included_by_override = settings.as_ref().override_settings.is_path_included(path);
if included_by_override.unwrap_or_default() {
return Ok(false);
}

let (ignored_files, included_files) = match params.feature {
FeatureName::Format => {
let formatter = &settings.as_ref().formatter;

(&formatter.ignored_files, &formatter.included_files)
}
FeatureName::Lint => {
Expand All @@ -313,11 +301,11 @@ impl Workspace for WorkspaceServer {
}
};

if !ignored_files.is_empty() {
if ignored_files.matches_path(path) {
return Ok(true);
}
} else if !included_files.is_empty() && included_files.matches_path(path) {
// Tool include/ignore have priority over (global) files include/ignore
if ignored_files.matches_path(path) {
return Ok(true);
}
if !included_files.is_empty() && included_files.matches_path(path) {
return Ok(false);
}

Expand Down
7 changes: 7 additions & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Read our [guidelines for writing a good changelog entry](https:/biom

- Fix [1440](https:/biomejs/biome/issues/1440), a case where `extends` and `overrides` weren't correctly emitting the final configuration. Contributed by @arendjr

- Correctly handle `include` when `ignore` is set (#1468). Contributed by @Conaclos

Previously, Biome ignored `include` if `ignore` was set.
Now, Biome check both `include` and `ignore`.
A file is processed if it is included and not ignored.
If `include` is not set all files are considered included.

### Editors

### Formatter
Expand Down

0 comments on commit ba034b5

Please sign in to comment.