Skip to content

Commit

Permalink
feat: allow "info" severity for analyzer rules (#3014)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored May 29, 2024
1 parent 2e079f9 commit 21e2512
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 4 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
- Add option `json.linter.enabled` to control the linter for JSON (and its super languages) files. Contributed by @ematipico
- Add option `css.linter.enabled` to control the linter for CSS (and its super languages) files. Contributed by @ematipico
- Add option `css.formatter`, to control the formatter options for CSS (and its super languages) files. Contributed by @ematipico
- You can now change the severity of lint rules down to `"info"`. The `"info"` severity doesn't emit error codes, and it isn't affected by other options like `--error-on-warnings`:

```json
{
"linter": {
"rules": {
"suspicious": {
"noDebugger": "info"
}
}
}
}
```
Contributed by @ematipico

#### Enhancements

Expand Down
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.
```
6 changes: 5 additions & 1 deletion crates/biome_configuration/src/linter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ impl From<RulePlainConfiguration> for Severity {
match conf {
RulePlainConfiguration::Warn => Severity::Warning,
RulePlainConfiguration::Error => Severity::Error,
_ => unreachable!("the rule is turned off, it should not step in here"),
RulePlainConfiguration::Info => Severity::Information,
RulePlainConfiguration::Off => {
unreachable!("the rule is turned off, it should not step in here")
}
}
}
}
Expand All @@ -251,6 +254,7 @@ pub enum RulePlainConfiguration {
#[default]
Warn,
Error,
Info,
Off,
}

Expand Down
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 21e2512

Please sign in to comment.