Skip to content

Commit

Permalink
feat(analyzer): useSortedKeys for JSON objects (#2412)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Jun 11, 2024
1 parent eca1507 commit e3e93cc
Show file tree
Hide file tree
Showing 36 changed files with 482 additions and 72 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ ignore = "0.4.21"
indexmap = { version = "2.2.6", features = ["serde"] }
insta = "1.39.0"
lazy_static = "1.4.0"
natord = "1.0.9"
oxc_resolver = "1.8.1"
proc-macro2 = "1.0.85"
quickcheck = "1.0.3"
Expand All @@ -187,7 +188,6 @@ tracing = { version = "0.1.40", default-features = false, features =
tracing-subscriber = "0.3.18"
unicode-bom = "2.0.3"
unicode-width = "0.1.12"

[profile.dev.package.biome_wasm]
debug = true
opt-level = "s"
Expand Down
4 changes: 3 additions & 1 deletion crates/biome_analyze/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ impl ActionCategory {
}
}

/// The sub-category of a refactor code action
/// The sub-category of a refactor code action.
///
/// [Check the LSP spec](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeActionKind) for more information:
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
Expand Down
41 changes: 39 additions & 2 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub trait RuleGroup {
/// This macro is used by the codegen script to declare an analyzer rule group,
/// and implement the [RuleGroup] trait for it
#[macro_export]
macro_rules! declare_group {
macro_rules! declare_lint_group {
( $vis:vis $id:ident { name: $name:tt, rules: [ $( $( $rule:ident )::* , )* ] } ) => {
$vis enum $id {}

Expand Down Expand Up @@ -442,6 +442,43 @@ macro_rules! declare_group {
};
}

/// This macro is used by the codegen script to declare an analyzer rule group,
/// and implement the [RuleGroup] trait for it
#[macro_export]
macro_rules! declare_assists_group {
( $vis:vis $id:ident { name: $name:tt, rules: [ $( $( $rule:ident )::* , )* ] } ) => {
$vis enum $id {}

impl $crate::RuleGroup for $id {
type Language = <( $( $( $rule )::* , )* ) as $crate::GroupLanguage>::Language;
type Category = super::Category;

const NAME: &'static str = $name;

fn record_rules<V: $crate::RegistryVisitor<Self::Language> + ?Sized>(registry: &mut V) {
$( registry.record_rule::<$( $rule )::*>(); )*
}
}

pub(self) use $id as Group;

// Declare a `group_category!` macro in the context of this module (and
// all its children). This macro takes the name of a rule as a string
// literal token and expands to the category of the lint rule with this
// name within this group.
// This is implemented by calling the `category_concat!` macro with the
// "lint" prefix, the name of this group, and the rule name argument
#[allow(unused_macros)]
macro_rules! group_category {
( $rule_name:tt ) => { $crate::category_concat!( "assists", $name, $rule_name ) };
}

// Re-export the macro for child modules, so `declare_rule!` can access
// the category of its parent group by using the `super` module
pub(self) use group_category;
};
}

/// A group category is a collection of rule groups under a given category ID,
/// serving as a broad classification on the kind of diagnostic or code action
/// these rule emit, and allowing whole categories of rules to be disabled at
Expand Down Expand Up @@ -880,7 +917,7 @@ impl<L: Language> RuleAction<L> {
pub fn new(
category: ActionCategory,
applicability: impl Into<Applicability>,
message: impl biome_console::fmt::Display,
message: impl Display,
mutation: BatchMutation<L>,
) -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_css_analyze/src/lint/nursery.rs

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

6 changes: 5 additions & 1 deletion crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ define_categories! {
"lint/suspicious/useIsArray": "https://biomejs.dev/linter/rules/use-is-array",
"lint/suspicious/useNamespaceKeyword": "https://biomejs.dev/linter/rules/use-namespace-keyword",
"lint/suspicious/useValidTypeof": "https://biomejs.dev/linter/rules/use-valid-typeof",
;
; // end lint rules

"assists/nursery/useSortedKeys",
// end assist rules

// General categories
"files/missingHandler",
"format",
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ biome_unicode_table = { workspace = true }
bitflags = { workspace = true }
enumflags2 = { workspace = true }
lazy_static = { workspace = true }
natord = "1.0.9"
natord = { workspace = true }
regex = { workspace = true }
roaring = "0.10.5"
rustc-hash = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/assists/correctness.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/a11y.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/complexity.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/correctness.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/nursery.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/performance.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/security.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/style.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/suspicious.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/syntax/correctness.rs

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

4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/syntax/nursery.rs

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

16 changes: 9 additions & 7 deletions crates/biome_json_analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ version = "0.5.7"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
biome_analyze = { workspace = true }
biome_console = { workspace = true }
biome_diagnostics = { workspace = true }
biome_json_syntax = { workspace = true }
biome_rowan = { workspace = true }
lazy_static = { workspace = true }
rustc-hash = { workspace = true }
biome_analyze = { workspace = true }
biome_console = { workspace = true }
biome_diagnostics = { workspace = true }
biome_json_factory = { workspace = true }
biome_json_syntax = { workspace = true }
biome_rowan = { workspace = true }
lazy_static = { workspace = true }
natord = { workspace = true }
rustc-hash = { workspace = true }

[dev-dependencies]
biome_json_parser = { path = "../biome_json_parser" }
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_json_analyze/src/assists.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

pub mod nursery;
::biome_analyze::declare_category! { pub Assists { kind : Action , groups : [self :: nursery :: Nursery ,] } }
14 changes: 14 additions & 0 deletions crates/biome_json_analyze/src/assists/nursery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_assists_group;

pub mod use_sorted_keys;

declare_assists_group! {
pub Nursery {
name : "nursery" ,
rules : [
self :: use_sorted_keys :: UseSortedKeys ,
]
}
}
Loading

0 comments on commit e3e93cc

Please sign in to comment.