This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rome_cli): Add a new option --config to set the path to rome.json
- Loading branch information
1 parent
ced6f5b
commit 680f251
Showing
9 changed files
with
187 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
use std::path::PathBuf; | ||
|
||
use rome_service::{load_config, Configuration}; | ||
|
||
use crate::{CliDiagnostic, CliSession}; | ||
|
||
/// Load the configuration for this session of the CLI, merging the content of | ||
/// the `rome.json` file if it exists on disk with common command line options | ||
pub(crate) fn load_configuration(session: &mut CliSession) -> Result<Configuration, CliDiagnostic> { | ||
let mut configuration = load_config(&session.app.fs, None)?.unwrap_or_default(); | ||
let config_path: Option<PathBuf> = session | ||
.args | ||
.opt_value_from_str("--config") | ||
.map_err(|source| CliDiagnostic::parse_error("--config", source))?; | ||
|
||
let is_config_path = config_path.is_some(); | ||
|
||
let mut config = load_config(&session.app.fs, config_path, is_config_path)?.unwrap_or_default(); | ||
|
||
let files_max_size = session | ||
.args | ||
.opt_value_from_str("--files-max-size") | ||
.map_err(|source| CliDiagnostic::parse_error("--files-max-size", source))?; | ||
|
||
if let Some(files_max_size) = files_max_size { | ||
let files = configuration.files.get_or_insert_with(Default::default); | ||
let files = config.files.get_or_insert_with(Default::default); | ||
files.max_size = Some(files_max_size); | ||
} | ||
|
||
Ok(configuration) | ||
Ok(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
crates/rome_cli/tests/snapshots/main_commands_format/custom_config_file_path.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
source: crates/rome_cli/tests/snap_test.rs | ||
assertion_line: 335 | ||
expression: content | ||
--- | ||
## `/test/rome.json` | ||
|
||
```json | ||
{ | ||
"formatter": { | ||
"enabled": true, | ||
"lineWidth": 160, | ||
"indentStyle": "space", | ||
"indentSize": 6 | ||
} | ||
} | ||
|
||
``` | ||
|
||
## `file.js` | ||
|
||
```js | ||
function f() { | ||
return { a, b }; | ||
} | ||
|
||
``` | ||
|
||
# Emitted Messages | ||
|
||
```block | ||
Formatted 1 file(s) in <TIME> | ||
``` | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
crates/rome_cli/tests/snapshots/main_commands_format/invalid_config_file_path.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
source: crates/rome_cli/tests/snap_test.rs | ||
assertion_line: 335 | ||
expression: content | ||
--- | ||
## `file.js` | ||
|
||
```js | ||
content | ||
``` | ||
|
||
# Termination Message | ||
|
||
```block | ||
/test/rome.json internalError/fs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
× Rome couldn't read the following file, maybe for permissions reasons or it doesn't exists: /test/rome.json | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters