Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into perf/daemon-transport
Browse files Browse the repository at this point in the history
  • Loading branch information
leops authored Sep 8, 2022
2 parents b08f302 + 437c7dc commit 8a9c7db
Show file tree
Hide file tree
Showing 43 changed files with 660 additions and 123 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Rome changelog

## 0.9.1

### CLI

- Fixes a regression where the arguments passed via CLI were ignored [#3175](https://github.com/rome/tools/issues/3175)
- Fixes a regression where the command `rome ci` was not correctly reading the configuration [#3167](https://github.com/rome/tools/issues/3167)

### VSCode

- Windows: fixes an issue where the extension could not load the configuration file [#3182](https://github.com/rome/tools/issues/3182)

## 0.9.0

### CLI
Expand Down
15 changes: 5 additions & 10 deletions crates/rome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ use crate::commands::format::apply_format_settings_from_cli;
use crate::{execute_mode, CliSession, Execution, Termination, TraversalMode};
use rome_diagnostics::MAXIMUM_DISPLAYABLE_DIAGNOSTICS;
use rome_service::load_config;
use rome_service::settings::WorkspaceSettings;
use rome_service::workspace::{FixFileMode, UpdateSettingsParams};

/// Handler for the "check" command of the Rome CLI
pub(crate) fn check(mut session: CliSession) -> Result<(), Termination> {
let configuration = load_config(&session.app.fs, None)?;
let mut workspace_settings = WorkspaceSettings::default();

let max_diagnostics: Option<u16> = session
.args
.opt_value_from_str("--max-diagnostics")
Expand All @@ -31,13 +28,11 @@ pub(crate) fn check(mut session: CliSession) -> Result<(), Termination> {
20
};

if let Some(configuration) = configuration {
session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;
}
apply_format_settings_from_cli(&mut session, &mut workspace_settings)?;
let configuration = apply_format_settings_from_cli(&mut session, configuration)?;
session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;

let apply = session.args.contains("--apply");
let apply_suggested = session.args.contains("--apply-suggested");
Expand Down
14 changes: 5 additions & 9 deletions crates/rome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use crate::{execute_mode, CliSession, Execution, Termination, TraversalMode};
use rome_service::load_config;
use rome_service::settings::WorkspaceSettings;
use rome_service::workspace::UpdateSettingsParams;

use super::format::apply_format_settings_from_cli;

/// Handler for the "ci" command of the Rome CLI
pub(crate) fn ci(mut session: CliSession) -> Result<(), Termination> {
let configuration = load_config(&session.app.fs, None)?;
let mut workspace_settings = WorkspaceSettings::default();
let configuration = apply_format_settings_from_cli(&mut session, configuration)?;

if let Some(configuration) = configuration {
session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;
}
apply_format_settings_from_cli(&mut session, &mut workspace_settings)?;
session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;

execute_mode(Execution::new(TraversalMode::CI), session)
}
99 changes: 57 additions & 42 deletions crates/rome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use rome_formatter::IndentStyle;
use rome_service::{load_config, settings::WorkspaceSettings, workspace::UpdateSettingsParams};
use rome_service::configuration::{
FormatterConfiguration, JavascriptConfiguration, JavascriptFormatter, PlainIndentStyle,
};
use rome_service::{load_config, workspace::UpdateSettingsParams, Configuration};
use std::path::PathBuf;

use crate::execute::ReportMode;
Expand All @@ -8,16 +11,12 @@ use crate::{execute_mode, CliSession, Execution, Termination, TraversalMode};
/// Handler for the "format" command of the Rome CLI
pub(crate) fn format(mut session: CliSession) -> Result<(), Termination> {
let configuration = load_config(&session.app.fs, None)?;
let mut workspace_settings = WorkspaceSettings::default();
let configuration = apply_format_settings_from_cli(&mut session, configuration)?;

if let Some(configuration) = configuration {
session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;
}

apply_format_settings_from_cli(&mut session, &mut workspace_settings)?;
session
.app
.workspace
.update_settings(UpdateSettingsParams { configuration })?;

let is_write = session.args.contains("--write");
let ignore_errors = session.args.contains("--skip-errors");
Expand Down Expand Up @@ -67,8 +66,21 @@ pub(crate) fn format(mut session: CliSession) -> Result<(), Termination> {
/// into the workspace settings
pub(crate) fn apply_format_settings_from_cli(
session: &mut CliSession,
workspace_settings: &mut WorkspaceSettings,
) -> Result<(), Termination> {
configuration: Option<Configuration>,
) -> Result<Configuration, Termination> {
let mut configuration = if let Some(configuration) = configuration {
configuration
} else {
Configuration {
formatter: Some(FormatterConfiguration::default()),
javascript: Some(JavascriptConfiguration {
formatter: Some(JavascriptFormatter::default()),
globals: None,
}),
..Configuration::default()
}
};

let size = session
.args
.opt_value_from_str("--indent-size")
Expand All @@ -85,27 +97,29 @@ pub(crate) fn apply_format_settings_from_cli(
source,
})?;

match indent_style {
Some(IndentStyle::Tab) => {
workspace_settings.formatter.indent_style = Some(IndentStyle::Tab);
}
Some(IndentStyle::Space(default_size)) => {
workspace_settings.formatter.indent_style =
Some(IndentStyle::Space(size.unwrap_or(default_size)));
}
None => {}
}

let quote_style = session
let line_width = session
.args
.opt_value_from_str("--quote-style")
.opt_value_from_str("--line-width")
.map_err(|source| Termination::ParseError {
argument: "--quote-style",
argument: "--line-width",
source,
})?;

if let Some(quote_style) = quote_style {
workspace_settings.languages.javascript.format.quote_style = Some(quote_style);
if let Some(formatter) = configuration.formatter.as_mut() {
match indent_style {
Some(IndentStyle::Tab) => {
formatter.indent_style = PlainIndentStyle::Tab;
}
Some(IndentStyle::Space(default_size)) => {
formatter.indent_style = PlainIndentStyle::Space;
formatter.indent_size = size.unwrap_or(default_size);
}
None => {}
}

if let Some(line_width) = line_width {
formatter.line_width = line_width;
}
}

let quote_properties = session
Expand All @@ -116,25 +130,26 @@ pub(crate) fn apply_format_settings_from_cli(
source,
})?;

if let Some(quote_properties) = quote_properties {
workspace_settings
.languages
.javascript
.format
.quote_properties = Some(quote_properties);
}

let line_width = session
let quote_style = session
.args
.opt_value_from_str("--line-width")
.opt_value_from_str("--quote-style")
.map_err(|source| Termination::ParseError {
argument: "--line-width",
argument: "--quote-style",
source,
})?;
if let Some(javascript) = configuration
.javascript
.as_mut()
.and_then(|j| j.formatter.as_mut())
{
if let Some(quote_properties) = quote_properties {
javascript.quote_properties = quote_properties;
}

if let Some(line_width) = line_width {
workspace_settings.formatter.line_width = Some(line_width);
if let Some(quote_style) = quote_style {
javascript.quote_style = quote_style;
}
}

Ok(())
Ok(configuration)
}
2 changes: 1 addition & 1 deletion crates/rome_cli/src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const CHECK: Markup = markup! {

const FORMAT_OPTIONS: Markup = markup! {
"
"<Dim>"--write"</Dim>" Edit the files in place (beware!) instead of instead of printing the diff to the console
"<Dim>"--write"</Dim>" Edit the files in place (beware!) instead of printing the diff to the console
"<Dim>"--skip-errors"</Dim>" Skip over files containing syntax errors instead of emitting an error diagnostic.
"<Dim>"--indent-style <tabs|space>"</Dim>" Change the indention character (default: tabs)
"<Dim>"--indent-size <number>"</Dim>" If the indentation style is set to spaces, determine how many spaces should be used for indentation (default: 2)
Expand Down
15 changes: 6 additions & 9 deletions crates/rome_cli/src/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,15 +556,12 @@ fn process_file(ctx: &TraversalOptions, path: &Path, file_id: FileId) -> FileRes
let can_format = ctx
.can_format(&rome_path)
.with_file_id_and_code(file_id, "IO")?;
let can_lint = ctx
.can_lint(&rome_path)
.with_file_id_and_code(file_id, "IO")?;
let can_handle = match ctx.execution.traversal_mode() {
TraversalMode::Check { .. } => ctx
.can_lint(&rome_path)
.with_file_id_and_code(file_id, "IO")?,
TraversalMode::CI { .. } => {
ctx.can_lint(&rome_path)
.with_file_id_and_code(file_id, "IO")?
|| can_format
}
TraversalMode::Check { .. } => can_lint,
TraversalMode::CI { .. } => can_lint || can_format,
TraversalMode::Format { .. } => can_format,
};

Expand Down Expand Up @@ -616,7 +613,7 @@ fn process_file(ctx: &TraversalOptions, path: &Path, file_id: FileId) -> FileRes
return Ok(FileStatus::Ignored);
}

let categories = if ctx.execution.is_format() {
let categories = if ctx.execution.is_format() || !can_lint {
RuleCategories::SYNTAX
} else {
RuleCategories::SYNTAX | RuleCategories::LINT
Expand Down
Loading

0 comments on commit 8a9c7db

Please sign in to comment.