Skip to content

Commit

Permalink
feat: allow "info" severity for analyzer rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 29, 2024
1 parent 04000a5 commit 294259c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 3 deletions.
54 changes: 53 additions & 1 deletion crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use std::path::{Path, PathBuf};
use crate::configs::{
CONFIG_FILE_SIZE_LIMIT, CONFIG_IGNORE_SYMLINK, CONFIG_LINTER_AND_FILES_IGNORE,
CONFIG_LINTER_DISABLED, CONFIG_LINTER_DISABLED_JSONC, CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC,
CONFIG_LINTER_IGNORED_FILES, CONFIG_LINTER_SUPPRESSED_GROUP, CONFIG_LINTER_SUPPRESSED_RULE,
CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC_INFO, CONFIG_LINTER_IGNORED_FILES,
CONFIG_LINTER_SUPPRESSED_GROUP, CONFIG_LINTER_SUPPRESSED_RULE,
CONFIG_LINTER_UPGRADE_DIAGNOSTIC, CONFIG_RECOMMENDED_GROUP,
};
use crate::snap_test::{assert_file_contents, markup_to_string, SnapshotPayload};
Expand Down Expand Up @@ -628,6 +629,57 @@ fn downgrade_severity() {
));
}

#[test]
fn downgrade_severity_info() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
let file_path = Path::new("biome.json");
fs.insert(
file_path.into(),
CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC_INFO.as_bytes(),
);

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

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(
[
("lint"),
"--error-on-warnings",
file_path.as_os_str().to_str().unwrap(),
]
.as_slice(),
),
);

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

let messages = &console.out_buffer;

assert_eq!(
messages
.iter()
.filter(|m| m.level == LogLevel::Error)
.filter(|m| {
let content = format!("{:#?}", m.content);
content.contains("suspicious/noDebugger")
})
.count(),
1
);

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

#[test]
fn upgrade_severity() {
let mut fs = MemoryFileSystem::default();
Expand Down
11 changes: 11 additions & 0 deletions crates/biome_cli/tests/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ pub const CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC: &str = r#"{
}
}"#;

pub const CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC_INFO: &str = r#"{
"linter": {
"rules": {
"recommended": true,
"suspicious": {
"noDebugger": "info"
}
}
}
}"#;

pub const CONFIG_LINTER_UPGRADE_DIAGNOSTIC: &str = r#"{
"linter": {
"rules": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{
"linter": {
"rules": {
"recommended": true,
"suspicious": {
"noDebugger": "info"
}
}
}
}
```

## `file.js`

```js
debugger;
```

# Emitted Messages

```block
file.js:1:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
i This is an unexpected use of the debugger statement.
> 1 │ debugger;
│ ^^^^^^^^^
i Unsafe fix: Remove debugger statement
1 │ debugger;
│ ---------
```

```block
Checked 1 file in <TIME>. No fixes needed.
```
2 changes: 1 addition & 1 deletion packages/@biomejs/backend-jsonrpc/src/workspace.ts

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

2 changes: 1 addition & 1 deletion packages/@biomejs/biome/configuration_schema.json

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

0 comments on commit 294259c

Please sign in to comment.