Skip to content

Commit

Permalink
refactor(biome_analyze): expose RuleMetadata via RuleContext
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed May 15, 2024
1 parent 7283b03 commit 310c891
Showing 1 changed file with 33 additions and 0 deletions.
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

0 comments on commit 310c891

Please sign in to comment.