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

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Mar 5, 2023
2 parents 8d063e0 + b32c29b commit 89e6386
Show file tree
Hide file tree
Showing 273 changed files with 4,477 additions and 2,716 deletions.
22 changes: 21 additions & 1 deletion crates/rome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::cmp::Ordering;
use std::collections::{BTreeMap, BinaryHeap};
use std::fmt::{Debug, Display, Formatter};
use std::ops;

mod categories;
Expand Down Expand Up @@ -685,7 +686,7 @@ type SuppressionCommentEmitter<L> = fn(SuppressionCommentEmitterPayload<L>);
type SignalHandler<'a, L, Break> = &'a mut dyn FnMut(&dyn AnalyzerSignal<L>) -> ControlFlow<Break>;

/// Allow filtering a single rule or group of rules by their names
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
pub enum RuleFilter<'a> {
Group(&'a str),
Rule(&'a str, &'a str),
Expand Down Expand Up @@ -714,6 +715,25 @@ impl RuleFilter<'_> {
}
}

impl<'a> Debug for RuleFilter<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(self, f)
}
}

impl<'a> Display for RuleFilter<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
RuleFilter::Group(group) => {
write!(f, "{group}")
}
RuleFilter::Rule(group, rule) => {
write!(f, "{group}/{rule}")
}
}
}
}

/// Allows filtering the list of rules that will be executed in a run of the analyzer,
/// and at what source code range signals (diagnostics or actions) may be raised
#[derive(Debug, Default, Clone, Copy)]
Expand Down
130 changes: 130 additions & 0 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,3 +1300,133 @@ import { bar, foom, lorem } from "foo";
result,
));
}

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

let rome_json = r#"{
"linter": {
"rules": { "all": true }
}
}"#;

let file_path = Path::new("fix.js");
fs.insert(file_path.into(), FIX_BEFORE.as_bytes());

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

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Arguments::from_vec(vec![OsString::from("check"), file_path.as_os_str().into()]),
);

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"all_rules",
fs,
console,
result,
));
}

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

let rome_json = r#"{
"linter": {
"rules": {
"all": true,
"style": {
"all": false
}
}
}
}"#;

// style/noArguments
// style/noShoutyConstants
// style/useSingleVarDeclarator
let code = r#"
function f() {arguments;}
const FOO = "FOO";
var x, y;
"#;

let file_path = Path::new("fix.js");
fs.insert(file_path.into(), code.as_bytes());

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

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Arguments::from_vec(vec![OsString::from("check"), file_path.as_os_str().into()]),
);

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"top_level_all_down_level_not_all",
fs,
console,
result,
));
}

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

let rome_json = r#"{
"linter": {
"rules": {
"all": false,
"style": {
"all": true
}
}
}
}"#;

// style/noArguments
// style/noShoutyConstants
// style/useSingleVarDeclarator
let code = r#"
function f() {arguments;}
const FOO = "FOO";
var x, y;
"#;

let file_path = Path::new("fix.js");
fs.insert(file_path.into(), code.as_bytes());

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

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Arguments::from_vec(vec![OsString::from("check"), file_path.as_os_str().into()]),
);

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"top_level_not_all_down_level_all",
fs,
console,
result,
));
}
16 changes: 14 additions & 2 deletions crates/rome_cli/tests/snap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use rome_console::fmt::{Formatter, Termcolor};
use rome_console::{markup, BufferConsole, Markup};
use rome_diagnostics::termcolor::NoColor;
use rome_diagnostics::{print_diagnostic_to_string, Error};
use rome_formatter::IndentStyle;
use rome_fs::{FileSystemExt, MemoryFileSystem};
use rome_json_formatter::context::JsonFormatOptions;
use rome_json_formatter::format_node;
use rome_json_parser::parse_json;
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::env::{current_exe, temp_dir};
Expand Down Expand Up @@ -45,11 +49,19 @@ impl CliSnapshot {
let mut content = String::new();

if let Some(configuration) = &self.configuration {
let parsed = parse_json(&redact_snapshot(configuration));
let formatted = format_node(
JsonFormatOptions::default().with_indent_style(IndentStyle::Space(2)),
&parsed.syntax(),
)
.expect("formatted JSON")
.print()
.expect("printed JSON");

content.push_str("## `rome.json`\n\n");
content.push_str("```json");
content.push('\n');
content.push_str(&redact_snapshot(configuration));
content.push('\n');
content.push_str(formatted.as_code());
content.push_str("```");
content.push_str("\n\n")
}
Expand Down
92 changes: 92 additions & 0 deletions crates/rome_cli/tests/snapshots/main_commands_check/all_rules.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
## `rome.json`

```json
{
"linter": {
"rules": { "all": true }
}
}
```

## `fix.js`

```js

if(a != -0) {}

```

# Termination Message

```block
internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Some errors were emitted while running checks
```

# Emitted Messages

```block
fix.js:2:4 lint/suspicious/noCompareNegZero FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Do not use the != operator to compare against -0.
> 2 │ if(a != -0) {}
│ ^^^^^^^
3 │
i Safe fix: Replace -0 with 0
2 │ if(a·!=·-0)·{}
│ -
```

```block
fix.js:2:6 lint/suspicious/noDoubleEquals FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Use !== instead of !=
> 2 │ if(a != -0) {}
│ ^^
3 │
i != is only allowed when comparing against null
> 2 │ if(a != -0) {}
│ ^^
3 │
i Using !== may be unsafe if you are relying on type coercion
i Suggested fix: Use !==
2 │ if(a·!==·-0)·{}
│ +
```

```block
fix.js:2:4 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The a variable is undeclared
> 2 │ if(a != -0) {}
│ ^
3 │
```

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


Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ expression: content
{
"linter": {
"rules": {
"recommended": false,
"correctness": {
"recommended": true
}
"recommended": false,
"correctness": {
"recommended": true
}
}
}
}
Expand Down
Loading

0 comments on commit 89e6386

Please sign in to comment.