Skip to content

Commit

Permalink
feat(config): add the includes field
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Jan 15, 2025
1 parent 4f07cc8 commit 53f9da6
Show file tree
Hide file tree
Showing 25 changed files with 276 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ impl Display for RageConfiguration<'_> {
.collect::<Vec<_>>()
.join(", ")
});
let includes = formatter_configuration.includes.map(|list| {
list.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(", ")
});
markup! (
{Section("Formatter")}
{KeyValuePair("Format with errors", markup!({DisplayOption(configuration.get_formatter_configuration().format_with_errors)}))}
Expand All @@ -265,6 +271,7 @@ impl Display for RageConfiguration<'_> {
{KeyValuePair("Bracket spacing", markup!({DisplayOption(formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Ignore", markup!({DisplayOption(ignore)}))}
{KeyValuePair("Include", markup!({DisplayOption(include)}))}
{KeyValuePair("Includes", markup!({DisplayOption(includes)}))}
).fmt(fmt)?;

let javascript_formatter_configuration =
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/execute/migrate/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl TryFrom<PrettierConfiguration> for biome_configuration::Configuration {
format_with_errors: Some(false.into()),
ignore: None,
include: None,
includes: None,
enabled: Some(true.into()),
// editorconfig support is intentionally set to true, because prettier always reads the editorconfig file
// see: https://github.com/prettier/prettier/issues/15255
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Formatter:
Bracket spacing: unset
Ignore: configuration-schema.json
Include: **/*.html, **/*.css, **/*.js, **/*.ts, **/*.tsx, **/*.jsx, **/*.json, **/*.md
Includes: unset
JavaScript Formatter:
Enabled: true
Expand Down
1 change: 1 addition & 0 deletions crates/biome_configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ biome_deserialize_macros = { workspace = true }
biome_diagnostics = { workspace = true, features = ["serde_ini", "oxc_resolver"] }
biome_flags = { workspace = true }
biome_formatter = { workspace = true, features = ["serde"] }
biome_glob = { workspace = true }
biome_graphql_analyze = { workspace = true }
biome_graphql_syntax = { workspace = true }
biome_html_formatter = { workspace = true, features = ["serde"] }
Expand Down
10 changes: 8 additions & 2 deletions crates/biome_configuration/src/analyzer/assist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ pub struct AssistConfiguration {
#[serde(skip_serializing_if = "Option::is_none")]
pub actions: Option<Actions>,

/// A list of Unix shell style patterns. The formatter will ignore files/folders that will
/// A list of Unix shell style patterns. Biome will ignore files/folders that will
/// match these patterns.
#[bpaf(hide, pure(Default::default()))]
#[serde(skip_serializing_if = "Option::is_none")]
pub ignore: Option<Vec<Box<str>>>,

/// A list of Unix shell style patterns. The formatter will include files/folders that will
/// A list of Unix shell style patterns. Biome will include files/folders that will
/// match these patterns.
#[bpaf(hide, pure(Default::default()))]
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<Box<str>>>,

/// A list of glob patterns. Biome will include files/folders that will
/// match these patterns.
#[bpaf(hide, pure(Default::default()))]
#[serde(skip_serializing_if = "Option::is_none")]
pub includes: Option<Vec<biome_glob::Glob>>,
}

impl AssistConfiguration {
Expand Down
48 changes: 48 additions & 0 deletions crates/biome_configuration/src/analyzer/assists/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
mod actions;

pub use crate::analyzer::assists::actions::*;
use biome_deserialize::StringSet;
use biome_deserialize_macros::{Deserializable, Merge, Partial};
use bpaf::Bpaf;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)]
#[partial(derive(Bpaf, Clone, Deserializable, Eq, Merge, PartialEq))]
#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))]
#[partial(serde(deny_unknown_fields, rename_all = "camelCase"))]
pub struct AssistsConfiguration {
/// Whether Biome should enable assists via LSP.
#[partial(bpaf(long("assists-enabled"), argument("true|false")))]
pub enabled: bool,

/// Whether Biome should fail in CLI if the assists were not applied to the code.
#[partial(bpaf(pure(Default::default()), optional, hide))]
pub actions: Actions,

/// A list of Unix shell style patterns. Biome will ignore files/folders that will
/// match these patterns.
#[partial(bpaf(hide))]
pub ignore: StringSet,

/// A list of Unix shell style patterns. Biome will include files/folders that will
/// match these patterns.
#[partial(bpaf(hide))]
pub include: StringSet,

/// A list of glob patterns. Biome will include files/folders that will
/// match these patterns.
#[partial(bpaf(pure(Default::default()), hide))]
pub includes: Vec<biome_glob::Glob>,
}

impl Default for AssistsConfiguration {
fn default() -> Self {
Self {
enabled: true,
actions: Actions::default(),
ignore: StringSet::default(),
include: StringSet::default(),
includes: Default::default(),
}
}
}
8 changes: 7 additions & 1 deletion crates/biome_configuration/src/analyzer/linter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ pub struct LinterConfiguration {
#[serde(skip_serializing_if = "Option::is_none")]
pub ignore: Option<Vec<Box<str>>>,

/// A list of Unix shell style patterns. The formatter will include files/folders that will
/// A list of Unix shell style patterns. The analyzer will include files/folders that will
/// match these patterns.
#[bpaf(hide, pure(Default::default()))]
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<Box<str>>>,

/// A list of glob patterns. The analyzer will handle only those files/folders that will
/// match these patterns.
#[bpaf(pure(Default::default()), hide)]
#[serde(skip_serializing_if = "Option::is_none")]
pub includes: Option<Vec<biome_glob::Glob>>,

/// An object where the keys are the names of the domains, and the values are boolean. `true` to turn-on the rules that
/// belong to that domain, `false` to turn them off
#[bpaf(hide, pure(Default::default()))]
Expand Down
14 changes: 6 additions & 8 deletions crates/biome_configuration/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ pub struct FormatterConfiguration {
#[bpaf(hide, pure(Default::default()))]
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<Box<str>>>,

/// A list of glob patterns. The formatter will include files/folders that will
/// match these patterns.
#[bpaf(pure(Default::default()), hide)]
#[serde(skip_serializing_if = "Option::is_none")]
pub includes: Option<Vec<biome_glob::Glob>>,
}

impl FormatterConfiguration {
Expand Down Expand Up @@ -121,12 +127,4 @@ impl FormatterConfiguration {
pub fn use_editorconfig_resolved(&self) -> bool {
self.use_editorconfig.unwrap_or_default().into()
}

pub fn ignore_resolved(&self) -> Vec<Box<str>> {
self.ignore.clone().unwrap_or_default()
}

pub fn include_resolved(&self) -> Vec<Box<str>> {
self.include.clone().unwrap_or_default()
}
}
6 changes: 6 additions & 0 deletions crates/biome_configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ pub struct FilesConfiguration {
#[bpaf(hide, pure(Default::default()))]
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<Box<str>>>,

/// A list of glob patterns. Biome will handle only those files/folders that will
/// match these patterns.
#[bpaf(hide, pure(Default::default()))]
#[serde(skip_serializing_if = "Option::is_none")]
pub includes: Option<Vec<biome_glob::Glob>>,
}

pub struct ConfigurationPayload {
Expand Down
50 changes: 50 additions & 0 deletions crates/biome_configuration/src/organize_imports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use biome_deserialize::StringSet;
use biome_deserialize_macros::{Deserializable, Merge, Partial};
use bpaf::Bpaf;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)]
#[partial(derive(Bpaf, Clone, Deserializable, Eq, Merge, PartialEq))]
#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))]
#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))]
pub struct OrganizeImports {
/// Enables the organization of imports
#[partial(bpaf(hide))]
pub enabled: bool,

/// A list of Unix shell style patterns. The import organizer will ignore files/folders that will
/// match these patterns.
#[partial(bpaf(hide))]
pub ignore: StringSet,

/// A list of Unix shell style patterns. The import organizer will include files/folders that will
/// match these patterns.
#[partial(bpaf(hide))]
pub include: StringSet,

/// A list of glob patterns. The import organizer will include files/folders that will
/// match these patterns.
#[partial(bpaf(pure(Default::default()), hide))]
pub includes: Vec<biome_glob::Glob>,
}

impl Default for OrganizeImports {
fn default() -> Self {
Self {
enabled: true,
ignore: Default::default(),
include: Default::default(),
includes: Default::default(),
}
}
}

impl PartialOrganizeImports {
pub const fn is_disabled(&self) -> bool {
matches!(self.enabled, Some(false))
}

pub const fn is_enabled(&self) -> bool {
!self.is_disabled()
}
}
9 changes: 7 additions & 2 deletions crates/biome_configuration/src/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ impl FromStr for Overrides {
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct OverridePattern {
/// A list of Unix shell style patterns. The formatter will ignore files/folders that will
/// A list of Unix shell style patterns. Biome will ignore files/folders that will
/// match these patterns.
#[serde(skip_serializing_if = "Option::is_none")]
pub ignore: Option<Vec<Box<str>>>,

/// A list of Unix shell style patterns. The formatter will include files/folders that will
/// A list of Unix shell style patterns. Biome will include files/folders that will
/// match these patterns.
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<Box<str>>>,

/// A list of glob patterns. Biome will include files/folders that will
/// match these patterns.
#[serde(skip_serializing_if = "Option::is_none")]
pub includes: Option<Vec<biome_glob::Glob>>,

/// Specific configuration for the JavaScript language
#[serde(skip_serializing_if = "Option::is_none")]
pub javascript: Option<JsConfiguration>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_service/tests/spec_tests.rs
expression: files_extraneous_field.json
snapshot_kind: text
---
files_extraneous_field.json:3:3 deserialize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand All @@ -19,3 +20,4 @@ files_extraneous_field.json:3:3 deserialize ━━━━━━━━━━━━
- ignoreUnknown
- ignore
- include
- includes
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ formatter_extraneous_field.json:3:3 deserialize ━━━━━━━━━━
- useEditorconfig
- ignore
- include
- includes
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ formatter_quote_style.json:3:9 deserialize ━━━━━━━━━━━━
- useEditorconfig
- ignore
- include
- includes
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ incorrect_key.json:4:4 deserialize ━━━━━━━━━━━━━━━

- ignore
- include
- includes
- javascript
- json
- css
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{
"ignore": [],
"include": [],
"includes": [],
"javascript": {},
"json": {},
"css": {}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_glob/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl biome_deserialize::Deserializable for Glob {
#[cfg(feature = "schema")]
impl schemars::JsonSchema for Glob {
fn schema_name() -> String {
"Regex".to_string()
"Glob".to_string()
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_js_parser/tests/spec_test.rs
expression: snapshot
snapshot_kind: text
---
## Input

Expand Down
1 change: 1 addition & 0 deletions crates/biome_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ biome_deserialize = { workspace = true }
biome_diagnostics = { workspace = true, features = ["camino"] }
biome_formatter = { workspace = true, features = ["serde"] }
biome_fs = { workspace = true, features = ["serde"] }
biome_glob = { workspace = true }
biome_graphql_analyze = { workspace = true }
biome_graphql_formatter = { workspace = true }
biome_graphql_parser = { workspace = true }
Expand Down
39 changes: 32 additions & 7 deletions crates/biome_service/src/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,52 @@ impl Projects {
};

let settings = &project_data.settings;
let (feature_included_files, feature_ignored_files) = match feature {
let (feature_includes_files, feature_included_files, feature_ignored_files) = match feature
{
FeatureKind::Format => {
let formatter = &settings.formatter;
(&formatter.included_files, &formatter.ignored_files)
(
&formatter.includes_files,
&formatter.included_files,
&formatter.ignored_files,
)
}
FeatureKind::Lint => {
let linter = &settings.linter;
(&linter.included_files, &linter.ignored_files)
(
&linter.includes_files,
&linter.included_files,
&linter.ignored_files,
)
}

FeatureKind::Assist => {
let assists = &settings.assist;
(&assists.included_files, &assists.ignored_files)
(
&assists.includes_files,
&assists.included_files,
&assists.ignored_files,
)
}
// TODO: enable once the configuration is available
FeatureKind::Search => return false, // There is no search-specific config.
FeatureKind::Debug => return false,
};
let is_feature_included = feature_included_files.is_empty()
|| is_dir(path)
|| feature_included_files.matches_path(path);

let mut is_feature_included = true;
if !feature_includes_files.is_empty() {
let candidate_path = biome_glob::CandidatePath::new(&path);
is_feature_included = if is_dir(path) {
candidate_path.matches_directory_with_exceptions(feature_includes_files)
} else {
candidate_path.matches_with_exceptions(feature_includes_files)
};
}
if !feature_included_files.is_empty() {
is_feature_included =
is_feature_included && (is_dir(path) || feature_included_files.matches_path(path));
};

!is_feature_included || feature_ignored_files.matches_path(path)
}
}
Loading

0 comments on commit 53f9da6

Please sign in to comment.