Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/dry-birds-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Improved the diagnostics of the rules `useSortedClasses` and `noUnnecessaryConditions`. The diagnostics now state that these rules are a work in progress and link to the relevant GitHub issue.
21 changes: 21 additions & 0 deletions crates/biome_analyze/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The analyzer allows implementors to create **three different** types of rules:
- [Naming Conventions for Rules](#naming-conventions-for-rules)
- [What a Rule should say to the User](#what-a-rule-should-say-to-the-user)
- [Placement of New Rules](#placement-of-new-rules)
+ [Mark a rule as a work in progress](#mark-a-rule-as-a-work-in-progress)
+ [Creating and Implementing the Rule](#creating-and-implementing-the-rule)
+ [Coding Tips for Rules](#coding-tips-for-rules)
- [`declare_lint_rule!` macro](#declare_lint_rule-macro)
Expand Down Expand Up @@ -219,6 +220,26 @@ New rules **must** be placed inside the `nursery` group. This group is meant as
>
> If you aren't familiar with Biome's APIs, this is an option that you have. If you decide to use this option, you should make sure to describe your plan in an issue.

### Mark a rule as a work in progress

Sometimes nursery rules aren't completed yet – missing use cases, code actions, etc. – and you might want to communicate that to your users.

You can add `issue_number` to the rule macro, and Biome will:
- Add a footnote to the diagnostic of the rule with a link to the issue, e.g. `https://github.com/biomejs/biome/issues/1111`
- Add a note on the website, with a link to the issue.

```rust
declare_lint_rule! {
/// Docs
pub(crate) NoVar {
version: "next",
name: "noVar",
language: "js",
issue_number: Some("1111"),
}
}
```

### Creating and Implementing the Rule

Let's say we want to create a new **lint** rule called `useMyRuleName`, follow these steps:
Expand Down
9 changes: 9 additions & 0 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct RuleMetadata {
pub severity: Severity,
/// Domains applied by this rule
pub domains: &'static [RuleDomain],
/// Use this field to tag the rule as being worked, which means the rule is still far from being completed.
/// Possible bugs should be reported in that issue.
pub issue_number: Option<&'static str>,
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
Expand Down Expand Up @@ -609,6 +612,7 @@ impl RuleMetadata {
sources: &[],
severity: Severity::Information,
domains: &[],
issue_number: None,
}
}

Expand Down Expand Up @@ -647,6 +651,11 @@ impl RuleMetadata {
self
}

pub const fn issue_number(mut self, issue_number: Option<&'static str>) -> Self {
self.issue_number = issue_number;
self
}

pub fn applicability(&self) -> Applicability {
self.fix_kind
.try_into()
Expand Down
9 changes: 8 additions & 1 deletion crates/biome_analyze/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
registry::{RuleLanguage, RuleRoot},
rule::Rule,
};
use biome_console::MarkupBuf;
use biome_console::{MarkupBuf, markup};
use biome_diagnostics::{Applicability, CodeSuggestion, Error, advice::CodeSuggestionAdvice};
use biome_rowan::{BatchMutation, Language};
use std::iter::FusedIterator;
Expand Down Expand Up @@ -376,6 +376,13 @@ where

R::diagnostic(&ctx, &self.state).map(|mut diagnostic| {
diagnostic.severity = ctx.metadata().severity;

if let Some(issue_number) = ctx.metadata().issue_number {
let url = format!("https://github.com/biomejs/biome/issues/{}", issue_number);
diagnostic = diagnostic.note(markup! {
"This rule is still being actively worked on, so it may be missing features or have rough edges. Visit "<Hyperlink href={url.as_str()}>{url.as_str()}</Hyperlink>" for more information or to report possible bugs."
});
}
AnalyzerDiagnostic::from(diagnostic)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ declare_lint_rule! {
recommended: false,
severity: Severity::Warning,
domains: &[RuleDomain::Project],
issue_number: Some("6611"),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ declare_lint_rule! {
language: "js",
recommended: false,
fix_kind: FixKind::Unsafe,
issue_number: Some("1274"),
}
}

Expand Down
Loading
Loading