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

feat(rome_service): add extends functionality #4572

Merged
merged 5 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@

### CLI

#### BREAKING CHANGES

- The CLI now exists with an error then there's an error inside the configuration.

Previously, rome would raise warnings and continue the execution, by applying its defaults.

This wasn't ideal for users, because this could have created false positives in linting, or formatted
code with a configuration that wasn't the of the user.


#### Other changes

- Fixes [#4556](https://github.com/rome/tools/issues/4556) using `lines()` to enable OS independent line parsing when processing the .gitignore file.
- Add a new option to ignore unknown files
- The command `rome check` now shows formatter diagnostics when checking the code.
- Fix [#4556](https://github.com/rome/tools/issues/4556), which correctly handles new lines in the
`.gitignore` file across OS.
- Add a new option to ignore unknown files.

```shell
rome format ./src --files-ignore-unknown=true
```

Doing so, Rome won't emit diagnostics for file that it doesn't know how to handle.
Doing so, Rome won't emit diagnostics for files that doesn't know how to handle.

### Configuration

Expand All @@ -30,7 +42,7 @@
```
Doing so, Rome won't emit diagnostics for file that it doesn't know how to handle.

- Add a new `"javascript"` option to support the usafe/experimental
- Add a new `"javascript"` option to support the unsafe/experimental
parameter decorators:

```json
Expand All @@ -42,6 +54,17 @@ parameter decorators:
}
}
```
- Add a new `"extends"` option, useful to split the configuration file in
multiple files:

```json
{
"extends": ["../sharedFormatter.json", "linter.json"]
}
```

The resolution of the files is file system based, Rome doesn't know how to
resolve dependencies yet.

### Editors

Expand Down Expand Up @@ -94,7 +117,7 @@ parameter decorators:
- The rules [`useExhaustiveDependencies`](https://docs.rome.tools/lint/rules/useexhaustivedependencies/) and [`useHookAtTopLevel`](https://docs.rome.tools/lint/rules/usehookattoplevel/) accept a different shape of options

Old configuration

```json
{
"linter": {
Expand All @@ -115,7 +138,7 @@ parameter decorators:
```

New configuration

```json
{
"linter": {
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ inherits = "release"
[workspace.dependencies]
countme = "3.0.1"
dashmap = "5.4.0"
indexmap = "1.9.1"
indexmap = "1.9.3"
rustc-hash = "1.1.0"
tracing = { version = "0.1.31", default-features = false, features = ["std"] }
# pinning to version 1.18 to avoid multiple versions of windows-sys as dependency
Expand Down
24 changes: 7 additions & 17 deletions crates/rome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::cli_options::CliOptions;
use crate::configuration::load_configuration;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{execute_mode, CliDiagnostic, CliSession, Execution, TraversalMode};
use rome_console::{markup, ConsoleExt};
use rome_diagnostics::{DiagnosticExt, PrintDiagnostic, Severity};
use rome_service::configuration::organize_imports::OrganizeImports;
use rome_service::configuration::{FormatterConfiguration, LinterConfiguration};
use rome_service::workspace::{FixFileMode, UpdateSettingsParams};
Expand Down Expand Up @@ -53,20 +51,12 @@ pub(crate) fn check(
Some(FixFileMode::SafeAndUnsafeFixes)
};

let (mut fs_configuration, diagnostics, configuration_path) =
load_configuration(&mut session, &cli_options)?.consume();
if !diagnostics.is_empty() {
let console = &mut session.app.console;
console.log(markup!{
<Warn>"Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect."</Warn>
});
for diagnostic in diagnostics {
let diagnostic = diagnostic.with_severity(Severity::Warning);
console.log(markup! {
{PrintDiagnostic::verbose(&diagnostic)}
})
}
}
let LoadedConfiguration {
configuration: mut fs_configuration,
directory_path: configuration_path,
..
} = load_configuration(&mut session, &cli_options)?
.or_diagnostic(session.app.console, cli_options.verbose)?;

let formatter = fs_configuration
.formatter
Expand Down
23 changes: 7 additions & 16 deletions crates/rome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::cli_options::CliOptions;
use crate::configuration::LoadedConfiguration;
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{
configuration::load_configuration, execute_mode, CliDiagnostic, CliSession, Execution,
TraversalMode,
};
use rome_console::{markup, ConsoleExt};
use rome_diagnostics::PrintDiagnostic;
use rome_service::configuration::organize_imports::OrganizeImports;
use rome_service::configuration::{FormatterConfiguration, LinterConfiguration};
use rome_service::workspace::UpdateSettingsParams;
Expand All @@ -23,20 +22,12 @@ pub(crate) struct CiCommandPayload {

/// Handler for the "ci" command of the Rome CLI
pub(crate) fn ci(mut session: CliSession, payload: CiCommandPayload) -> Result<(), CliDiagnostic> {
let (mut configuration, diagnostics, configuration_path) =
load_configuration(&mut session, &payload.cli_options)?.consume();

if !diagnostics.is_empty() {
let console = &mut session.app.console;
for diagnostic in diagnostics {
console.error(markup! {
{PrintDiagnostic::verbose(&diagnostic)}
})
}
return Err(CliDiagnostic::incompatible_end_configuration(
"The deserialization of the configuration resulted into an error.",
));
}
let LoadedConfiguration {
mut configuration,
directory_path: configuration_path,
..
} = load_configuration(&mut session, &payload.cli_options)?
.or_diagnostic(session.app.console, payload.cli_options.verbose)?;

let formatter = configuration
.formatter
Expand Down
24 changes: 7 additions & 17 deletions crates/rome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::cli_options::CliOptions;
use crate::configuration::load_configuration;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::execute::ReportMode;
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{execute_mode, CliDiagnostic, CliSession, Execution, TraversalMode};
use rome_console::{markup, ConsoleExt};
use rome_diagnostics::{DiagnosticExt, PrintDiagnostic, Severity};
use rome_service::configuration::vcs::VcsConfiguration;
use rome_service::configuration::{FilesConfiguration, FormatterConfiguration};
use rome_service::workspace::UpdateSettingsParams;
Expand Down Expand Up @@ -38,20 +36,12 @@ pub(crate) fn format(
files_configuration,
write,
} = payload;
let (mut configuration, diagnostics, configuration_path) =
load_configuration(&mut session, &cli_options)?.consume();
if !diagnostics.is_empty() {
let console = &mut session.app.console;
console.log(markup!{
<Warn>"Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect."</Warn>
});
for diagnostic in diagnostics {
let diagnostic = diagnostic.with_severity(Severity::Warning);
console.log(markup! {
{PrintDiagnostic::verbose(&diagnostic)}
})
}
}
let LoadedConfiguration {
mut configuration,
directory_path: configuration_path,
..
} = load_configuration(&mut session, &cli_options)?
.or_diagnostic(session.app.console, cli_options.verbose)?;

configuration.merge_with(javascript_formatter);
configuration.merge_with(formatter_configuration);
Expand Down
9 changes: 7 additions & 2 deletions crates/rome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cli_options::CliOptions;
use crate::configuration::load_configuration;
use crate::configuration::{load_configuration, LoadedConfiguration};
use crate::diagnostics::MigrationDiagnostic;
use crate::execute::{execute_mode, Execution, TraversalMode};
use crate::{CliDiagnostic, CliSession};
Expand All @@ -10,7 +10,12 @@ pub(crate) fn migrate(
cli_options: CliOptions,
write: bool,
) -> Result<(), CliDiagnostic> {
let (_, _, path) = load_configuration(&mut session, &cli_options)?.consume();
let LoadedConfiguration {
configuration: _,
diagnostics: _,
directory_path: path,
..
} = load_configuration(&mut session, &cli_options)?;
let config_name = session.app.fs.config_name();
if let Some(path) = path {
execute_mode(
Expand Down
22 changes: 20 additions & 2 deletions crates/rome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,18 @@ pub enum RomeCommand {
#[bpaf(external, optional, hide_usage)]
files_configuration: Option<FilesConfiguration>,

/// A file name with its extension to pass when reading from standard in, e.g. echo 'let a;' | rome format --stdin-file-path=file.js"
/// A file name with its extension to pass when reading from standard in, e.g. echo 'let a;' | rome format --stdin-file-path=file.js".
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
stdin_file_path: Option<String>,

#[bpaf(external, hide_usage)]
cli_options: CliOptions,

/// Writes formatted files to file system.
#[bpaf(switch)]
write: bool,

/// Single file, single path or list of paths
/// Single file, single path or list of paths.
#[bpaf(positional("PATH"), many)]
paths: Vec<OsString>,
},
Expand Down Expand Up @@ -189,6 +190,23 @@ impl RomeCommand {
pub const fn has_metrics(&self) -> bool {
false
}

pub fn is_verbose(&self) -> bool {
match self {
RomeCommand::Version(_) => false,
RomeCommand::Rage(_) => false,
RomeCommand::Start => false,
RomeCommand::Stop => false,
RomeCommand::Check { cli_options, .. } => cli_options.verbose,
RomeCommand::Format { cli_options, .. } => cli_options.verbose,
RomeCommand::Ci { cli_options, .. } => cli_options.verbose,
RomeCommand::Init => false,
RomeCommand::LspProxy(cli_options) => cli_options.verbose,
RomeCommand::Migrate(cli_options, _) => cli_options.verbose,
RomeCommand::RunServer { .. } => false,
RomeCommand::PrintSocket => false,
}
}
}

pub fn parse_command() -> OptionParser<RomeCommand> {
Expand Down
5 changes: 2 additions & 3 deletions crates/rome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ impl Display for RageConfiguration<'_, '_> {

match load_config(self.0, ConfigurationBasePath::default()) {
Ok(None) => KeyValuePair("Status", markup!(<Dim>"unset"</Dim>)).fmt(fmt)?,
Ok(Some(deserialized)) => {
let (deserialized, _) = deserialized;
let (configuration, diagnostics) = deserialized.consume();
Ok(Some(result)) => {
let (configuration, diagnostics) = result.deserialized.consume();
let status = if !diagnostics.is_empty() {
for diagnostic in diagnostics {
(markup! {
Expand Down
Loading