+
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
```
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
parameter decorators:

```json
{
"javascript": {
"parser": {
"unsafeParameterDecoratorsEnabled": true
}
}
}
```

### Editors
### Formatter

Expand Down
34 changes: 34 additions & 0 deletions crates/rome_service/src/configuration/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub struct JavascriptConfiguration {
#[bpaf(external(javascript_formatter), optional)]
pub formatter: Option<JavascriptFormatter>,

#[serde(skip_serializing_if = "Option::is_none")]
#[bpaf(external(javascript_parser), optional)]
pub parser: Option<JavascriptParser>,

/// A list of global bindings that should be ignored by the analyzers
///
/// If defined here, they should not emit diagnostics.
Expand Down Expand Up @@ -66,18 +70,23 @@ impl JavascriptConfiguration {
pub struct JavascriptFormatter {
/// The style for quotes. Defaults to double.
#[bpaf(long("quote-style"), argument("double|single"), optional)]
#[serde(skip_serializing_if = "Option::is_none")]
pub quote_style: Option<QuoteStyle>,
/// The style for JSX quotes. Defaults to double.
#[bpaf(long("jsx-quote-style"), argument("double|single"), optional)]
#[serde(skip_serializing_if = "Option::is_none")]
pub jsx_quote_style: Option<QuoteStyle>,
/// When properties in objects are quoted. Defaults to asNeeded.
#[bpaf(long("quote-properties"), argument("preserve|as-needed"), optional)]
#[serde(skip_serializing_if = "Option::is_none")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it work without skip_serializing_if? Does it use default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, which is not ideal. Still, we don't use the serialization feature, but when we will, that's exactly what will happen.

pub quote_properties: Option<QuoteProperties>,
/// Print trailing commas wherever possible in multi-line comma-separated syntactic structures. Defaults to "all".
#[bpaf(long("trailing-comma"), argument("all|es5|none"), optional)]
#[serde(skip_serializing_if = "Option::is_none")]
pub trailing_comma: Option<TrailingComma>,
/// Whether the formatter prints semicolons for all statements or only in for statements where it is necessary because of ASI.
#[bpaf(long("semicolons"), argument("always|as-needed"), optional)]
#[serde(skip_serializing_if = "Option::is_none")]
pub semicolons: Option<Semicolons>,
}

Expand Down Expand Up @@ -115,3 +124,28 @@ impl MergeWith<JavascriptFormatter> for JavascriptFormatter {
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(default, deny_unknown_fields)]
pub struct JavascriptOrganizeImports {}

#[derive(Default, Debug, Deserialize, Serialize, Eq, PartialEq, Clone, Bpaf)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct JavascriptParser {
#[bpaf(hide)]
#[serde(skip_serializing_if = "Option::is_none")]
/// It enables the experimental and unsafe parsing of parameter decorators
///
/// These decorators belong to an old proposal, and they are subject to change.
pub unsafe_parameter_decorators_enabled: Option<bool>,
}

impl JavascriptParser {
pub(crate) const KNOWN_KEYS: &'static [&'static str] = &["unsafeParameterDecoratorsEnabled"];
}

impl MergeWith<JavascriptParser> for JavascriptParser {
fn merge_with(&mut self, other: JavascriptParser) {
if let Some(unsafe_parameter_decorators_enabled) = other.unsafe_parameter_decorators_enabled
{
self.unsafe_parameter_decorators_enabled = Some(unsafe_parameter_decorators_enabled);
}
}
}
29 changes: 28 additions & 1 deletion crates/rome_service/src/configuration/parse/json/javascript.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::configuration::javascript::JavascriptOrganizeImports;
use crate::configuration::javascript::{JavascriptOrganizeImports, JavascriptParser};
use crate::configuration::string_set::StringSet;
use crate::configuration::{JavascriptConfiguration, JavascriptFormatter};
use rome_deserialize::json::{has_only_known_keys, VisitJsonNode};
Expand Down Expand Up @@ -118,3 +118,30 @@ impl VisitNode<JsonLanguage> for JavascriptOrganizeImports {
Some(())
}
}

impl VisitJsonNode for JavascriptParser {}
impl VisitNode<JsonLanguage> for JavascriptParser {
fn visit_member_name(
&mut self,
node: &JsonSyntaxNode,
diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> Option<()> {
has_only_known_keys(node, JavascriptParser::KNOWN_KEYS, diagnostics)
}

fn visit_map(
&mut self,
key: &SyntaxNode<JsonLanguage>,
value: &SyntaxNode<JsonLanguage>,
diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> Option<()> {
let (name, value) = self.get_key_and_value(key, value, diagnostics)?;
let name_text = name.text();
if name_text == "unsafeParameterDecoratorsEnabled" {
self.unsafe_parameter_decorators_enabled =
self.map_to_boolean(&value, name_text, diagnostics);
}

Some(())
}
}
21 changes: 16 additions & 5 deletions editors/vscode/configuration_schema.json

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

9 changes: 9 additions & 0 deletions npm/backend-jsonrpc/src/workspace.ts

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

21 changes: 16 additions & 5 deletions npm/rome/configuration_schema.json

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

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载