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(config): reduce size by 350% using exact rule options #1876

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Linter:
correctness/all = true
nursery/useConsistentArrayType = {"level":"warn","options":{"syntax":"shorthand"}}
style/noNonNullAssertion = "off"
suspicious/noCommentText = {"level":"warn"}
suspicious/noCommentText = {"level":"warn","options":null}
Conaclos marked this conversation as resolved.
Show resolved Hide resolved

Server:
Version: 0.0.0
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_css_analyze/src/analyzers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

pub(crate) mod nursery;
::biome_analyze::declare_category! { pub (crate) Analyzers { kind : Lint , groups : [self :: nursery :: Nursery ,] } }
pub mod nursery;
::biome_analyze::declare_category! { pub Analyzers { kind : Lint , groups : [self :: nursery :: Nursery ,] } }
4 changes: 2 additions & 2 deletions crates/biome_css_analyze/src/analyzers/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use biome_analyze::declare_group;

pub(crate) mod noop;
pub mod noop;

declare_group! {
pub (crate) Nursery {
pub Nursery {
name : "nursery" ,
rules : [
self :: noop :: Noop ,
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_css_analyze/src/analyzers/nursery/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use biome_css_syntax::CssColor;

declare_rule! {
/// Noop rule
pub(crate) Noop {
pub Noop {
version: "next",
name: "noop",
}
Expand Down
10 changes: 10 additions & 0 deletions crates/biome_deserialize/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ impl Deserializable for PathBuf {
}
}

impl<T: Deserializable> Deserializable for Box<T> {
fn deserialize(
value: &impl DeserializableValue,
name: &str,
diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> Option<Self> {
T::deserialize(value, name, diagnostics).map(Box::new)
}
}

impl<T: Deserializable> Deserializable for Vec<T> {
fn deserialize(
value: &impl DeserializableValue,
Expand Down
59 changes: 52 additions & 7 deletions crates/biome_deserialize_macros/src/deserializable_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ fn generate_deserializable_newtype(
};

let trait_bounds = generate_trait_bounds(&generics);
let generics = generate_generics_without_trait_bounds(&generics);

quote! {
impl #generics biome_deserialize::Deserializable for #ident #generics #trait_bounds {
Expand Down Expand Up @@ -401,8 +402,6 @@ fn generate_deserializable_struct(
})
.collect();

let trait_bounds = generate_trait_bounds(&generics);

let validator = if required_fields.is_empty() {
quote! {}
} else {
Expand Down Expand Up @@ -443,16 +442,21 @@ fn generate_deserializable_struct(
validator
};

let tuple_type = generate_generics_tuple(&generics);
let trait_bounds = generate_trait_bounds(&generics);
let generics = generate_generics_without_trait_bounds(&generics);

quote! {
impl #generics biome_deserialize::Deserializable for #ident #generics #trait_bounds {
fn deserialize(
value: &impl biome_deserialize::DeserializableValue,
name: &str,
diagnostics: &mut Vec<biome_deserialize::DeserializationDiagnostic>,
) -> Option<Self> {
struct Visitor #generics;
impl #generics biome_deserialize::DeserializationVisitor for Visitor #generics {
type Output = #ident;
use std::marker::PhantomData;
struct Visitor #generics (PhantomData< #tuple_type >);
impl #generics biome_deserialize::DeserializationVisitor for Visitor #generics #trait_bounds {
type Output = #ident #generics;

const EXPECTED_TYPE: biome_deserialize::VisitableType = biome_deserialize::VisitableType::MAP;

Expand Down Expand Up @@ -486,7 +490,7 @@ fn generate_deserializable_struct(
}
}

value.deserialize(Visitor, name, diagnostics)
value.deserialize(Visitor(PhantomData), name, diagnostics)
}
}
}
Expand All @@ -498,6 +502,7 @@ fn generate_deserializable_from(
data: DeserializableFromData,
) -> TokenStream {
let trait_bounds = generate_trait_bounds(&generics);
let generics = generate_generics_without_trait_bounds(&generics);
let from = data.from;
let validator = if data.with_validator {
quote! {
Expand Down Expand Up @@ -530,6 +535,7 @@ fn generate_deserializable_try_from(
data: DeserializableTryFromData,
) -> TokenStream {
let trait_bounds = generate_trait_bounds(&generics);
let generics = generate_generics_without_trait_bounds(&generics);
let try_from = data.try_from;
let validator = if data.with_validator {
quote! {
Expand Down Expand Up @@ -565,14 +571,40 @@ fn generate_deserializable_try_from(
}
}

fn generate_generics_without_trait_bounds(generics: &Generics) -> TokenStream {
if generics.params.is_empty() {
quote! {}
} else {
let params = generics.params.iter().map(|param| match param {
GenericParam::Type(ty) => {
let attrs = ty
.attrs
.iter()
.fold(quote! {}, |acc, attr| quote! { #acc #attr });
let ident = &ty.ident;
quote! { #attrs #ident }
}
_ => abort!(generics, "Unsupported generic parameter"),
});
quote! {
< #(#params),* >
}
}
}
Conaclos marked this conversation as resolved.
Show resolved Hide resolved

fn generate_trait_bounds(generics: &Generics) -> TokenStream {
if generics.params.is_empty() {
quote! {}
} else {
let params = generics.params.iter().map(|param| match param {
GenericParam::Type(ty) => {
let ident = &ty.ident;
quote! { #ident: biome_deserialize::Deserializable }
let bounds = &ty.bounds;
if bounds.is_empty() {
quote! { #ident: biome_deserialize::Deserializable }
} else {
quote! { #ident: #bounds + biome_deserialize::Deserializable }
}
}
_ => abort!(generics, "Unsupported generic parameter"),
});
Expand All @@ -581,3 +613,16 @@ fn generate_trait_bounds(generics: &Generics) -> TokenStream {
}
}
}

fn generate_generics_tuple(generics: &Generics) -> TokenStream {
let params = generics.params.iter().map(|param| match param {
GenericParam::Type(ty) => {
let ident = &ty.ident;
quote! { #ident }
}
_ => abort!(generics, "Unsupported generic parameter"),
});
quote! {
( #(#params),* )
}
}
16 changes: 8 additions & 8 deletions crates/biome_js_analyze/src/analyzers.rs

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

36 changes: 18 additions & 18 deletions crates/biome_js_analyze/src/analyzers/a11y.rs

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

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare_rule! {
/// - [WebAIM: Keyboard Accessibility - Accesskey](https://webaim.org/techniques/keyboard/accesskey#spec)
/// - [MDN `accesskey` documentation](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/accesskey)
///
pub(crate) NoAccessKey {
pub NoAccessKey {
version: "1.0.0",
name: "noAccessKey",
source: RuleSource::EslintJsxA11y("no-access-key"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ declare_rule! {
/// - [WHATWG HTML Standard, The autofocus attribute](https://html.spec.whatwg.org/multipage/interaction.html#attr-fe-autofocus)
/// - [The accessibility of HTML 5 autofocus](https://brucelawson.co.uk/2009/the-accessibility-of-html-5-autofocus/)
///
pub(crate) NoAutoFocus {
pub NoAutofocus {
version: "1.0.0",
name: "noAutofocus",
source: RuleSource::EslintJsxA11y("no-autofocus"),
Expand All @@ -66,7 +66,7 @@ declare_rule! {
}
}

impl Rule for NoAutoFocus {
impl Rule for NoAutofocus {
type Query = Ast<AnyJsxElement>;
type State = JsxAttribute;
type Signals = Option<Self::State>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare_rule! {
/// ```jsx
/// <a href='http://external.link' target='_blank' rel="noopener" {...props}>child</a>
/// ```
pub(crate) NoBlankTarget {
pub NoBlankTarget {
version: "1.0.0",
name: "noBlankTarget",
source: RuleSource::EslintReact("jsx-no-target-blank"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare_rule! {
///
/// - [WCAG 2.2.2](https://www.w3.org/WAI/WCAG21/Understanding/pause-stop-hide)
///
pub(crate) NoDistractingElements {
pub NoDistractingElements {
version: "1.0.0",
name: "noDistractingElements",
source: RuleSource::EslintJsxA11y("no-distracting-elements"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare_rule! {
/// - [WCAG 1.3.1](https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships)
/// - [WCAG 4.1.1](https://www.w3.org/WAI/WCAG21/Understanding/parsing)
///
pub(crate) NoHeaderScope {
pub NoHeaderScope {
version: "1.0.0",
name: "noHeaderScope",
source: RuleSource::EslintJsxA11y("scope"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare_rule! {
/// </>
/// ```
///
pub(crate) NoRedundantAlt {
pub NoRedundantAlt {
version: "1.0.0",
name: "noRedundantAlt",
source: RuleSource::EslintJsxA11y("no-redundant-roles"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ declare_rule! {
/// [Accessible SVGs | CSS-Tricks - CSS-Tricks](https://css-tricks.com/accessible-svgs/)
/// [Contextually Marking up accessible images and SVGs | scottohara.me](https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html)
///
pub(crate) NoSvgWithoutTitle {
pub NoSvgWithoutTitle {
version: "1.0.0",
name: "noSvgWithoutTitle",
recommended: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/analyzers/a11y/use_alt_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare_rule! {
///
/// - [WCAG 1.1.1](https://www.w3.org/WAI/WCAG21/Understanding/non-text-content.html)
///
pub(crate) UseAltText {
pub UseAltText {
version: "1.0.0",
name: "useAltText",
source: RuleSource::EslintJsxA11y("alt-text"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ declare_rule! {
/// - [WCAG 2.4.4](https://www.w3.org/WAI/WCAG21/Understanding/link-purpose-in-context)
/// - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value)
///
pub(crate) UseAnchorContent {
pub UseAnchorContent {
version: "1.0.0",
name: "useAnchorContent",
source: RuleSource::EslintJsxA11y("anchor-has-content"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare_rule! {
///
/// - [WCAG 2.4.6](https://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-descriptive.html)
///
pub(crate) UseHeadingContent {
pub UseHeadingContent {
version: "1.0.0",
name: "useHeadingContent",
source: RuleSource::EslintJsxA11y("heading-has-content"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ declare_rule! {
///
/// - [WCAG 3.1.1](https://www.w3.org/WAI/WCAG21/Understanding/language-of-page)
///
pub(crate) UseHtmlLang {
pub UseHtmlLang {
version: "1.0.0",
name: "useHtmlLang",
source: RuleSource::EslintJsxA11y("html-has-lang"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ declare_rule! {
/// - [WCAG 2.4.1](https://www.w3.org/WAI/WCAG21/Understanding/bypass-blocks)
/// - [WCAG 4.1.2](https://www.w3.org/WAI/WCAG21/Understanding/name-role-value)
///
pub(crate) UseIframeTitle {
pub UseIframeTitle {
version: "1.0.0",
name: "useIframeTitle",
source: RuleSource::EslintJsxA11y("iframe-has-title"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare_rule! {
///
/// - [WCAG 2.1.1](https://www.w3.org/WAI/WCAG21/Understanding/keyboard)
///
pub(crate) UseKeyWithClickEvents {
pub UseKeyWithClickEvents {
version: "1.0.0",
name: "useKeyWithClickEvents",
source: RuleSource::EslintJsxA11y("click-events-have-key-events"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ declare_rule! {
///
/// - [WCAG 2.1.1](https://www.w3.org/WAI/WCAG21/Understanding/keyboard)
///
pub(crate) UseKeyWithMouseEvents {
pub UseKeyWithMouseEvents {
version: "1.0.0",
name: "useKeyWithMouseEvents",
source: RuleSource::EslintJsxA11y("mouse-events-have-key-events"),
recommended: true,
}
}

pub(crate) enum UseKeyWithMouseEventsState {
pub enum UseKeyWithMouseEventsState {
MissingOnFocus,
MissingOnBlur,
}
Expand Down
Loading
Loading