Skip to content

Commit

Permalink
WIP: fix rage and migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Jul 4, 2024
1 parent c784c61 commit 3494506
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 66 deletions.
14 changes: 8 additions & 6 deletions crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub(crate) struct CiCommandPayload {
pub(crate) linter_enabled: Option<bool>,
pub(crate) organize_imports_enabled: Option<bool>,
pub(crate) paths: Vec<OsString>,
// TODO(zzwu): What's the purpose of this option?
pub(crate) configuration: Option<Configuration>,
pub(crate) cli_options: CliOptions,
pub(crate) changed: bool,
Expand Down Expand Up @@ -74,13 +75,14 @@ pub(crate) fn ci(session: CliSession, payload: CiCommandPayload) -> Result<(), C
organize_imports.enabled = organize_imports_enabled.map(Into::into);
}

// TODO(zzwu): We shouldn't bail because overrides can re-enable these options
// no point in doing the traversal if all the checks have been disabled
if fs_configuration.is_formatter_disabled()
&& fs_configuration.is_linter_disabled()
&& fs_configuration.is_organize_imports_disabled()
{
return Err(CliDiagnostic::incompatible_end_configuration("Formatter, linter and organize imports are disabled, can't perform the command. This is probably and error."));
}
// if !fs_configuration.is_formatter_enabled()
// && !fs_configuration.is_linter_enabled()
// && !fs_configuration.is_organize_imports_enabled()
// {
// return Err(CliDiagnostic::incompatible_end_configuration("Formatter, linter and organize imports are disabled, can't perform the command. This is probably and error."));
// }

if let Some(mut configuration) = configuration {
if let Some(linter) = configuration.linter.as_mut() {
Expand Down
87 changes: 54 additions & 33 deletions crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,84 +200,105 @@ impl Display for RageConfiguration<'_, '_> {

markup! (
{KeyValuePair("Status", status)}
{KeyValuePair("Formatter disabled", markup!({DebugDisplay(configuration.is_formatter_disabled())}))}
{KeyValuePair("Linter disabled", markup!({DebugDisplay(configuration.is_linter_disabled())}))}
{KeyValuePair("Organize imports disabled", markup!({DebugDisplay(configuration.is_organize_imports_disabled())}))}
{KeyValuePair("VCS disabled", markup!({DebugDisplay(configuration.is_vcs_disabled())}))}
{KeyValuePair("Formatter disabled", markup!({DebugDisplay(!configuration.is_formatter_enabled())}))}
{KeyValuePair("Linter disabled", markup!({DebugDisplay(!configuration.is_linter_enabled())}))}
{KeyValuePair("Organize imports disabled", markup!({DebugDisplay(!configuration.is_organize_imports_enabled())}))}
{KeyValuePair("VCS disabled", markup!({DebugDisplay(!configuration.is_vcs_enabled())}))}
).fmt(fmt)?;

// Print formatter configuration if --formatter option is true
if self.formatter {
let formatter_configuration = configuration.get_formatter_configuration();
markup! (
{Section("Formatter")}
{KeyValuePair("Format with errors", markup!({DebugDisplay(configuration.get_formatter_configuration().format_with_errors)}))}
{KeyValuePair("Indent style", markup!({DebugDisplay(formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplay(formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplay(formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplay(formatter_configuration.line_width.value())}))}
{KeyValuePair("Attribute position", markup!({DebugDisplay(formatter_configuration.attribute_position)}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplay(formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Ignore", markup!({DebugDisplay(formatter_configuration.ignore.iter().collect::<Vec<_>>())}))}
{KeyValuePair("Include", markup!({DebugDisplay(formatter_configuration.include.iter().collect::<Vec<_>>())}))}
// Should display resolved values
{KeyValuePair("Format with errors", markup!({DebugDisplay(formatter_configuration.format_with_errors_resolved())}))}
{KeyValuePair("Indent style", markup!({DebugDisplay(formatter_configuration.indent_style_resolved())}))}
{KeyValuePair("Indent width", markup!({DebugDisplay(formatter_configuration.indent_width_resolved())}))}
{KeyValuePair("Line ending", markup!({DebugDisplay(formatter_configuration.line_ending_resolved())}))}
{KeyValuePair("Line width", markup!({DebugDisplay(formatter_configuration.line_width_resolved())}))}
{KeyValuePair("Attribute position", markup!({DebugDisplay(formatter_configuration.attribute_position_resolved())}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplay(formatter_configuration.bracket_spacing_resolved())}))}
{KeyValuePair("Ignore", markup!({DebugDisplay(formatter_configuration.ignore_resolved().iter().collect::<Vec<_>>())}))}
{KeyValuePair("Include", markup!({DebugDisplay(formatter_configuration.include_resolved().iter().collect::<Vec<_>>())}))}
).fmt(fmt)?;

let javascript_formatter_configuration =
configuration.get_javascript_formatter_configuration();
markup! (
{Section("JavaScript Formatter")}
{KeyValuePair("Enabled", markup!({DebugDisplay(javascript_formatter_configuration.enabled)}))}
{KeyValuePair("JSX quote style", markup!({DebugDisplay(javascript_formatter_configuration.jsx_quote_style)}))}
{KeyValuePair("Quote properties", markup!({DebugDisplay(javascript_formatter_configuration.quote_properties)}))}
{KeyValuePair("Trailing commas", markup!({DebugDisplay(javascript_formatter_configuration.trailing_commas)}))}
{KeyValuePair("Semicolons", markup!({DebugDisplay(javascript_formatter_configuration.semicolons)}))}
{KeyValuePair("Arrow parentheses", markup!({DebugDisplay(javascript_formatter_configuration.arrow_parentheses)}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplayOption(javascript_formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Bracket same line", markup!({DebugDisplay(javascript_formatter_configuration.bracket_same_line)}))}
{KeyValuePair("Quote style", markup!({DebugDisplay(javascript_formatter_configuration.quote_style)}))}
// Enabled
{KeyValuePair("Enabled", markup!({DebugDisplay(javascript_formatter_configuration.enabled_resolved())}))}
// These options will fallback to their language agnostic counterparts when they're `None`,
// So we should use `DebugDisplayOption` to indicate whether values are unset
// instead of resolving them to a concrete value
{KeyValuePair("Indent style", markup!({DebugDisplayOption(javascript_formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplayOption(javascript_formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplayOption(javascript_formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(javascript_formatter_configuration.line_width.map(|lw| lw.value()))}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(javascript_formatter_configuration.line_width)}))}
{KeyValuePair("Attribute position", markup!({DebugDisplayOption(javascript_formatter_configuration.attribute_position)}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplayOption(javascript_formatter_configuration.bracket_spacing)}))}
// Should use `DebugDisplay` to display resolved values
{KeyValuePair("JSX quote style", markup!({DebugDisplay(javascript_formatter_configuration.jsx_quote_style_resolved())}))}
{KeyValuePair("Quote properties", markup!({DebugDisplay(javascript_formatter_configuration.quote_properties_resolved())}))}
{KeyValuePair("Trailing commas", markup!({DebugDisplay(javascript_formatter_configuration.trailing_commas_resolved())}))}
{KeyValuePair("Semicolons", markup!({DebugDisplay(javascript_formatter_configuration.semicolons_resolved())}))}
{KeyValuePair("Arrow parentheses", markup!({DebugDisplay(javascript_formatter_configuration.arrow_parentheses_resolved())}))}
{KeyValuePair("Bracket same line", markup!({DebugDisplay(javascript_formatter_configuration.bracket_same_line_resolved())}))}
{KeyValuePair("Quote style", markup!({DebugDisplay(javascript_formatter_configuration.quote_style_resolved())}))}
)
.fmt(fmt)?;

let json_formatter_configuration =
configuration.get_json_formatter_configuration();
markup! (
{Section("JSON Formatter")}
{KeyValuePair("Enabled", markup!({DebugDisplay(json_formatter_configuration.enabled)}))}
// Enabled
{KeyValuePair("Enabled", markup!({DebugDisplay(json_formatter_configuration.enabled_resolved())}))}
// These options will fallback to their language agnostic counterparts when they're `None`,
// So we should use `DebugDisplayOption` to indicate whether values are unset
// instead of resolving them to a concrete value
{KeyValuePair("Indent style", markup!({DebugDisplayOption(json_formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplayOption(json_formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplayOption(json_formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(json_formatter_configuration.line_width.map(|lw| lw.value()))}))}
{KeyValuePair("Trailing Commas", markup!({DebugDisplayOption(json_formatter_configuration.trailing_commas)}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(json_formatter_configuration.line_width)}))}
// Should use `DebugDisplay` to display resolved values
{KeyValuePair("Trailing Commas", markup!({DebugDisplay(json_formatter_configuration.trailing_commas_resolved())}))}
).fmt(fmt)?;

let css_formatter_configuration =
configuration.get_css_formatter_configuration();
markup! (
{Section("CSS Formatter")}
{KeyValuePair("Enabled", markup!({DebugDisplay(css_formatter_configuration.enabled)}))}
// Enabled
{KeyValuePair("Enabled", markup!({DebugDisplay(css_formatter_configuration.enabled_resolved())}))}
// These options will fallback to their language agnostic counterparts when they're `None`,
// So we should use `DebugDisplayOption` to indicate whether values are unset
// instead of resolving them to a concrete value
{KeyValuePair("Indent style", markup!({DebugDisplayOption(css_formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplayOption(css_formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplayOption(css_formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(css_formatter_configuration.line_width)}))}
{KeyValuePair("Quote style", markup!({DebugDisplay(css_formatter_configuration.quote_style)}))}
// Should use `DebugDisplay` to display resolved values
{KeyValuePair("Quote style", markup!({DebugDisplay(css_formatter_configuration.quote_style_resolved())}))}
).fmt(fmt)?;

let graphql_formatter_configuration =
configuration.get_graphql_formatter_configuration();
markup! (
{Section("GraphQL Formatter")}
{KeyValuePair("Enabled", markup!({DebugDisplay(graphql_formatter_configuration.enabled)}))}
// Enabled
{KeyValuePair("Enabled", markup!({DebugDisplay(graphql_formatter_configuration.enabled_resolved())}))}
// These options will fallback to their language agnostic counterparts when they're `None`,
// So we should use `DebugDisplayOption` to indicate whether values are unset
// instead of resolving them to a concrete value
{KeyValuePair("Indent style", markup!({DebugDisplayOption(graphql_formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplayOption(graphql_formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplayOption(graphql_formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(graphql_formatter_configuration.line_width)}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplayOption(graphql_formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Quote style", markup!({DebugDisplayOption(graphql_formatter_configuration.quote_style)}))}
// Should use `DebugDisplay` to display resolved values
{KeyValuePair("Quote style", markup!({DebugDisplay(graphql_formatter_configuration.quote_style_resolved())}))}
).fmt(fmt)?;
}

Expand All @@ -290,9 +311,9 @@ impl Display for RageConfiguration<'_, '_> {
let css_linter = configuration.get_css_linter_configuration();
markup! (
{Section("Linter")}
{KeyValuePair("JavaScript enabled", markup!({DebugDisplay(javascript_linter.enabled)}))}
{KeyValuePair("JSON enabled", markup!({DebugDisplay(json_linter.enabled)}))}
{KeyValuePair("CSS enabled", markup!({DebugDisplay(css_linter.enabled)}))}
{KeyValuePair("JavaScript enabled", markup!({DebugDisplay(javascript_linter.enabled_resolved())}))}
{KeyValuePair("JSON enabled", markup!({DebugDisplay(json_linter.enabled_resolved())}))}
{KeyValuePair("CSS enabled", markup!({DebugDisplay(css_linter.enabled_resolved())}))}
{KeyValuePair("Recommended", markup!({DebugDisplay(linter_configuration.recommended.unwrap_or_default())}))}
{KeyValuePair("All", markup!({DebugDisplay(linter_configuration.all.unwrap_or_default())}))}
{RageConfigurationLintRules("Enabled rules",linter_configuration)}
Expand Down
20 changes: 9 additions & 11 deletions crates/biome_cli/src/execute/migrate/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ impl TryFrom<PrettierConfiguration> for biome_configuration::Configuration {
indent_style: Some(indent_style),
line_ending: Some(value.end_of_line.into()),
attribute_position: Some(AttributePosition::default()),
format_with_errors: Some(false),
format_with_errors: Some(false.into()),
ignore: None,
include: None,
enabled: Some(true),
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
use_editorconfig: Some(true),
use_editorconfig: Some(true.into()),
// deprecated
indent_size: None,
bracket_spacing: Some(BracketSpacing::default()),
Expand Down Expand Up @@ -243,7 +243,7 @@ impl TryFrom<PrettierConfiguration> for biome_configuration::Configuration {
indent_size: None,

// js ones
bracket_same_line: Some(value.bracket_line),
bracket_same_line: Some(value.bracket_line.into()),
arrow_parentheses: Some(value.arrow_parens.into()),
semicolons: Some(semicolons),
trailing_commas: Some(value.trailing_comma.into()),
Expand Down Expand Up @@ -306,7 +306,7 @@ impl TryFrom<Override> for biome_configuration::OverridePattern {
indent_width,
line_width,
indent_style,
line_ending: options.end_of_line.map(|end_of_line| end_of_line.into()),
line_ending: options.end_of_line.map(Into::into),
..Default::default()
};
result.formatter = Some(formatter);
Expand Down Expand Up @@ -346,14 +346,12 @@ impl TryFrom<Override> for biome_configuration::OverridePattern {
}
});
let js_formatter = biome_configuration::JsFormatterConfiguration {
bracket_same_line: options.bracket_line,
arrow_parentheses: options.arrow_parens.map(|arrow_parens| arrow_parens.into()),
bracket_same_line: options.bracket_line.map(Into::into),
arrow_parentheses: options.arrow_parens.map(Into::into),
semicolons,
trailing_commas: options
.trailing_comma
.map(|trailing_comma| trailing_comma.into()),
trailing_commas: options.trailing_comma.map(Into::into),
quote_style,
quote_properties: options.quote_props.map(|quote_props| quote_props.into()),
quote_properties: options.quote_props.map(Into::into),
jsx_quote_style,
..Default::default()
};
Expand Down
Loading

0 comments on commit 3494506

Please sign in to comment.