+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.
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
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ bench_parser = "run -p xtask_bench --release -- --feature parser"
bench_formatter = "run -p xtask_bench --release -- --feature formatter"
bench_analyzer = "run -p xtask_bench --release -- --feature analyzer"
coverage = "run -p xtask_coverage --profile=release-with-debug --"
rome-cli = "run -p rome_cli --release --"
rome-cli = "run -p rome_cli --release --"
rome-cli-dev = "run -p rome_cli --"
15 changes: 11 additions & 4 deletions Cargo.lock

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

26 changes: 7 additions & 19 deletions crates/rome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::commands::format::parse_format_options;
use crate::commands::format::apply_format_settings_from_cli;
use crate::{
traversal::{traverse, TraversalMode},
CliSession, Termination,
};
use rome_diagnostics::MAXIMUM_DISPLAYABLE_DIAGNOSTICS;
use rome_service::configuration::Configuration;
use rome_service::settings::{LinterSettings, WorkspaceSettings};
use rome_service::settings::WorkspaceSettings;
use rome_service::workspace::UpdateSettingsParams;
use rome_service::{load_config, ConfigurationType};

Expand Down Expand Up @@ -35,8 +34,11 @@ pub(crate) fn check(mut session: CliSession) -> Result<(), Termination> {
20
};

parse_format_options(&mut session, &mut workspace_settings, &configuration)?;
parse_linter_options(&mut session, &mut workspace_settings, &configuration)?;
if let Some(configuration) = configuration {
workspace_settings.merge_with_configuration(configuration)
}

apply_format_settings_from_cli(&mut session, &mut workspace_settings)?;

session
.app
Expand All @@ -53,17 +55,3 @@ pub(crate) fn check(mut session: CliSession) -> Result<(), Termination> {
session,
)
}

pub(crate) fn parse_linter_options(
_session: &mut CliSession,
workspace_settings: &mut WorkspaceSettings,
configuration: &Option<Configuration>,
) -> Result<(), Termination> {
if let Some(configuration) = configuration {
if let Some(linter) = &configuration.linter {
workspace_settings.linter = LinterSettings::from(linter);
}
}

Ok(())
}
10 changes: 6 additions & 4 deletions crates/rome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::commands::check::parse_linter_options;
use crate::{
traversal::{traverse, TraversalMode},
CliSession, Termination,
Expand All @@ -7,15 +6,18 @@ use rome_service::settings::WorkspaceSettings;
use rome_service::workspace::UpdateSettingsParams;
use rome_service::{load_config, ConfigurationType};

use super::format::parse_format_options;
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, ConfigurationType::Root)?;
let mut workspace_settings = WorkspaceSettings::default();

parse_format_options(&mut session, &mut workspace_settings, &configuration)?;
parse_linter_options(&mut session, &mut workspace_settings, &configuration)?;
if let Some(configuration) = configuration {
workspace_settings.merge_with_configuration(configuration);
}

apply_format_settings_from_cli(&mut session, &mut workspace_settings)?;

session
.app
Expand Down
19 changes: 9 additions & 10 deletions crates/rome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rome_formatter::IndentStyle;
use rome_service::configuration::Configuration;
use rome_service::{
load_config, settings::WorkspaceSettings, workspace::UpdateSettingsParams, ConfigurationType,
};
Expand All @@ -12,23 +11,28 @@ use crate::{
/// 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, ConfigurationType::Root)?;
let mut settings = WorkspaceSettings::default();
let mut workspace_settings = WorkspaceSettings::default();

if let Some(configuration) = &configuration {
if configuration.is_formatter_disabled() {
return Ok(());
}
}
if let Some(configuration) = configuration {
workspace_settings.merge_with_configuration(configuration);
}

parse_format_options(&mut session, &mut settings, &configuration)?;
apply_format_settings_from_cli(&mut session, &mut workspace_settings)?;

let is_write = session.args.contains("--write");
let ignore_errors = session.args.contains("--skip-errors");

session
.app
.workspace
.update_settings(UpdateSettingsParams { settings })?;
.update_settings(UpdateSettingsParams {
settings: workspace_settings,
})?;

traverse(
TraversalMode::Format {
Expand All @@ -41,15 +45,10 @@ pub(crate) fn format(mut session: CliSession) -> Result<(), Termination> {

/// Read the formatting options for the command line arguments and inject them
/// into the workspace settings
pub(crate) fn parse_format_options(
pub(crate) fn apply_format_settings_from_cli(
session: &mut CliSession,
workspace_settings: &mut WorkspaceSettings,
configuration: &Option<Configuration>,
) -> Result<(), Termination> {
if let Some(configuration) = configuration {
workspace_settings.merge_with_configuration(configuration);
}

let size = session
.args
.opt_value_from_str("--indent-size")
Expand Down
30 changes: 27 additions & 3 deletions crates/rome_cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,35 @@ pub(crate) fn init(mut session: CliSession) -> Result<(), Termination> {
let fs = &mut session.app.fs;
create_config(fs, Configuration::default())?;
let message = markup! {
<Info><Emphasis>"Files created:
<Info><Emphasis>"Files created:

"</Emphasis></Info>
<Emphasis>"- rome.json: "</Emphasis>"Your project configuration. Documentation: "<Underline>"https://rome.tools/#project-configuration"</Underline>
};
<Emphasis>"- rome.json: "</Emphasis>"Your project configuration. Documentation: "<Underline>"https://rome.tools/#project-configuration"</Underline>


<Info><Emphasis>"

What's next?

"</Emphasis></Info>
"
1. "<Emphasis>"Setup an editor extension
"</Emphasis>
" Get live errors as you type and format when you save. Learn more:"<Underline>"https://rome.tools/#install-official-rome-vs-code-extension"</Underline>
"
2. "<Emphasis>"Try a command
"</Emphasis>
<Italic>" rome check"</Italic>" is used to validate your code, verify formatting, and check for lint errors. Run " <Italic>"rome --help"</Italic>" for a full list of commands and flags"
"
3. "<Emphasis>"Read documentation
"</Emphasis>
" Our website serves as a comprehensive source of guides and documentation: "<Underline>"https://rome.tools/"</Underline>
"
4. "<Emphasis>"Get involved in the community
"</Emphasis>
" Ask questions, get support, or contribute by participating on GitHub ("<Underline>"https://github.com/rome/tools"</Underline>"), or our community Discord ("<Underline>"https://discord.gg/rome"</Underline>")"

};

session.app.console.log(message);

Expand Down
26 changes: 23 additions & 3 deletions crates/rome_cli/tests/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pub const CONFIG_FORMAT: &str = r#"{
"#;

pub const CONFIG_INIT_DEFAULT: &str = r#"{
"root": true
"root": true,
"linter": {
"enabled": true
}
}"#;

pub const CONFIG_DISABLED_FORMATTER: &str = r#"{
Expand All @@ -37,15 +40,22 @@ pub const CONFIG_ALL_FIELDS: &str = r#"{
},
"linter": {
"enabled": true,
"globals": ["$"],
"rules": {
"js": {
"noDeadCode": "off",
"useSimplifiedLogicExpression": "warn"
"useSimplifiedLogicExpression": "warn",
"noCatchAssign": "error",
"noLabelVar": {
"level": "warn"
},
"useTemplate": {
"level": "error"
}
}
}
},
"javascript": {
"globals": ["$"],
"formatter": {
"quoteStyle": "double"
}
Expand Down Expand Up @@ -80,3 +90,13 @@ pub const CONFIG_LINTER_WRONG_RULE: &str = r#"{
}
}
}"#;

pub const CONFIG_INCORRECT_GLOBALS: &str = r#"{
"root": true,
"linter": {
"enabled": false
},
"javascript": {
"globals": [false]
}
}"#;
30 changes: 29 additions & 1 deletion crates/rome_cli/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ mod init {

mod configuration {
use crate::configs::{
CONFIG_ALL_FIELDS, CONFIG_BAD_LINE_WIDTH, CONFIG_LINTER_WRONG_RULE, CONFIG_ROOT_FALSE,
CONFIG_ALL_FIELDS, CONFIG_BAD_LINE_WIDTH, CONFIG_INCORRECT_GLOBALS,
CONFIG_LINTER_WRONG_RULE, CONFIG_ROOT_FALSE,
};
use pico_args::Arguments;
use rome_cli::{run_cli, CliSession};
Expand Down Expand Up @@ -954,4 +955,31 @@ mod configuration {
_ => panic!("expected an error, but found none"),
}
}

#[test]
fn incorrect_globals() {
let mut fs = MemoryFileSystem::default();

let file_path = Path::new("rome.json");
fs.insert(file_path.into(), CONFIG_INCORRECT_GLOBALS.as_bytes());

let result = run_cli(CliSession {
app: App::with_filesystem_and_console(
DynRef::Borrowed(&mut fs),
DynRef::Owned(Box::new(BufferConsole::default())),
),
args: Arguments::from_vec(vec![OsString::from("check"), OsString::from("file.js")]),
});

assert!(result.is_err());

match result {
Err(error) => {
assert!(error
.to_string()
.contains("invalid type: boolean `false`, expected a string"),)
}
_ => panic!("expected an error, but found none"),
}
}
}
2 changes: 1 addition & 1 deletion crates/rome_lsp/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Config {
/// we use the settings coming from the client
pub fn as_workspace_settings(
&self,
configuration: Option<&Configuration>,
configuration: Option<Configuration>,
) -> settings::WorkspaceSettings {
let mut settings = settings::WorkspaceSettings::default();

Expand Down
6 changes: 4 additions & 2 deletions crates/rome_lsp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ impl Session {
error!("Cannot set workspace settings: {}", err);
})
.ok()?;
let configuration = self.configuration.read();
let settings = config.as_workspace_settings(configuration.as_ref());
let mut configuration = self.configuration.write();
// This operation is intended, we want to consume the configuration because once it's read
// from the LSP, it's not needed anymore
let settings = config.as_workspace_settings(configuration.take());

trace!(
"The LSP will now use the following configuration: \n {:?}",
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT"
[dependencies]
dashmap = "5.2.0"
serde = { version = "1.0.133", features = ["derive"] }
serde_json = "1.0.74"
serde_json = { version = "1.0.74", features = ["raw_value"] }
rome_analyze = { path = "../rome_analyze" }
rome_console = { path = "../rome_console" }
rome_diagnostics = { path = "../rome_diagnostics" }
Expand All @@ -21,3 +21,4 @@ rome_js_syntax = { path = "../rome_js_syntax" }
rome_js_parser = { path = "../rome_js_parser" }
rome_js_formatter = { path = "../rome_js_formatter" }
rome_rowan = { path = "../rome_rowan" }
indexmap = "1.9.1"
2 changes: 1 addition & 1 deletion crates/rome_service/src/configuration/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rome_formatter::{IndentStyle, LineWidth};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "camelCase", default)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct FormatterConfiguration {
// if `false`, it disables the feature. `true` by default
pub enabled: bool,
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载