+
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
- `rome lsp-proxy` should accept the global CLI options [#4505](https://github.com/rome/tools/issues/4505)

### Configuration

#### Other changes

- Fix an issue where all the `nursery` were enabled when the `"nursery": {}` object
was defined [#4479](https://github.com/rome/tools/issues/4479)

### Editors
### Formatter
### Linter
Expand Down
53 changes: 53 additions & 0 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2220,3 +2220,56 @@ array.map((sentence) => sentence.split(" ")).flat();
result,
));
}

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

let configuration = r#" {
"$schema": "https://docs.rome.tools/schemas/12.1.0/schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"nursery": {
"noAccumulatingSpread": "error"
}
}
}
}"#;

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

let file_path = Path::new("fix.ts");
fs.insert(
file_path.into(),
r#"const bannedType: Boolean = true;

if (true) {
const obj = {};
obj["useLiteralKey"];
}
"#,
);
Comment on lines +2251 to +2258
Copy link
Contributor

Choose a reason for hiding this comment

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

A drawback to this test is it relies on one of these 3 rules to be in the nursery still

lint/nursery/noBannedTypes
lint/nursery/noConstantCondition
lint/nursery/useLiteralKeys

Are there any nursery rules that only exist at test time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately no. That's the bad thing of this test :(

When we promote the rules, it's going to fail, probably. But I think it's okay.


let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(&[("check"), file_path.as_os_str().to_str().unwrap()]),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_not_enable_nursery_rules",
fs,
console,
result,
));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
## `rome.json`

```json
{
"$schema": "https://docs.rome.tools/schemas/12.1.0/schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"nursery": {
"noAccumulatingSpread": "error"
}
}
}
}
```

## `fix.ts`

```ts
const bannedType: Boolean = true;

if (true) {
const obj = {};
obj["useLiteralKey"];
}

```

# Emitted Messages

```block
Checked 1 file(s) in <TIME>
```


4 changes: 2 additions & 2 deletions crates/rome_service/src/configuration/linter/rules.rs

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

16 changes: 13 additions & 3 deletions xtask/codegen/src/generate_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,17 @@ fn generate_struct(group: &str, rules: &BTreeMap<&'static str, RuleMetadata>) ->
let group_struct_name = Ident::new(&group.to_capitalized(), Span::call_site());

let number_of_recommended_rules = Literal::u8_unsuffixed(number_of_recommended_rules);

let (group_recommended, parent_parameter) = if group == "nursery" {
(
quote! { self.is_recommended() },
quote! { _parent_is_recommended: bool, },
)
} else {
(
quote! { parent_is_recommended || self.is_recommended() },
quote! { parent_is_recommended: bool, },
)
};
quote! {
#[derive(Deserialize, Default, Serialize, Debug, Clone, Bpaf)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
Expand Down Expand Up @@ -537,13 +547,13 @@ fn generate_struct(group: &str, rules: &BTreeMap<&'static str, RuleMetadata>) ->
/// Select preset rules
pub(crate) fn collect_preset_rules(
&self,
parent_is_recommended: bool,
#parent_parameter
enabled_rules: &mut IndexSet<RuleFilter>,
disabled_rules: &mut IndexSet<RuleFilter>,
) {
if self.is_all() {
enabled_rules.extend(Self::all_rules_as_filters());
} else if parent_is_recommended || self.is_recommended() {
} else if #group_recommended {
enabled_rules.extend(Self::recommended_rules_as_filters());
}
if self.is_not_all() {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载