Skip to content

Commit

Permalink
WIP: formatter, linter, organize_imports enabled calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Jul 5, 2024
1 parent 22a8d41 commit 5eedd9f
Show file tree
Hide file tree
Showing 13 changed files with 391 additions and 322 deletions.
18 changes: 13 additions & 5 deletions crates/biome_configuration/src/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ use std::{
};

/// A `bool` type wrapper with a configurable default value (`true` or `false`)
///
/// The const generic indicates the default bool value of this wrapper type
#[derive(
Clone, Copy, Eq, Merge, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
)]
pub struct Bool<const D: bool = false>(pub bool);
pub struct Bool<const D: bool>(pub bool);

impl<const D: bool> Bool<D> {
pub fn value(&self) -> bool {
self.0
}
}

impl Default for Bool<true> {
fn default() -> Self {
Expand Down Expand Up @@ -42,7 +50,7 @@ impl<const D: bool> Deserializable for Bool<D> {

impl<const D: bool> fmt::Debug for Bool<D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
self.value().fmt(f)
}
}

Expand All @@ -54,18 +62,18 @@ impl<const D: bool> From<bool> for Bool<D> {

impl<const D: bool> From<Bool<D>> for bool {
fn from(value: Bool<D>) -> Self {
value.0
value.value()
}
}

impl From<Bool<false>> for Bool<true> {
fn from(value: Bool<false>) -> Self {
Self(value.0)
Self(value.value())
}
}

impl From<Bool<true>> for Bool<false> {
fn from(value: Bool<true>) -> Self {
Self(value.0)
Self(value.value())
}
}
9 changes: 6 additions & 3 deletions crates/biome_configuration/src/css.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bool::Bool, formatter::FormatterEnabled, linter::LinterEnabled, PlainIndentStyle};
use crate::{bool::Bool, PlainIndentStyle};
use biome_deserialize_macros::{Deserializable, Merge};
use biome_formatter::{IndentWidth, LineEnding, LineWidth, QuoteStyle};
use bpaf::Bpaf;
Expand Down Expand Up @@ -43,6 +43,8 @@ pub struct CssParserConfiguration {
pub css_modules: Option<CssModulesEnabled>,
}

pub type CssFormatterEnabled = Bool<false>;

/// Options that changes how the CSS formatter behaves
#[derive(
Bpaf, Clone, Debug, Default, Deserializable, Deserialize, Eq, Merge, PartialEq, Serialize,
Expand All @@ -52,7 +54,7 @@ pub struct CssParserConfiguration {
pub struct CssFormatterConfiguration {
/// Control the formatter for CSS (and its super languages) files.
#[bpaf(long("css-formatter-enabled"), argument("true|false"))]
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<CssFormatterEnabled>,

/// The indent style applied to CSS (and its super languages) files.
#[bpaf(long("css-formatter-indent-style"), argument("tab|space"))]
Expand Down Expand Up @@ -85,6 +87,7 @@ impl CssFormatterConfiguration {
}
}

pub type CssLinterEnabled = Bool<false>;
/// Options that changes how the CSS linter behaves
#[derive(
Bpaf, Clone, Debug, Default, Deserializable, Deserialize, Eq, Merge, PartialEq, Serialize,
Expand All @@ -94,7 +97,7 @@ impl CssFormatterConfiguration {
pub struct CssLinterConfiguration {
/// Control the linter for CSS (and its super languages) files.
#[bpaf(long("css-linter-enabled"), argument("true|false"))]
pub enabled: Option<LinterEnabled>,
pub enabled: Option<CssLinterEnabled>,
}

impl CssLinterConfiguration {
Expand Down
6 changes: 4 additions & 2 deletions crates/biome_configuration/src/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{formatter::FormatterEnabled, PlainIndentStyle};
use crate::{bool::Bool, PlainIndentStyle};
use biome_deserialize_macros::{Deserializable, Merge};
use biome_formatter::{BracketSpacing, IndentWidth, LineEnding, LineWidth, QuoteStyle};
use bpaf::Bpaf;
Expand All @@ -16,6 +16,8 @@ pub struct GraphqlConfiguration {
pub formatter: Option<GraphqlFormatterConfiguration>,
}

pub type GraphqlFormatterEnabled = Bool<false>;

/// Options that changes how the GraphQL formatter behaves
#[derive(
Bpaf, Clone, Debug, Default, Deserializable, Deserialize, Eq, Merge, PartialEq, Serialize,
Expand All @@ -25,7 +27,7 @@ pub struct GraphqlConfiguration {
pub struct GraphqlFormatterConfiguration {
/// Control the formatter for GraphQL files.
#[bpaf(long("graphql-formatter-enabled"), argument("true|false"))]
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<GraphqlFormatterEnabled>,

/// The indent style applied to GraphQL files.
#[bpaf(long("graphql-formatter-indent-style"), argument("tab|space"))]
Expand Down
5 changes: 3 additions & 2 deletions crates/biome_configuration/src/javascript/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bool::Bool, formatter::FormatterEnabled, PlainIndentStyle};
use crate::{bool::Bool, PlainIndentStyle};
use biome_deserialize_macros::{Deserializable, Merge};
use biome_formatter::{
AttributePosition, BracketSpacing, IndentWidth, LineEnding, LineWidth, QuoteStyle,
Expand All @@ -9,6 +9,7 @@ use biome_js_formatter::context::{
use bpaf::Bpaf;
use serde::{Deserialize, Serialize};

pub type JsFormatterEnabled = Bool<true>;
pub type BracketSameLineEnabled = Bool<false>;

/// Formatting options specific to the JavaScript files
Expand All @@ -20,7 +21,7 @@ pub type BracketSameLineEnabled = Bool<false>;
pub struct JsFormatterConfiguration {
/// Control the formatter for JavaScript (and its super languages) files.
#[bpaf(long("javascript-formatter-enabled"), argument("true|false"))]
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<JsFormatterEnabled>,

/// The type of quotes used in JSX. Defaults to double.
#[bpaf(long("jsx-quote-style"), argument("double|single"))]
Expand Down
6 changes: 4 additions & 2 deletions crates/biome_configuration/src/javascript/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod formatter;
use crate::{bool::Bool, linter::LinterEnabled};
use crate::bool::Bool;
use biome_deserialize::StringSet;
use biome_deserialize_macros::{Deserializable, Merge};
use bpaf::Bpaf;
Expand Down Expand Up @@ -99,6 +99,8 @@ impl FromStr for JsxRuntime {
}
}

pub type JsLinterEnabled = Bool<true>;

/// Linter options specific to the JavaScript linter
#[derive(
Bpaf, Clone, Debug, Default, Deserializable, Deserialize, Eq, Merge, PartialEq, Serialize,
Expand All @@ -108,7 +110,7 @@ impl FromStr for JsxRuntime {
pub struct JsLinterConfiguration {
/// Control the linter for JavaScript (and its super languages) files.
#[bpaf(long("javascript-linter-enabled"), argument("true|false"))]
pub enabled: Option<LinterEnabled>,
pub enabled: Option<JsLinterEnabled>,
}

impl JsLinterConfiguration {
Expand Down
10 changes: 7 additions & 3 deletions crates/biome_configuration/src/json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{bool::Bool, formatter::FormatterEnabled, linter::LinterEnabled, PlainIndentStyle};
use crate::{bool::Bool, PlainIndentStyle};
use biome_deserialize_macros::{Deserializable, Merge};
use biome_formatter::{IndentWidth, LineEnding, LineWidth};
use biome_json_formatter::context::TrailingCommas;
Expand Down Expand Up @@ -44,6 +44,8 @@ pub struct JsonParserConfiguration {
pub allow_trailing_commas: Option<AllowTrailingCommasEnabled>,
}

pub type JsonFormatterEnabled = Bool<true>;

#[derive(
Bpaf, Clone, Debug, Default, Deserializable, Deserialize, Eq, Merge, PartialEq, Serialize,
)]
Expand All @@ -52,7 +54,7 @@ pub struct JsonParserConfiguration {
pub struct JsonFormatterConfiguration {
/// Control the formatter for JSON (and its super languages) files.
#[bpaf(long("json-formatter-enabled"), argument("true|false"))]
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<JsonFormatterEnabled>,

/// The indent style applied to JSON (and its super languages) files.
#[bpaf(long("json-formatter-indent-style"), argument("tab|space"))]
Expand Down Expand Up @@ -90,6 +92,8 @@ impl JsonFormatterConfiguration {
}
}

pub type JsonLinterEnabled = Bool<true>;

/// Linter options specific to the JSON linter
#[derive(
Bpaf, Clone, Debug, Default, Deserializable, Deserialize, Eq, Merge, PartialEq, Serialize,
Expand All @@ -99,7 +103,7 @@ impl JsonFormatterConfiguration {
pub struct JsonLinterConfiguration {
/// Control the linter for JSON (and its super languages) files.
#[bpaf(long("json-linter-enabled"), argument("true|false"), optional)]
pub enabled: Option<LinterEnabled>,
pub enabled: Option<JsonLinterEnabled>,
}

impl JsonLinterConfiguration {
Expand Down
16 changes: 9 additions & 7 deletions crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use biome_analyze::{
AnalysisFilter, AnalyzerConfiguration, AnalyzerOptions, ControlFlow, Never,
RuleCategoriesBuilder, RuleCategory, RuleError,
};
use biome_configuration::css::{AllowWrongLineCommentsEnabled, CssModulesEnabled};
use biome_configuration::formatter::FormatterEnabled;
use biome_configuration::linter::LinterEnabled;
use biome_configuration::organize_imports::OrganizeImportsEnabled;
use biome_configuration::bool::Bool;
use biome_configuration::css::{
AllowWrongLineCommentsEnabled, CssFormatterEnabled, CssLinterEnabled, CssModulesEnabled,
};
use biome_css_analyze::analyze;
use biome_css_formatter::context::CssFormatOptions;
use biome_css_formatter::format_node;
Expand Down Expand Up @@ -56,7 +56,7 @@ pub struct CssFormatterSettings {
pub indent_width: Option<IndentWidth>,
pub indent_style: Option<IndentStyle>,
pub quote_style: Option<QuoteStyle>,
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<CssFormatterEnabled>,
}

impl CssFormatterSettings {
Expand All @@ -68,7 +68,7 @@ impl CssFormatterSettings {
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CssLinterSettings {
pub enabled: Option<LinterEnabled>,
pub enabled: Option<CssLinterEnabled>,
}

impl CssLinterSettings {
Expand All @@ -77,10 +77,12 @@ impl CssLinterSettings {
}
}

pub type CssOrganizeImportsEnabled = Bool<false>;

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CssOrganizeImportsSettings {
pub enabled: Option<OrganizeImportsEnabled>,
pub enabled: Option<CssOrganizeImportsEnabled>,
}

impl ServiceLanguage for CssLanguage {
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_service/src/file_handlers/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use biome_analyze::{
AnalysisFilter, AnalyzerConfiguration, AnalyzerOptions, ControlFlow, Never,
RuleCategoriesBuilder, RuleCategory, RuleError,
};
use biome_configuration::formatter::FormatterEnabled;
use biome_configuration::graphql::GraphqlFormatterEnabled;
use biome_diagnostics::{category, Applicability, Diagnostic, DiagnosticExt, Severity};
use biome_formatter::{
BracketSpacing, FormatError, IndentStyle, IndentWidth, LineEnding, LineWidth, Printed,
Expand All @@ -38,7 +38,7 @@ use tracing::{debug_span, error, info, trace, trace_span};
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct GraphqlFormatterSettings {
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<GraphqlFormatterEnabled>,
pub line_ending: Option<LineEnding>,
pub line_width: Option<LineWidth>,
pub indent_width: Option<IndentWidth>,
Expand Down
16 changes: 9 additions & 7 deletions crates/biome_service/src/file_handlers/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use biome_analyze::{
QueryMatch, Queryable, RegistryVisitor, RuleCategoriesBuilder, RuleCategory, RuleError,
RuleFilter, RuleGroup,
};
use biome_configuration::formatter::FormatterEnabled;
use biome_configuration::javascript::{JsxRuntime, UnsafeParameterDecoratorsEnabled};
use biome_configuration::linter::LinterEnabled;
use biome_configuration::organize_imports::OrganizeImportsEnabled;
use biome_configuration::bool::Bool;
use biome_configuration::javascript::{
JsFormatterEnabled, JsLinterEnabled, JsxRuntime, UnsafeParameterDecoratorsEnabled,
};
use biome_diagnostics::{category, Applicability, Diagnostic, DiagnosticExt, Severity};
use biome_formatter::{
AttributePosition, BracketSpacing, FormatError, IndentStyle, IndentWidth, LineEnding,
Expand Down Expand Up @@ -69,7 +69,7 @@ pub struct JsFormatterSettings {
pub line_width: Option<LineWidth>,
pub indent_width: Option<IndentWidth>,
pub indent_style: Option<IndentStyle>,
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<JsFormatterEnabled>,
pub attribute_position: Option<AttributePosition>,
}

Expand All @@ -88,7 +88,7 @@ pub struct JsParserSettings {
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct JsLinterSettings {
pub enabled: Option<LinterEnabled>,
pub enabled: Option<JsLinterEnabled>,
}

impl JsLinterSettings {
Expand All @@ -97,10 +97,12 @@ impl JsLinterSettings {
}
}

pub type JsOrganizeImportsEnabled = Bool<true>;

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct JsOrganizeImportsSettings {
pub enabled: Option<OrganizeImportsEnabled>,
pub enabled: Option<JsOrganizeImportsEnabled>,
}

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
Expand Down
16 changes: 9 additions & 7 deletions crates/biome_service/src/file_handlers/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use biome_analyze::{
AnalysisFilter, AnalyzerConfiguration, AnalyzerOptions, ControlFlow, GroupCategory, Never,
Queryable, RegistryVisitor, RuleCategoriesBuilder, RuleCategory, RuleFilter, RuleGroup,
};
use biome_configuration::formatter::FormatterEnabled;
use biome_configuration::json::{AllowCommentsEnabled, AllowTrailingCommasEnabled};
use biome_configuration::linter::LinterEnabled;
use biome_configuration::organize_imports::OrganizeImportsEnabled;
use biome_configuration::bool::Bool;
use biome_configuration::json::{
AllowCommentsEnabled, AllowTrailingCommasEnabled, JsonFormatterEnabled, JsonLinterEnabled,
};
use biome_configuration::Configuration;
use biome_deserialize::json::deserialize_from_json_ast;
use biome_diagnostics::{category, Diagnostic, DiagnosticExt, Severity};
Expand All @@ -49,7 +49,7 @@ pub struct JsonFormatterSettings {
pub indent_width: Option<IndentWidth>,
pub indent_style: Option<IndentStyle>,
pub trailing_commas: Option<TrailingCommas>,
pub enabled: Option<FormatterEnabled>,
pub enabled: Option<JsonFormatterEnabled>,
}

impl JsonFormatterSettings {
Expand All @@ -68,7 +68,7 @@ pub struct JsonParserSettings {
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct JsonLinterSettings {
pub enabled: Option<LinterEnabled>,
pub enabled: Option<JsonLinterEnabled>,
}

impl JsonLinterSettings {
Expand All @@ -77,10 +77,12 @@ impl JsonLinterSettings {
}
}

pub type JsonOrganizeImportsEnabled = Bool<true>;

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct JsonOrganizeImportsSettings {
pub enabled: Option<OrganizeImportsEnabled>,
pub enabled: Option<JsonOrganizeImportsEnabled>,
}

impl ServiceLanguage for JsonLanguage {
Expand Down
5 changes: 5 additions & 0 deletions crates/biome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ pub use javascript::JsFormatterSettings;
use std::ffi::OsStr;
use std::path::Path;

pub use crate::file_handlers::{
css::CssOrganizeImportsEnabled, javascript::JsOrganizeImportsEnabled,
json::JsonOrganizeImportsEnabled,
};

mod astro;
mod css;
mod graphql;
Expand Down
Loading

0 comments on commit 5eedd9f

Please sign in to comment.