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

Commit

Permalink
chore: use folder from configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Apr 14, 2023
1 parent 4fd1e95 commit 139a6b0
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 10 deletions.
23 changes: 18 additions & 5 deletions crates/rome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::configuration::load_configuration;
use crate::parse_arguments::{apply_files_settings_from_cli, apply_format_settings_from_cli};
use crate::diagnostics::DisabledVcs;
use crate::parse_arguments::{
apply_files_settings_from_cli, apply_format_settings_from_cli, apply_vcs_settings_from_cli,
};
use crate::vcs::read_vcs_ignore_file;
use crate::{execute_mode, CliDiagnostic, CliSession, Execution, TraversalMode};
use indexmap::IndexSet;
Expand All @@ -26,15 +29,25 @@ pub(crate) fn check(mut session: CliSession) -> Result<(), CliDiagnostic> {
}
apply_files_settings_from_cli(&mut session, &mut configuration)?;
apply_format_settings_from_cli(&mut session, &mut configuration)?;
apply_vcs_settings_from_cli(&mut session, &mut configuration)?;

// check if support of git ignore files is enabled

let files_to_ignore =
if let (Some(vcs), Some(configuration_path)) = (&configuration.vcs, configuration_path) {
read_vcs_ignore_file(&mut session, configuration_path, vcs)?
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
let files_to_ignore = if let Some(vcs) = &configuration.vcs {
if let Some(vcs_base_path) = vcs_base_path {
read_vcs_ignore_file(&mut session, vcs_base_path, vcs)?
} else {
let console = &mut session.app.console;
let diagnostic = DisabledVcs {};
console.error(markup! {
{PrintDiagnostic::verbose(&diagnostic)}
});
vec![]
};
}
} else {
vec![]
};
if files_to_ignore.len() > 0 {
let files = configuration
.files
Expand Down
8 changes: 8 additions & 0 deletions crates/rome_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ pub struct NoVcsFolderFound {
pub path: String,
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
severity = Warning,
message = "Rome couldn't determine a directory for the VCS integration. VCS integration will be disabled."
)]
pub struct DisabledVcs {}

/// Advices for the [CliDiagnostic]
#[derive(Debug, Default)]
struct CliAdvice {
Expand Down
45 changes: 45 additions & 0 deletions crates/rome_cli/src/parse_arguments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{CliDiagnostic, CliSession};
use rome_formatter::IndentStyle;
use rome_service::configuration::vcs::{VcsClientKind, VcsConfiguration};
use rome_service::configuration::{
FormatterConfiguration, JavascriptConfiguration, JavascriptFormatter, PlainIndentStyle,
};
Expand Down Expand Up @@ -107,3 +108,47 @@ pub(crate) fn apply_files_settings_from_cli(

Ok(())
}

pub(crate) fn apply_vcs_settings_from_cli(
session: &mut CliSession,
configuration: &mut Configuration,
) -> Result<(), CliDiagnostic> {
let vcs = configuration
.vcs
.get_or_insert_with(VcsConfiguration::default);

let enabled = session
.args
.opt_value_from_str("--vcs-enabled")
.map_err(|source| CliDiagnostic::parse_error("--vcs-enabled", source))?;
let client_kind = session
.args
.opt_value_from_str("--vcs-client-kind")
.map_err(|source| CliDiagnostic::parse_error("--vcs-client-kind", source))?;

let use_ignore_file = session.args.contains("--vcs-use-ignore-file");
let root = session
.args
.opt_value_from_str("--vcs-root")
.map_err(|source| CliDiagnostic::parse_error("--vcs-root", source))?;

if let Some(enabled) = enabled {
vcs.enabled = enabled;
}

match client_kind {
None => {}
Some(VcsClientKind::Git) => {
vcs.client_kind = Some(VcsClientKind::Git);
}
}

if use_ignore_file {
vcs.use_ignore_file = Some(true);
}
if let Some(root) = root {
vcs.enabled = root;
}

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ expression: malformedOptions.js
```
malformedOptions.js:2:5 deserialize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Found an unknown key `hook`
× Found an unknown key `hook`.
1 │ {
> 2 │ "hook": [
Expand Down
19 changes: 17 additions & 2 deletions crates/rome_service/src/configuration/vcs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use std::str::FromStr;

const GIT_IGNORE_FILE_NAME: &str = ".gitignore";

Expand All @@ -19,8 +20,11 @@ pub struct VcsConfiguration {
#[serde(skip_serializing_if = "Option::is_none")]
pub use_ignore_file: Option<bool>,

/// The folder where Rome should check for VCS files. By default, Rome will use the
/// the working directory.
/// The folder where Rome should check for VCS files. By default, Rome will use the same
/// folder where `rome.json` was found.
///
/// If Rome can't fine the configuration, it will attempt to use the current working directory.
/// If no current working directory can't be found, Rome won't use the VCS integration.
#[serde(skip_serializing_if = "Option::is_none")]
pub root: Option<String>,
}
Expand All @@ -44,6 +48,17 @@ impl VcsClientKind {
}
}

impl FromStr for VcsClientKind {
type Err = &'static str;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"git" => Ok(Self::Git),
_ => Err("Value not supported for VcsClientKind"),
}
}
}

impl VcsConfiguration {
pub const KNOWN_KEYS: &'static [&'static str] =
&["clientKind", "enabled", "useIgnoreFile", "root"];
Expand Down
3 changes: 1 addition & 2 deletions rome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true,
"root": "/"
"useIgnoreFile": true
},
"files": {
"ignore": [
Expand Down

0 comments on commit 139a6b0

Please sign in to comment.