Skip to content

Commit

Permalink
feat(analyzer): useSortedKeys for JSON objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Apr 11, 2024
1 parent 45e2c05 commit 34173a3
Show file tree
Hide file tree
Showing 35 changed files with 505 additions and 60 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 @@ -160,6 +160,7 @@ ignore = "0.4.21"
indexmap = "1.9.3"
insta = "1.36.1"
lazy_static = "1.4.0"
natord = "1.0.9"
oxc_resolver = "1.4.0"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
Expand All @@ -175,7 +176,6 @@ tokio = { version = "1.36.0" }
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
unicode-bom = "2.0.3"


[profile.dev.package.biome_wasm]
debug = true
opt-level = "s"
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 @@ -8,11 +8,11 @@ use biome_console::fmt::Display;
use biome_console::{markup, MarkupBuf};
use biome_diagnostics::advice::CodeSuggestionAdvice;
use biome_diagnostics::location::AsSpan;
use biome_diagnostics::Applicability;
use biome_diagnostics::{
Advices, Category, Diagnostic, DiagnosticTags, Location, LogCategory, MessageAndDescription,
Visit,
};
use biome_diagnostics::{Applicability, DiagnosticExt};
use biome_rowan::{AstNode, BatchMutation, BatchMutationExt, Language, TextRange};
use std::cmp::Ordering;
use std::fmt::Debug;
Expand Down Expand Up @@ -347,7 +347,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 @@ -381,6 +381,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
4 changes: 2 additions & 2 deletions crates/biome_css_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_color_invalid_hex;
pub mod no_duplicate_font_names;

declare_group! {
declare_lint_group! {
pub Nursery {
name : "nursery" ,
rules : [
Expand Down
3 changes: 2 additions & 1 deletion crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ define_categories! {
"lint/nursery/noConsole": "https://biomejs.dev/linter/rules/no-console",
"lint/nursery/noDoneCallback": "https://biomejs.dev/linter/rules/no-done-callback",
"lint/nursery/noDuplicateElseIf": "https://biomejs.dev/linter/rules/no-duplicate-else-if",
"lint/nursery/noDuplicateFontNames": "https://biomejs.dev/linter/rules/no-font-family-duplicate-names",
"lint/nursery/noDuplicateJsonKeys": "https://biomejs.dev/linter/rules/no-duplicate-json-keys",
"lint/nursery/noDuplicateTestHooks": "https://biomejs.dev/linter/rules/no-duplicate-test-hooks",
"lint/nursery/noEvolvingAny": "https://biomejs.dev/linter/rules/no-evolving-any",
"lint/nursery/noExcessiveNestedTestSuites": "https://biomejs.dev/linter/rules/no-excessive-nested-test-suites",
"lint/nursery/noExportsInTest": "https://biomejs.dev/linter/rules/no-exports-in-test",
"lint/nursery/noFocusedTests": "https://biomejs.dev/linter/rules/no-focused-tests",
"lint/nursery/noDuplicateFontNames": "https://biomejs.dev/linter/rules/no-font-family-duplicate-names",
"lint/nursery/noMisplacedAssertion": "https://biomejs.dev/linter/rules/no-misplaced-assertion",
"lint/nursery/noNamespaceImport": "https://biomejs.dev/linter/rules/no-namespace-import",
"lint/nursery/noNodejsModules": "https://biomejs.dev/linter/rules/no-nodejs-modules",
Expand Down Expand Up @@ -231,6 +231,7 @@ 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",
"assists/nursery/useSortedKeys": "https://biomejs.dev/linter/rules/use-sorted-keys",
;
// General categories
"files/missingHandler",
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 @@ -27,7 +27,7 @@ biome_string_case = { workspace = true }
biome_suppression = { workspace = true }
biome_unicode_table = { workspace = true }
lazy_static = { workspace = true }
natord = "1.0.9"
natord = { workspace = true }
roaring = "0.10.1"
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_access_key;
pub mod no_aria_hidden_on_focusable;
Expand Down Expand Up @@ -33,7 +33,7 @@ pub mod use_valid_aria_role;
pub mod use_valid_aria_values;
pub mod use_valid_lang;

declare_group! {
declare_lint_group! {
pub A11y {
name : "a11y" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/complexity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_banned_types;
pub mod no_empty_type_parameters;
Expand Down Expand Up @@ -30,7 +30,7 @@ pub mod use_regex_literals;
pub mod use_simple_number_keys;
pub mod use_simplified_logic_expression;

declare_group! {
declare_lint_group! {
pub Complexity {
name : "complexity" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/correctness.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_children_prop;
pub mod no_const_assign;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub mod use_is_nan;
pub mod use_valid_for_direction;
pub mod use_yield;

declare_group! {
declare_lint_group! {
pub Correctness {
name : "correctness" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_barrel_file;
pub mod no_console;
Expand All @@ -25,7 +25,7 @@ pub mod use_jsx_key_in_iterable;
pub mod use_node_assert_strict;
pub mod use_sorted_classes;

declare_group! {
declare_lint_group! {
pub Nursery {
name : "nursery" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/performance.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_accumulating_spread;
pub mod no_delete;

declare_group! {
declare_lint_group! {
pub Performance {
name : "performance" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/security.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_dangerously_set_inner_html;
pub mod no_dangerously_set_inner_html_with_children;
pub mod no_global_eval;

declare_group! {
declare_lint_group! {
pub Security {
name : "security" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_arguments;
pub mod no_comma_operator;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub mod use_single_var_declarator;
pub mod use_template;
pub mod use_while;

declare_group! {
declare_lint_group! {
pub Style {
name : "style" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/lint/suspicious.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_approximative_numeric_constant;
pub mod no_array_index_key;
Expand Down Expand Up @@ -53,7 +53,7 @@ pub mod use_is_array;
pub mod use_namespace_keyword;
pub mod use_valid_typeof;

declare_group! {
declare_lint_group! {
pub Suspicious {
name : "suspicious" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/syntax/correctness.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_duplicate_private_class_members;
pub mod no_initializer_with_definite;
pub mod no_super_without_extends;

declare_group! {
declare_lint_group! {
pub Correctness {
name : "correctness" ,
rules : [
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/syntax/nursery.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

use biome_analyze::declare_group;
use biome_analyze::declare_lint_group;

pub mod no_type_only_import_attributes;

declare_group! {
declare_lint_group! {
pub Nursery {
name : "nursery" ,
rules : [
Expand Down
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 ,
]
}
}

0 comments on commit 34173a3

Please sign in to comment.