From 465b1f9c4c3905d6dc96cfc230bd91df1ac452fa Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 25 Sep 2024 22:59:09 +0200 Subject: [PATCH 1/4] feat(grit): implement disregarded snippet nodes --- .../src/grit_node_patterns.rs | 7 +-- .../src/grit_target_language.rs | 55 +++++++++++++++++++ .../js_target_language.rs | 35 +++++++++++- .../js_target_language/constants.rs | 51 +++++++++++++++++ .../src/pattern_compiler/snippet_compiler.rs | 25 ++++----- .../tests/specs/ts/functionMatchesAsync.grit | 1 + .../tests/specs/ts/functionMatchesAsync.snap | 13 +++++ .../tests/specs/ts/functionMatchesAsync.ts | 3 + .../tests/specs/ts/typeAlias.grit | 1 + .../tests/specs/ts/typeAlias.snap | 13 +++++ .../tests/specs/ts/typeAlias.ts | 2 + xtask/codegen/src/ast.rs | 10 ++++ .../src/generate_target_language_constants.rs | 49 +++++++++++++++++ xtask/codegen/src/language_kind.rs | 8 +++ xtask/codegen/src/lib.rs | 1 + 15 files changed, 254 insertions(+), 20 deletions(-) create mode 100644 crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs create mode 100644 crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.grit create mode 100644 crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.snap create mode 100644 crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.ts create mode 100644 crates/biome_grit_patterns/tests/specs/ts/typeAlias.grit create mode 100644 crates/biome_grit_patterns/tests/specs/ts/typeAlias.snap create mode 100644 crates/biome_grit_patterns/tests/specs/ts/typeAlias.ts create mode 100644 xtask/codegen/src/generate_target_language_constants.rs diff --git a/crates/biome_grit_patterns/src/grit_node_patterns.rs b/crates/biome_grit_patterns/src/grit_node_patterns.rs index 412f0c11e81a..0e050ea6304c 100644 --- a/crates/biome_grit_patterns/src/grit_node_patterns.rs +++ b/crates/biome_grit_patterns/src/grit_node_patterns.rs @@ -85,10 +85,9 @@ impl Matcher for GritNodePattern { let mut cur_state = running_state.clone(); let res = pattern.execute( - &if let Some(child) = node.child_by_slot_index(*slot_index) { - GritResolvedPattern::from_node_binding(child) - } else { - GritResolvedPattern::from_empty_binding(node.clone(), *slot_index) + &match node.child_by_slot_index(*slot_index) { + Some(child) => GritResolvedPattern::from_node_binding(child), + None => GritResolvedPattern::from_empty_binding(node.clone(), *slot_index), }, &mut cur_state, context, diff --git a/crates/biome_grit_patterns/src/grit_target_language.rs b/crates/biome_grit_patterns/src/grit_target_language.rs index 0a7c4e570948..00e89cfa9761 100644 --- a/crates/biome_grit_patterns/src/grit_target_language.rs +++ b/crates/biome_grit_patterns/src/grit_target_language.rs @@ -74,6 +74,17 @@ macro_rules! generate_target_language { } } + pub fn is_disregarded_snippet_field( + &self, + kind: GritTargetSyntaxKind, + slot_index: u32, + node: Option>, + ) -> bool { + match self { + $(Self::$language(lang) => lang.is_disregarded_snippet_field(kind, slot_index, node)),+ + } + } + pub fn get_equivalence_class( &self, kind: GritTargetSyntaxKind, @@ -266,6 +277,44 @@ trait GritTargetLanguageImpl { false } + /// Ordinarily, we want to match on all possible fields, including the absence of nodes within a field. + /// e.g., `my_function()` should not match `my_function(arg)`. + /// + /// However, some fields are trivial or not expected to be part of the snippet, and should be disregarded. + /// For example, in JavaScript, we want to match both `function name() {}` and `async function name() {}` with the same snippet. + /// + /// You can still match on the presence/absence of the field in the snippet by including a metavariable and checking its value. + /// For example, in JavaScript: + /// ```grit + /// `$async func name(args)` where $async <: . + /// ``` + /// + /// This method allows you to specify fields that should be (conditionally) disregarded in snippets. + /// The actual value of the field from the snippet, if any, is passed in as the third argument. + /// + /// Note that if a field is always disregarded, you can still switch to ast_node syntax to match on these fields. + /// For example, in react_to_hooks we match on `arrow_function` and capture `$parenthesis` for inspection. + /// + /// ```grit + /// arrow_function(parameters=$props, $body, $parenthesis) where { + /// $props <: contains or { `props`, `inputProps` }, + /// $body <: not contains `props`, + /// if ($parenthesis <: .) { + /// $props => `()` + /// } else { + /// $props => . + /// } + /// } + /// ``` + fn is_disregarded_snippet_field( + &self, + _kind: GritTargetSyntaxKind, + _slot_index: u32, + _node: Option>, + ) -> bool { + false + } + /// Returns an optional "equivalence class" for the given syntax kind. /// /// Equivalence classes allow leaf nodes to be classified as being equal, @@ -353,3 +402,9 @@ fn normalize_quoted_string(string: &str) -> Option<&str> { // Strip the quotes, regardless of type: (string.len() >= 2).then(|| &string[1..string.len() - 1]) } + +#[derive(Debug, Clone)] +enum DisregardedSlotCondition { + Always, + OnlyIf(&'static [&'static str]), +} diff --git a/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs b/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs index 2d10ffa761ef..cbb83a78de29 100644 --- a/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs +++ b/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs @@ -1,9 +1,16 @@ +mod constants; + use super::{ - normalize_quoted_string, GritTargetLanguageImpl, LeafEquivalenceClass, LeafNormalizer, + normalize_quoted_string, DisregardedSlotCondition, GritTargetLanguageImpl, + LeafEquivalenceClass, LeafNormalizer, +}; +use crate::{ + grit_target_node::{GritTargetNode, GritTargetSyntaxKind}, + CompileError, }; -use crate::{grit_target_node::GritTargetSyntaxKind, CompileError}; use biome_js_syntax::{JsLanguage, JsSyntaxKind}; use biome_rowan::{RawSyntaxKind, SyntaxKindSet}; +use constants::DISREGARDED_SNIPPET_SLOTS; const COMMENT_KINDS: SyntaxKindSet = SyntaxKindSet::from_raw(RawSyntaxKind(JsSyntaxKind::COMMENT as u16)).union( @@ -135,6 +142,30 @@ impl GritTargetLanguageImpl for JsTargetLanguage { }) } + fn is_disregarded_snippet_field( + &self, + kind: GritTargetSyntaxKind, + slot_index: u32, + node: Option>, + ) -> bool { + DISREGARDED_SNIPPET_SLOTS.iter().any( + |(disregarded_kind, disregarded_slot_index, condition)| { + if GritTargetSyntaxKind::from(*disregarded_kind) != kind + || *disregarded_slot_index != slot_index + { + return false; + } + + match condition { + DisregardedSlotCondition::Always => true, + DisregardedSlotCondition::OnlyIf(node_texts) => node_texts.iter().any(|text| { + *text == node.as_ref().map(|node| node.text()).unwrap_or_default() + }), + } + }, + ) + } + fn get_equivalence_class( &self, kind: GritTargetSyntaxKind, diff --git a/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs b/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs new file mode 100644 index 000000000000..dffc1e2904dc --- /dev/null +++ b/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs @@ -0,0 +1,51 @@ +//! Generated file, do not edit by hand, see `xtask/codegen/src/generate_target_language_constants.rs` + +use crate::grit_target_language::DisregardedSlotCondition::{self, *}; +use biome_js_syntax::JsSyntaxKind::{self, *}; + +pub(crate) const DISREGARDED_SNIPPET_SLOTS: &[(JsSyntaxKind, u32, DisregardedSlotCondition)] = &[ + (JS_ARROW_FUNCTION_EXPRESSION, 0, OnlyIf(&[""])), + (JS_BREAK_STATEMENT, 2, Always), + (JS_CONTINUE_STATEMENT, 2, Always), + (JS_DEBUGGER_STATEMENT, 1, Always), + (JS_DIRECTIVE, 1, Always), + (JS_DO_WHILE_STATEMENT, 6, Always), + (JS_EXPORT_DEFAULT_DECLARATION_CLAUSE, 2, Always), + (JS_EXPORT_DEFAULT_EXPRESSION_CLAUSE, 2, Always), + (JS_EXPORT_FROM_CLAUSE, 6, Always), + (JS_EXPORT_NAMED_CLAUSE, 4, Always), + (JS_EXPORT_NAMED_FROM_CLAUSE, 7, Always), + (JS_EXPRESSION_STATEMENT, 1, Always), + (JS_FUNCTION_DECLARATION, 0, OnlyIf(&[""])), + (JS_FUNCTION_EXPORT_DEFAULT_DECLARATION, 0, OnlyIf(&[""])), + (JS_FUNCTION_EXPRESSION, 0, OnlyIf(&[""])), + (JS_IMPORT, 2, Always), + (JS_METHOD_CLASS_MEMBER, 1, OnlyIf(&[""])), + (JS_METHOD_OBJECT_MEMBER, 0, OnlyIf(&[""])), + (JS_PROPERTY_CLASS_MEMBER, 4, Always), + (JS_RETURN_STATEMENT, 2, Always), + (JS_THROW_STATEMENT, 2, Always), + (JS_VARIABLE_DECLARATION_CLAUSE, 1, Always), + (JS_VARIABLE_STATEMENT, 1, Always), + (TS_CONSTRUCTOR_SIGNATURE_CLASS_MEMBER, 3, Always), + (TS_DECLARE_FUNCTION_DECLARATION, 0, OnlyIf(&[""])), + (TS_DECLARE_FUNCTION_DECLARATION, 6, Always), + ( + TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, + 0, + OnlyIf(&[""]), + ), + (TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, 6, Always), + (TS_EXPORT_AS_NAMESPACE_CLAUSE, 3, Always), + (TS_EXPORT_ASSIGNMENT_CLAUSE, 2, Always), + (TS_GETTER_SIGNATURE_CLASS_MEMBER, 6, Always), + (TS_IMPORT_EQUALS_DECLARATION, 5, Always), + (TS_INDEX_SIGNATURE_CLASS_MEMBER, 5, Always), + (TS_INITIALIZED_PROPERTY_SIGNATURE_CLASS_MEMBER, 4, Always), + (TS_MAPPED_TYPE, 10, Always), + (TS_METHOD_SIGNATURE_CLASS_MEMBER, 1, OnlyIf(&[""])), + (TS_METHOD_SIGNATURE_CLASS_MEMBER, 7, Always), + (TS_PROPERTY_SIGNATURE_CLASS_MEMBER, 3, Always), + (TS_SETTER_SIGNATURE_CLASS_MEMBER, 6, Always), + (TS_TYPE_ALIAS_DECLARATION, 5, Always), +]; diff --git a/crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs b/crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs index 6057ee8e755b..adf776c19a77 100644 --- a/crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs +++ b/crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs @@ -213,7 +213,7 @@ fn pattern_from_node( return Ok(metavariable); } - if node.slots().is_none() { + let Some(slots) = node.slots() else { let content = node.text(); let lang = &context.compilation.lang; let pattern = if let Some(regex_pattern) = lang @@ -227,22 +227,19 @@ fn pattern_from_node( }; return Ok(pattern); - } + }; let kind = node.kind(); - let args = node - .slots() - .map(|slots| { - // TODO: Implement filtering for disregarded snippet fields. - // Implementing this will make it more convenient to match - // CST nodes without needing to match all the trivia in the - // snippet (if I understand correctly). - slots - .map(|slot| pattern_arg_from_slot(slot, context_range, range_map, context, is_rhs)) - .collect::, CompileError>>() + let args = slots + .filter(|slot| { + !context.compilation.lang.is_disregarded_snippet_field( + kind, + slot.index(), + node.child_by_slot_index(slot.index()), + ) }) - .transpose()? - .unwrap_or_default(); + .map(|slot| pattern_arg_from_slot(slot, context_range, range_map, context, is_rhs)) + .collect::, CompileError>>()?; Ok(Pattern::AstNode(Box::new(GritNodePattern { kind, args }))) } diff --git a/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.grit b/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.grit new file mode 100644 index 000000000000..57ebb984edee --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.grit @@ -0,0 +1 @@ +`function foo() {}` diff --git a/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.snap b/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.snap new file mode 100644 index 000000000000..a4234f3501af --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.snap @@ -0,0 +1,13 @@ +--- +source: crates/biome_grit_patterns/tests/spec_tests.rs +expression: functionMatchesAsync +--- +SnapshotResult { + messages: [], + matched_ranges: [ + "1:1-1:18", + "3:1-3:23", + ], + rewritten_files: [], + created_files: [], +} diff --git a/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.ts b/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.ts new file mode 100644 index 000000000000..1f14cd9bbc71 --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/functionMatchesAsync.ts @@ -0,0 +1,3 @@ +function foo() {} +function bar(){} +async function foo(){} diff --git a/crates/biome_grit_patterns/tests/specs/ts/typeAlias.grit b/crates/biome_grit_patterns/tests/specs/ts/typeAlias.grit new file mode 100644 index 000000000000..6ac8495ed861 --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/typeAlias.grit @@ -0,0 +1 @@ +`type $T = $U` diff --git a/crates/biome_grit_patterns/tests/specs/ts/typeAlias.snap b/crates/biome_grit_patterns/tests/specs/ts/typeAlias.snap new file mode 100644 index 000000000000..3dc7c9679fa1 --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/typeAlias.snap @@ -0,0 +1,13 @@ +--- +source: crates/biome_grit_patterns/tests/spec_tests.rs +expression: typeAlias +--- +SnapshotResult { + messages: [], + matched_ranges: [ + "1:1-1:19", + "2:1-2:19", + ], + rewritten_files: [], + created_files: [], +} diff --git a/crates/biome_grit_patterns/tests/specs/ts/typeAlias.ts b/crates/biome_grit_patterns/tests/specs/ts/typeAlias.ts new file mode 100644 index 000000000000..887997807560 --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/typeAlias.ts @@ -0,0 +1,2 @@ +type Foo = string; +type Bar = number; diff --git a/xtask/codegen/src/ast.rs b/xtask/codegen/src/ast.rs index cf40032324fb..2efb5cb1c7a5 100644 --- a/xtask/codegen/src/ast.rs +++ b/xtask/codegen/src/ast.rs @@ -11,6 +11,7 @@ use super::{ use crate::generate_node_factory::generate_node_factory; use crate::generate_nodes_mut::generate_nodes_mut; use crate::generate_syntax_factory::generate_syntax_factory; +use crate::generate_target_language_constants::generate_target_language_constants; use crate::js_kinds_src::{ AstEnumSrc, AstListSeparatorConfiguration, AstListSrc, AstNodeSrc, TokenKind, }; @@ -76,6 +77,9 @@ pub(crate) fn generate_syntax(ast: AstSrc, mode: &Mode, language_kind: LanguageK .join("crates") .join(language_kind.factory_crate_name()) .join("src/generated"); + let target_language_path = project_root() + .join("crates/biome_grit_patterns/src/grit_target_language") + .join(language_kind.grit_target_language_module_name()); let kind_src = language_kind.kinds(); @@ -103,6 +107,12 @@ pub(crate) fn generate_syntax(ast: AstSrc, mode: &Mode, language_kind: LanguageK let contents = generate_macros(&ast, language_kind)?; update(ast_macros_file.as_path(), &contents, mode)?; + if language_kind.supports_grit() { + let target_language_constants_file = target_language_path.join("constants.rs"); + let contents = generate_target_language_constants(&ast, language_kind)?; + update(target_language_constants_file.as_path(), &contents, mode)?; + } + Ok(()) } diff --git a/xtask/codegen/src/generate_target_language_constants.rs b/xtask/codegen/src/generate_target_language_constants.rs new file mode 100644 index 000000000000..d7bbd615d8f9 --- /dev/null +++ b/xtask/codegen/src/generate_target_language_constants.rs @@ -0,0 +1,49 @@ +use crate::{ + js_kinds_src::{AstSrc, Field}, + language_kind::LanguageKind, +}; +use biome_string_case::Case; +use xtask::Result; + +pub fn generate_target_language_constants( + ast: &AstSrc, + _language_kind: LanguageKind, +) -> Result { + let disregarded_slots: Vec = ast + .nodes + .iter() + .flat_map(|node| { + let node_kind = Case::Constant.convert(node.name.as_str()); + node.fields + .iter() + .enumerate() + .filter_map(|(index, field)| match field { + Field::Token { name, optional, .. } => Some((index, name, optional)), + Field::Node { .. } => None, + }) + // TODO: We might want to move this to `js_kinds_src.rs` when we + // start supporting other languages with Grit. + .filter_map(|(index, name, optional)| match (name.as_str(), optional) { + ("async", true) => Some(format!("({node_kind}, {index}, OnlyIf(&[\"\"])),")), + (";", true) => Some(format!("({node_kind}, {index}, Always),")), + _ => None, + }) + .collect::>() + }) + .collect(); + let disregarded_slots = disregarded_slots.join("\n "); + + let result = format!( + "//! Generated file, do not edit by hand, see `xtask/codegen/src/generate_target_language_constants.rs` + +use crate::grit_target_language::DisregardedSlotCondition::{{self, *}}; +use biome_js_syntax::JsSyntaxKind::{{self, *}}; + +pub(crate) const DISREGARDED_SNIPPET_SLOTS: &[(JsSyntaxKind, u32, DisregardedSlotCondition)] = &[ + {disregarded_slots} +]; +" + ); + + Ok(result) +} diff --git a/xtask/codegen/src/language_kind.rs b/xtask/codegen/src/language_kind.rs index 7de12e90e371..db859cb40a03 100644 --- a/xtask/codegen/src/language_kind.rs +++ b/xtask/codegen/src/language_kind.rs @@ -131,6 +131,10 @@ impl LanguageKind { format!("biome_{self}_factory") } + pub fn grit_target_language_module_name(&self) -> String { + format!("{self}_target_language") + } + pub fn kinds(&self) -> KindsSrc { match self { LanguageKind::Js => JS_KINDS_SRC, @@ -156,4 +160,8 @@ impl LanguageKind { LanguageKind::Markdown => include_str!("../markdown.ungram"), } } + + pub fn supports_grit(&self) -> bool { + matches!(self, Self::Js) + } } diff --git a/xtask/codegen/src/lib.rs b/xtask/codegen/src/lib.rs index 34a2bb100f19..88eaade701cc 100644 --- a/xtask/codegen/src/lib.rs +++ b/xtask/codegen/src/lib.rs @@ -11,6 +11,7 @@ mod generate_nodes; mod generate_nodes_mut; mod generate_syntax_factory; mod generate_syntax_kinds; +mod generate_target_language_constants; mod graphql_kind_src; mod grit_kinds_src; mod js_kinds_src; From 76a32399f4f2142ba564ad7fa15d5574e8a4f02c Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 25 Sep 2024 23:07:53 +0200 Subject: [PATCH 2/4] One more test case --- .../specs/ts/asyncFunctionDoesntMatchNonAsync.grit | 1 + .../specs/ts/asyncFunctionDoesntMatchNonAsync.snap | 12 ++++++++++++ .../specs/ts/asyncFunctionDoesntMatchNonAsync.ts | 3 +++ 3 files changed, 16 insertions(+) create mode 100644 crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.grit create mode 100644 crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.snap create mode 100644 crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.ts diff --git a/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.grit b/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.grit new file mode 100644 index 000000000000..4a9df0736c27 --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.grit @@ -0,0 +1 @@ +`async function foo() {}` diff --git a/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.snap b/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.snap new file mode 100644 index 000000000000..b55c3047c441 --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.snap @@ -0,0 +1,12 @@ +--- +source: crates/biome_grit_patterns/tests/spec_tests.rs +expression: asyncFunctionDoesntMatchNonAsync +--- +SnapshotResult { + messages: [], + matched_ranges: [ + "3:1-3:23", + ], + rewritten_files: [], + created_files: [], +} diff --git a/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.ts b/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.ts new file mode 100644 index 000000000000..1f14cd9bbc71 --- /dev/null +++ b/crates/biome_grit_patterns/tests/specs/ts/asyncFunctionDoesntMatchNonAsync.ts @@ -0,0 +1,3 @@ +function foo() {} +function bar(){} +async function foo(){} From eb8a3b914e0a662d06cacf67d282242cc6fe021c Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 25 Sep 2024 23:23:13 +0200 Subject: [PATCH 3/4] Codegen fix --- .gitattributes | 2 ++ .../grit_target_language/js_target_language/constants.rs | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitattributes b/.gitattributes index 9828b77e8573..610bf12a05dc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,6 +26,8 @@ /crates/biome_js_analyze/src/{lint,assists,syntax}/*.rs linguist-generated=true text=auto eol=lf /crates/biome_js_analyze/src/options.rs linguist-generated=true text=auto eol=lf /crates/biome_js_analyze/src/registry.rs linguist-generated=true text=auto eol=lf +# Grit +/crates/biome_grit_patterns/src/grit_target_language/*/constants.rs linguist-generated=true text=auto eol=lf # Other /crates/biome_unicode_table/src/tables.rs linguist-generated=true text=auto eol=lf diff --git a/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs b/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs index dffc1e2904dc..de2cc9468ac4 100644 --- a/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs +++ b/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs @@ -30,11 +30,7 @@ pub(crate) const DISREGARDED_SNIPPET_SLOTS: &[(JsSyntaxKind, u32, DisregardedSlo (TS_CONSTRUCTOR_SIGNATURE_CLASS_MEMBER, 3, Always), (TS_DECLARE_FUNCTION_DECLARATION, 0, OnlyIf(&[""])), (TS_DECLARE_FUNCTION_DECLARATION, 6, Always), - ( - TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, - 0, - OnlyIf(&[""]), - ), + (TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, 0, OnlyIf(&[""])), (TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, 6, Always), (TS_EXPORT_AS_NAMESPACE_CLAUSE, 3, Always), (TS_EXPORT_ASSIGNMENT_CLAUSE, 2, Always), From 8b024ed3dcab5e0370707337dad15e7dfcd8dc73 Mon Sep 17 00:00:00 2001 From: "Arend van Beelen jr." Date: Wed, 25 Sep 2024 23:37:35 +0200 Subject: [PATCH 4/4] Formatting fix --- .../grit_target_language/js_target_language/constants.rs | 8 ++++++-- xtask/codegen/src/generate_target_language_constants.rs | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs b/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs index de2cc9468ac4..ac54c3408649 100644 --- a/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs +++ b/crates/biome_grit_patterns/src/grit_target_language/js_target_language/constants.rs @@ -1,4 +1,4 @@ -//! Generated file, do not edit by hand, see `xtask/codegen/src/generate_target_language_constants.rs` +//! Generated file, do not edit by hand, see `xtask/codegen` use crate::grit_target_language::DisregardedSlotCondition::{self, *}; use biome_js_syntax::JsSyntaxKind::{self, *}; @@ -30,7 +30,11 @@ pub(crate) const DISREGARDED_SNIPPET_SLOTS: &[(JsSyntaxKind, u32, DisregardedSlo (TS_CONSTRUCTOR_SIGNATURE_CLASS_MEMBER, 3, Always), (TS_DECLARE_FUNCTION_DECLARATION, 0, OnlyIf(&[""])), (TS_DECLARE_FUNCTION_DECLARATION, 6, Always), - (TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, 0, OnlyIf(&[""])), + ( + TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, + 0, + OnlyIf(&[""]), + ), (TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION, 6, Always), (TS_EXPORT_AS_NAMESPACE_CLAUSE, 3, Always), (TS_EXPORT_ASSIGNMENT_CLAUSE, 2, Always), diff --git a/xtask/codegen/src/generate_target_language_constants.rs b/xtask/codegen/src/generate_target_language_constants.rs index d7bbd615d8f9..6b554e68b68d 100644 --- a/xtask/codegen/src/generate_target_language_constants.rs +++ b/xtask/codegen/src/generate_target_language_constants.rs @@ -34,9 +34,7 @@ pub fn generate_target_language_constants( let disregarded_slots = disregarded_slots.join("\n "); let result = format!( - "//! Generated file, do not edit by hand, see `xtask/codegen/src/generate_target_language_constants.rs` - -use crate::grit_target_language::DisregardedSlotCondition::{{self, *}}; + "use crate::grit_target_language::DisregardedSlotCondition::{{self, *}}; use biome_js_syntax::JsSyntaxKind::{{self, *}}; pub(crate) const DISREGARDED_SNIPPET_SLOTS: &[(JsSyntaxKind, u32, DisregardedSlotCondition)] = &[ @@ -45,5 +43,7 @@ pub(crate) const DISREGARDED_SNIPPET_SLOTS: &[(JsSyntaxKind, u32, DisregardedSlo " ); - Ok(result) + let pretty = xtask::reformat(result)?; + + Ok(pretty) }