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

feat(biome_css_analyze): add rule useSortedProperties #4063

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
12 changes: 12 additions & 0 deletions crates/biome_configuration/src/analyzer/linter/rules.rs

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

35 changes: 35 additions & 0 deletions crates/biome_css_analyze/src/keywords.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{collections::HashMap, sync::LazyLock};

pub const BASIC_KEYWORDS: [&str; 5] = ["initial", "inherit", "revert", "revert-layer", "unset"];

// https://drafts.csswg.org/css-fonts/#system-family-name-value
Expand Down Expand Up @@ -5422,6 +5424,25 @@ pub const LONGHAND_SUB_PROPERTIES_OF_SHORTHAND_PROPERTIES: [&[&str]; 57] = [
],
];

// longhand => shorthand map
pub(crate) static LONGHAND_SUB_PROPERTIES_MAP: LazyLock<HashMap<String, String>> =
LazyLock::new(|| {
let cap: usize = LONGHAND_SUB_PROPERTIES_OF_SHORTHAND_PROPERTIES
.map(|list| list.len())
.iter()
.sum();
let mut map: HashMap<String, String> = HashMap::with_capacity(cap);
for (shorthand, longhand_list) in SHORTHAND_PROPERTIES
.iter()
.zip(LONGHAND_SUB_PROPERTIES_OF_SHORTHAND_PROPERTIES)
{
for longhand in longhand_list {
map.insert((*longhand).to_string(), (*shorthand).to_string());
}
}
map
});
simon-paris marked this conversation as resolved.
Show resolved Hide resolved

pub const RESET_TO_INITIAL_PROPERTIES_BY_BORDER: [&str; 6] = [
"border-image",
"border-image-outset",
Expand All @@ -5447,6 +5468,20 @@ pub const RESET_TO_INITIAL_PROPERTIES_BY_FONT: [&str; 13] = [
"font-variation-settings",
];

pub(crate) static RESET_TO_INITIAL_PROPERTIES_MAP: LazyLock<HashMap<String, String>> =
LazyLock::new(|| {
let cap = RESET_TO_INITIAL_PROPERTIES_BY_BORDER.len()
+ RESET_TO_INITIAL_PROPERTIES_BY_BORDER.len();
let mut map: HashMap<String, String> = HashMap::with_capacity(cap);
for longhand in RESET_TO_INITIAL_PROPERTIES_BY_BORDER {
map.insert(longhand.to_string(), "border".to_string());
}
for longhand in RESET_TO_INITIAL_PROPERTIES_BY_BORDER {
map.insert(longhand.to_string(), "font".to_string());
}
map
});

// https://developer.mozilla.org/ja/docs/Web/HTML/Element
// https://github.com/sindresorhus/html-tags/blob/main/html-tags.json
pub(crate) const HTML_TAGS: [&str; 150] = [
Expand Down
5 changes: 4 additions & 1 deletion crates/biome_css_analyze/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod keywords;
mod lint;
pub mod options;
mod order;
mod registry;
mod services;
mod suppression_action;
Expand All @@ -10,14 +11,16 @@ pub use crate::registry::visit_registry;
use crate::suppression_action::CssSuppressionAction;
use biome_analyze::{
AnalysisFilter, AnalyzerOptions, AnalyzerSignal, ControlFlow, LanguageRoot, MatchQueryParams,
MetadataRegistry, RuleRegistry, SuppressionKind,
MetadataRegistry, RuleAction, RuleRegistry, SuppressionKind,
};
use biome_css_syntax::CssLanguage;
use biome_diagnostics::{category, Error};
use biome_suppression::{parse_suppression_comment, SuppressionDiagnostic};
use std::ops::Deref;
use std::sync::LazyLock;

pub(crate) type CssRuleAction = RuleAction<CssLanguage>;

pub static METADATA: LazyLock<MetadataRegistry> = LazyLock::new(|| {
let mut metadata = MetadataRegistry::default();
visit_registry(&mut metadata);
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_css_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod no_unknown_pseudo_class;
pub mod no_unknown_pseudo_element;
pub mod no_unknown_type_selector;
pub mod no_value_at_rule;
pub mod use_sorted_properties;

declare_lint_group! {
pub Nursery {
Expand All @@ -25,6 +26,7 @@ declare_lint_group! {
self :: no_unknown_pseudo_element :: NoUnknownPseudoElement ,
self :: no_unknown_type_selector :: NoUnknownTypeSelector ,
self :: no_value_at_rule :: NoValueAtRule ,
self :: use_sorted_properties :: UseSortedProperties ,
]
}
}
Loading
Loading