Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(biome_analyze): expose RuleMetadata via RuleContext #2821

Merged
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
33 changes: 33 additions & 0 deletions crates/biome_analyze/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::options::{JsxRuntime, PreferredQuote};
use crate::RuleMetadata;
use crate::{registry::RuleRoot, FromServices, Queryable, Rule, RuleKey, ServiceBag};
use biome_diagnostics::{Error, Result};
use std::ops::Deref;
Expand Down Expand Up @@ -60,6 +61,38 @@ where
self.root.clone()
}

/// Returns the metadata of the rule
///
/// The metadata contains information about the rule, such as the name, version, language, and whether it is recommended.
///
/// ## Examples
/// ```rust,ignore
/// declare_rule! {
/// /// Some doc
/// pub(crate) Foo {
/// version: "0.0.0",
/// name: "foo",
/// language: "js",
/// recommended: true,
/// }
/// }
///
/// impl Rule for Foo {
/// const CATEGORY: RuleCategory = RuleCategory::Lint;
/// type Query = ();
/// type State = ();
/// type Signals = ();
/// type Options = ();
///
/// fn run(ctx: &RuleContext<Self>) -> Self::Signals {
/// assert_eq!(ctx.metadata().name, "foo");
/// }
/// }
/// ```
pub fn metadata(&self) -> &RuleMetadata {
&R::METADATA
}

/// It retrieves the options that belong to a rule, if they exist.
///
/// In order to retrieve a typed data structure, you have to create a deserializable
Expand Down